akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define repi(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,a) repi(i,0,a)
#define repd(i,a,b) for(int i=(a);i>=(b);i--)
#define repit(i,a) for(__typeof((a).begin()) i=(a).begin();i!=(a).end();i++)

#define all(u) (u).begin(),(u).end()
#define rall(u) (u).rbegin(),(u).rend()
#define UNIQUE(u) (u).erase(unique(all(u)),(u).end())

#define pb push_back
#define mp make_pair
#define INF 1e9
#define EPS 1e-9
#define PI acos(-1.0)

using namespace std;

typedef long long ll;
typedef vector<int> vi;

const int MAX_V = 1024;
int  V;
vector<int> G[MAX_V];
int match[MAX_V];
bool used[MAX_V];

void add_edge(int u, int v){
    G[u].push_back(v);
    G[v].push_back(u);
}

bool dfs(int v){
    used[v] = 1;
    rep(i,G[v].size()){
        int u = G[v][i], w = match[u];
        if(w < 0 || !used[w] && dfs(w)){
            match[v] = u;
            match[u] = v;
            return 1;
        }
    }
    return 0;
}

int bi_matching(){
    int res = 0;
    memset(match, -1, sizeof(match));
    rep(v,V) if(match[v] < 0){
        memset(used, 0, sizeof(used));
        if(dfs(v)) res++;
    }
    return res;
}

int b[512], r[512], n, m;

int solve(){
    rep(i,m) rep(j,n) if(__gcd(b[i],r[j]) > 1) add_edge(i,m+j);
        
    return bi_matching();
}

int main()
{
    while(cin >> m >> n, m or n){
        rep(i,m) cin >> b[i];
        rep(i,n) cin >> r[i];
        V = m+n;
        rep(i,MAX_V) G[i].clear();
        cout << solve() << endl;
    }
    return 0;
}

Measured memory_bytes: 3372
from itertools import permutations
from math import sqrt
import sys
sys.setrecursionlimit(10**9)
input = lambda: sys.stdin.readline().rstrip()
inpl = lambda: list(map(int,input().split()))
N = int(input())
xy = [inpl() for _ in range(N)]
S = sum(sum(sqrt(sum((xy[p[i+1]][k]-xy[p[i]][k])**2 for k in range(2)))
        for i in range(N-1)) for p in permutations(range(N)))
M = 1
for i in range(2,N+1): M*=i
print(S/M)

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

int main() {
int n,k,a[100000];
long long s=0,p=0,m=0,l;
cin>>n>>k;
for(int i=0;i<n;i++){
    cin>>a[i];
    if(a[i]>0)s+=a[i];
}
l=s;
for(int i=0;i<n;i++){
    if(a[i]>=0){
        p+=a[i];
    }else{
        m-=a[i];
    }
    if(i>=k-1){
        l=min(l,min(p,m));
        if(a[i-k+1]>=0){
            p-=a[i-k+1];
        }else{
            m+=a[i-k+1];
        }
    }
}
//cout<<s<<","<<l<<endl;
cout<<s-l<<endl;
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main(){
	long long n;
	cin >> n;

	int ans=0;
	long long rt=sqrt(n)+1;
    vector<bool> is_prime(rt+1, 1);
	for (long long p=2; p<=n; p++) {
        if (!is_prime[p]) continue;
        for (long long k=2*p; k<=rt; k += p) is_prime[k] = false;
        long long q=p;
		while(n%q==0){
			++ans;
			n /= q;
			q *= p;
		}
		while(n%p==0) n/=p; 
		if(p>rt){
			++ans;
			break;
		} 
    }
	cout << ans << endl;
}

Measured memory_bytes: 3784
#include<bits/stdc++.h>
using namespace std;
int main(){
    char a[4];
    cin>>a;
    if(a[0]==a[1]&&a[1]==a[2]||a[1]==a[2]&&a[2]==a[3]){ cout<<"Yes"<<endl;}
    else cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
int len[205];
int ans=0;
int main(){
	int n;
	scanf("%d",&n);
	n*=2;
	for(int i=1;i<=n;i++)
		scanf("%d",&len[i]);
	sort(len+1,len+1+n);
	for(int i=1;i<=n;i++){
		ans+=len[(i<<1)-1];
	}
	printf("%d",ans);
}

Measured memory_bytes: 128
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
# include <unordered_map>
# include <numeric>
# include <complex>
# include <bitset>
# include <random>
# include <chrono>
# include <cstdlib>
# include <tuple>
# include <array>
# include <climits>
#define ll long long int
#define rep(i,rept) for (ll i = 0; i < rept; i++)
#define yes(b) std::cout<< (b ? "Yes" : "No")
#define YES(b) std::cout<< (b ? "YES" : "NO")
using namespace std;
/*int ketawa(ll num) {
	int dig, sum = 0;
	while (num) {
		dig = num % 10;
		sum = sum + dig;
		num = num / 10;
	}
	return sum;
}
*/
ll func(ll a, ll b, ll c, ll d,int n) {
	return ((c / (d - b) + n)*(d - b)) + (a % (d - b));
}
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s, ans;
	cin >> s;
	for (int i = 0; i < s.size(); i++) {
		decltype(ans)::iterator it;
		if (ans.size() != 0) {
			it = ans.end() - 1;
		}
		if (s[i] == '0') {
			ans+='0';
		}
		if (s[i] == '1') {
			ans += '1';
		}
		if (s[i] == 'B'&&ans.size() != 0) {
			ans.erase(it,ans.end());
		}
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 256
using System;

public class Rect
{
    public static void Main(string[] args) 
    {
        int W, H, x, y;
        string[] input = Console.ReadLine().Split(new string[] {" "}, StringSplitOptions.RemoveEmptyEntries);
        W = Int32.Parse(input[0]);
        H = Int32.Parse(input[1]);
        x = Int32.Parse(input[2]);
        y = Int32.Parse(input[3]);
        float area = (float)W * (float)H / 2.0f;
        // 長方形の中点が整数で存在する、かつx, yが中点の時
        if (W % 2 == 0 && H % 2 == 0 && x == W / 2 && y == H / 2)
        {
            Console.WriteLine($"{area} 1");
            return;
        }
        Console.WriteLine($"{area} 0");
    }
}

Measured memory_bytes: 13140
#include <cstdio>
using namespace std;

struct team {
	int id, time, count;
};

bool comp(team a, team b) {
	if (b.count > a.count)return true;
	if (b.count == a.count && b.time < a.time)return true;
	if (b.count == a.count && b.time == a.time && b.id > a.id)return true;
	return false;
}

int main() {
	int penalty[51][11];
	int M, T, P, R;
	int m, t, p, j;
	team dat[51];
	int point;
	team sub;

	while (true) {
		scanf("%d%d%d%d", &M, &T, &P, &R);
		if (M == 0 && T == 0 && P == 0 && R == 0)break;

		//penalty data
		for (int i = 1;i <= T;i++) {
			for (int j = 1;j <= 10;j++) {
				penalty[i][j] = 0;
			}
		}
		for (int i = 1;i <= T;i++) {
			dat[i].id = i;
			dat[i].time = 0;
			dat[i].count = 0;
		}
		for (int i = 0;i < R;i++) {
			scanf("%d%d%d%d", &m, &t, &p, &j);
			if (j == 0) {
				dat[t].time += m + penalty[t][p] * 20;
				dat[t].count++;
			}
			else {
				penalty[t][p]++;
			}
		}
		//bubble sort
		for (int i = 1;i <= T;i++) {
			for (int j = T;j > i;j--) {
				if (comp(dat[j - 1], dat[j])) {
					sub = dat[j - 1];
					dat[j - 1] = dat[j];
					dat[j] = sub;
				}
			}
		}
		point = 1;
		while (point <= T) {
			printf("%d", dat[point].id);
			while (point + 1 <= T&&dat[point].count == dat[point + 1].count
				&&dat[point].time == dat[point + 1].time) {
				printf("=%d", dat[point + 1].id);
				point++;
			}
			point++;
			if (point <= T) {
				printf(",");
			}
			else {
				printf("\n");
			}
		}
	}

	return 0;
}

Measured memory_bytes: 1032
import math
A, B = map(int, input().split())

def make_divisors(n):
    divisors = []
    i = 1
    while i <= math.sqrt(n):
        if n % i == 0:
            divisors.append(i)
            if i != math.sqrt(n):
                divisors.append(n // i)
        i += 1

    return divisors

def test_prime(n):
    if n == 1:
        return True
    i = 2
    while i <= math.sqrt(n):
        if n % i == 0:
            return False
        i += 1
        
    return True
    
a_d = make_divisors(A)
b_d = make_divisors(B)

common_d = set(a_d) & set(b_d)

prime = 0

for c in common_d:
    if test_prime(c):
        prime += 1

print(prime)

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

long long pow(long long m, long long n, long long p){
  if(n==1) return m%p;
  if(n%2==0) return pow((m*m)%p,n/2,p);
  return (pow((m*m)%p,(n-1)/2,p)*m)%p;
}

int main(){
  long long m,n;
  cin >> m >> n;
  cout << pow(m,n,1000000007) << endl;

  return 0;
}

Measured memory_bytes: 3092
#include <iostream>
#include <algorithm>

using namespace std;

int main(void){
  int N, K;
  cin >> N >> K;
  int a[60];
  for(int i=0; i<N; ++i){
    cin >> a[i];
  }
  sort(a, a+N, greater<int>());
  int s=0;
  for(int i=0; i<K; ++i){
    s += a[i];
  }
  cout << s << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <utility>
using i64 = long long;

std::vector<std::vector<std::pair<int, int>>> g;
int cnt[16];

auto precalc() {
    std::vector<int> ret(1 << 16);
    for (int i = 1; i < (1 << 16); i++) {
        if (i & 1) continue;
        int x = 0;
        for (int j = 0; j < 16; j++) if (i & (1 << j)) x ^= j;
        int max = !x;
        for (int j = i; j > 0; j = (j - 1) & i) {
            const int v = ret[j] + ret[j ^ i];
            if (v > max) max = v;
        }
        ret[i] = max;
    }
    return ret;
}

void dfs(const int v, const int p, int x) {
    for (const auto &edge : g[v]) {
        if (edge.first == p) continue;
        dfs(edge.first, v, edge.second);
        x ^= edge.second;
    }
    if (p >= 0) cnt[x]++;
}

int main() {
    int n;
    std::cin >> n;
    g.resize(n);
    for (int i = 1; i < n; i++) {
        int u, v, a;
        std::cin >> u >> v >> a;
        g[u].emplace_back(v, a);
        g[v].emplace_back(u, a);
    }

    const auto v = precalc();
    dfs(0, -1, 0);

    int ret = n - 1 - cnt[0], mask = 0;
    for (int i = 1; i < 16; i++) {
        ret -= cnt[i] / 2;
        if (cnt[i] & 1) mask |= 1 << i;
    }

    std::cout << ret - v[mask] << std::endl;

    return 0;
}


Measured memory_bytes: 10496
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

using ll = long long;
using P = std::pair<ll, ll>;

constexpr ll INF = 1ll<<60;

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; }

template<class S, class T>
std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a )
{ std::cout << '(' << a.first << ", " << a.second << ')'; return out; }

template<class T>
std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a )
{ std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; }

ll N;
ll ans = 1;
bool fl = false;

int main()
{
  std::cin >> N;

  rep( i, N )
  {
    ll A;
    std::cin >> A;

    if( ans != -1 && ans > 1000000000000000000ll/A )
      ans = -1;

    if( ans != -1 )
      ans *= A;

    if( !A )
      fl = true;
  }

  std::cout << (fl ? 0 : ans) << std::endl;

  return 0;
}

Measured memory_bytes: 3192
def SelectionSort(A, N):
    for i in range(N):
        minj = i
        for j in range(i, N):
            if A[j][1:] < A[minj][1:]:
                minj = j
        #if i != minj:
            #times += 1
        A[i], A[minj] = A[minj], A[i]
        #print(*A)
    return A

def BubbleSort(A, N):
    for i in range(N):
        for j in reversed(range(i+1, N)):
            if A[j][1:] < A[j-1][1:]:
                A[j], A[j-1] = A[j-1], A[j]

    return A

N= int(input())
A = [str(x) for x in input().split()]
B = [0 for i in range(N)]
for i in range(N):
    B[i] = A[i]
bubble = BubbleSort(A, N)
selection = SelectionSort(B, N)
#print(A, B)
#print(*A)
print(*bubble)
print('Stable')
print(*selection)
if bubble == selection:
    print('Stable')
else:
    print('Not stable')

Measured memory_bytes: 7732
import java.util.*

fun main(args: Array<String>) {
	val scanner = Scanner(System.`in`)
	val n = scanner.nextLong()
	val m = scanner.nextLong()
	println(calc(n, m))
}

fun calc(n: Long, m: Long): Long {
	for (i in m / n downTo 1) {
		if (m % i == 0L && m / n >= i) return i
	}
	return 1
}

Measured memory_bytes: 31264
s = list(input())
zeroichi = 0
ichizero = 0
for i in range(len(s)):
         if i % 2 == 0:
                  if s[i] != "0":
                           zeroichi += 1
                  else:
                           ichizero += 1
         else:
                  if s[i] == "0":
                           zeroichi += 1
                  else:
                           ichizero += 1
print(min(zeroichi,ichizero))



Measured memory_bytes: 3956
#include <bits/stdc++.h>
#define ll long long

using namespace std;

const int MAXN = (int) 1e3;
const int INF = (int) 1e9;

std::vector <int> g[MAXN + 1];

int val[MAXN + 1];

int dp[MAXN + 1];

int dp1[5 * MAXN + 1];
int dp2[5 * MAXN + 1];

void dfs(int nod, int p) {
    int i, j;
    if(g[nod].size() == 0) {
        dp[nod] = 0;
        return ;
    }
    for(auto it : g[nod])
        if(it != p)
           dfs(it, nod);
    for(i = 0; i <= val[nod]; i++)
           dp1[i] = dp2[i] = INF;
    dp1[0] = 0;
    for(auto it : g[nod]) {
        for(j = val[nod]; j >= 0; j--) {
            if(j - val[it] >= 0)
                dp2[j] = std::min(dp2[j], dp1[j - val[it]] + dp[it]);
        }
        for(j = val[nod]; j >= 0; j--) {
            if(j - dp[it] >= 0)
                dp2[j] = std::min(dp2[j], dp1[j - dp[it]] + val[it]);
        }
        for(j = val[nod]; j >= 0; j--) {
            dp1[j] = dp2[j];
            dp2[j] = INF;
        }
    }
    dp[nod] = INF;
    for(i = 0; i <= val[nod]; i++)
        dp[nod] = min(dp[nod], dp1[i]);
    if(dp[nod] == INF) {
        cout << "IMPOSSIBLE";
        exit(0);
    }
}

int main() {
    //fstream cin("A.in");
    //ofstream cout("A.out");
    int n, i, x;
    ios::sync_with_stdio(false);
    cin >> n;
    for(i = 2; i <= n; i++) {
        cin >> x;
        g[x].push_back(i);
    }
    for(i = 1; i <= n; i++)
        cin >> val[i];
    dfs(1, 0);
    cout << "POSSIBLE";
    //cin.close();
    //cout.close();
    return 0;
}


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

vector<int> xs, ys;

double dist(double x, double y) {
  double ans = 0;
  for (int i = 0; i < xs.size(); i++) {
    double dx = x - xs.at(i), dy = y - ys.at(i);
    ans = max(ans, sqrt(dx * dx + dy * dy));
  }
  return ans;
}

double calc_y(double x) {
  double y0 = 0, y1 = 1000;
  while (y1 - y0 > 1e-8) {
    double dy = y1 - y0, l = y0 + dy / 3, r = y1 - dy / 3;
    double d1 = dist(x, l);
    double d2 = dist(x, r);
    if (d1 < d2) {
      y1 = r;
    } else {
      y0 = l;
    }
  }
  return (y0 + y1) / 2;
}

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int xi, yi;
    cin >> xi >> yi;
    xs.push_back(xi);
    ys.push_back(yi);
  }
  double x0 = 0, x1 = 1000;
  while (x1 - x0 > 1e-8) {
    double dx = x1 - x0, l = x0 + dx / 3, r = x1 - dx / 3;
    double d1 = dist(l, calc_y(l));
    double d2 = dist(r, calc_y(r));
    if (d1 < d2) {
      x1 = r;
    } else {
      x0 = l;
    }
  }
  cout << setprecision(17) << dist(x0, calc_y(x0)) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define pii pair<int, int>
#define endl "\n"
#define int long long
#define F first
#define S second
#define B begin
#define E end
#define RB rbegin
#define RE rend
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
 
const int INF = 1e9 + 1;
const double EPS = 1e-10;
const ll P = 1e9 + 7;
const int Q = 47;
 
using namespace std;
 
void hello()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
}
 
void show(vector<int>& arr)
{
    for (auto i : arr)
        cout << i << " ";
    cout << endl;
}
void show(vector<vector<int>>& arr)
{
    for (auto i : arr)
        show(i);
    cout << endl;
}


signed main()
{
    hello();
    
    int n, k;
    cin >> n >> k;
    vector <int> seq(n);
    for (int i = 0; i < n; ++i)
        cin >> seq[i];
    sort(seq.B(), seq.E());
    int res = 0;
    for (int i = 0; i < k; ++i)
        res += seq[i];
    cout << res << endl;
}

Measured memory_bytes: 3656
N = int(input())
A = list(map(int,input().split()))
B = []
k = 0
for i in range(1, N):
    k ^= A[i]
B.append(k)
for i in range(1, N):
    B.append(B[-1] ^ A[i] ^ A[i-1])

print(*B)

Measured memory_bytes: 31448
import numpy as np
from sys import stdin

'''
Reference: https://codeforces.com/blog/entry/75046#comment-591494 (1-based index)

(0-based index)

For a sequence A[l]..A[k]..A[r] with sum S contributes l * (N - r) to answer.
    0, 1, 2, ..., l....k....r, ..., N - 2, N - 1
    x  x  x   x   x         v   v     v      v
There are (l + 1) `x` and (N - r) `v`.

Enumerate all possible sequence is impossible. 
Consider all sequeuces with sum S and **ends** at specific r:
    A[l1]...A[r] -> l1 * (N - r)
    A[l2]...A[r] -> l2 * (N - r)
    A[l3]...A[r] -> l3 * (N - r)
    .
    .
    .
which contributes (l1 + l2 + ... + lm) * (N - r) in total.

We can find *sum of left index for all valid sequence* for each r using DP.

    dp[i][s] = the sum of left index for all sequence that
                    1. ends at i
                    2. has sum s
    
    dp[i][:A[i]] = 0  since any sequence ends at i has sum >= A[i]

    dp[i][A[i]] = i + 1
    dp[i][s] = sum(dp[j][s - A[i]] for j in range(i))

    Take A = [2, 3, 4] for example, sequences that end at A[2] are:
    
            Base case:
                   [4] -> dp[2][4] = 3

            Transition from dp[0][s - 4]:
             [2,    4]

            Transition from dp[1][s - 4]:
                [3, 4]
             [2, 3, 4]
    
    The answer is sum(dp[r][S] * (N - r) for r in range(N))

So the naive implementation is:

    dp = np.zeros((N, max(S, A.max()) + 1), dtype=np.int64)
    for i, a in enumerate(A):
        dp[i, a] = i + 1
        for s in range(a + 1, S + 1):
            dp[i, s] = dp[:i, s - a].sum() % M  # here can be optimized
    
    ans = 0
    for i in range(N):
        ans += (N - i) * dp[i, S]
        ans = ans % M

has time O(N * S * N) which results in TLE.

Using another array to store the cumsum (prefix sum) of dp solves the problem.
One can compress the dp matrix to vector to reduce memory usage.
'''

N, S = map(int, input().split())
A = np.int32(input().split())
M = 998244353
V = max(A.max(), S)

ans = 0
cs = np.zeros(V + 1, dtype=np.int64)
for i, a in enumerate(A):
    dp = np.zeros(V + 1, dtype=np.int64)
    dp[a] = i + 1
    dp[a + 1 : S + 1] = cs[np.arange(a + 1, S + 1) - a]
    cs = (cs + dp) % M
    ans = (ans + (N - i) * dp[S]) % M
print(ans)


Measured memory_bytes: 12508
n = int(input())
ac = 0
wa = 0
tle = 0
re = 0
for _ in range(n):
    s = input()
    if s == 'AC':
        ac+=1
    elif s == 'WA':
        wa+=1
    elif s=='TLE':
        tle +=1
    elif s=='RE':
        re += 1

print('AC x '+str(ac))
print('WA x '+str(wa))
print('TLE x '+str(tle))
print('RE x '+str(re))




Measured memory_bytes: 9192
# coding=utf-8
import math

if __name__ == '__main__':
    A, B, C = map(int, input().split())

    MV = max(A, B, C) * 3
    SumABC = A + B + C

    if MV % 2 == 0 and SumABC % 2 == 0:
        ans = (MV - SumABC) / 2

    elif MV % 2 == 1 and SumABC % 2 == 1:
        ans = math.ceil(MV - SumABC) / 2

    else:
        ans = math.ceil((MV - SumABC) / 2) + 1

    print(int(ans))

Measured memory_bytes: 9132
#!/usr/bin/env ruby

# Generated by AtcoderGreedy on 2018-06-10
# ABC099 C

# my lib

module Enumerable
  # work just like String#split,
  # except this method does not use regex match
  # but check whether yield succeeds or not.
  def split
    current = nil
    ret = []
    each do |elem|
      if yield elem
        if current
          ret << current
          current = nil
        end
      elsif current
        current << elem
      else
        current = [elem]
      end
    end
    ret << current if current
    ret
  end
end

class Array
  # truncate tail, opposite of drop
  def clip(amount = 1)
    if amount < 0
      raise ArgumentError, "amount == #{amount}, cannot be negative!"
    end
    take_amount = size - amount
    take_amount < 0 ? [] : take(take_amount)
  end
end

def n_choose_k(n, k)
  return 0 unless (0..n).cover? k
  result = 1
  1.upto(k) do |d|
    result *= n
    result /= d
    n -= 1
  end
  result
end

# end of lib

# Your code here

require 'set'

MAX = 100_000

arr = { 0 => 0 }
edges = [0]

def withdraws(base)
  ret = [base]
  cand = ret.last * base
  while cand <= MAX
    ret << cand
    cand = ret.last * base
  end
  ret
end

withds = [1] + withdraws(6) + withdraws(9)
withds = withds.sort

WITHDRAWS = withds

N = gets.to_i

edges = [0]
n = 0

until edges.empty?
  n += 1
  next_edges = []
  edges.each do |e|
    WITHDRAWS.each do |w|
      next_ind = e + w
      break if next_ind > MAX
      unless arr[next_ind]
        arr[next_ind] = n
        next_edges << next_ind
      end
    end
  end
  edges = next_edges
end

puts arr[N]


Measured memory_bytes: 11132
n = list(input())

for bit in range(3 ** 2):
    array = ['-','-','-']
    for i in range(3):
        if bit >> i & 1:
            array[i] = '+'
    tmp = int(n[0])
    ans = n[0]
    for i in range(len(array)):
        if array[i] == '+':
            tmp += int(n[i+1])
            ans+='+'+n[i+1]
        else:
            tmp -= int(n[i+1])
            ans+='-'+n[i+1]
    if tmp == 7:
        print(ans+'=7')
        exit(0)

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

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;
typedef vector < vector<ll> > Mat;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int main(){
  int N, A, B; cin >> N >> A >> B;
  cout << min(A, B) << " " << max(0, A + B - N) << endl;

  return 0;
}


Measured memory_bytes: 3556
s=int(input())
def cmb(n,r,mod):
  if r<0 or n<r:
    return 0
  r=min(r,n-r)
  return g1[n]*g2[r]*g2[n-r]%mod

n=2000
mod=10**9+7

g1=[1,1]#元table
g2=[1,1]#逆元table
inv=[0,1]#逆元table計算用

for i in range(2,n+1):
  g1.append(g1[-1]*i%mod)
  inv.append(-inv[mod%i]*(mod//i)%mod)
  g2.append(g2[-1]*inv[-1]%mod)

ans=0
for i in range(s//3+1):
  ans+=cmb(s-2*i-1,i-1,mod)
  ans%=mod
print(ans)

Measured memory_bytes: 9408
#include <iostream>      // cout, endl, cin
#include <string>        // string, to_string, stoi
#include <vector>        // vector
#include <algorithm>     // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility>       // pair, make_pair
#include <tuple>         // tuple, make_tuple
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <map>           // map
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <deque>         // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset>        // bitset
#include <cctype>        // isupper, islower, isdigit, toupper, tolower

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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()

int main()
{
        string s;
        cin >> s;
        for (int i = 0; i < s.size(); i+=2)
        {
                cout << s[i];
        }

        cout  << endl;

        return 0;
}


Measured memory_bytes: 512
using static System.Math;
using System;

public class hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var n = int.Parse(line[0]);
        var Q = int.Parse(line[1]);
        line = Console.ReadLine().Trim().Split(' ');
        var a = Array.ConvertAll(line, int.Parse);
        Array.Sort(a);
        var amax = a[n - 1];
        var amin = a[0];
        var b = new int[amax + 1];
        setB(a, b );
        for (int i = 0; i < Q; i++)
        {
            var q = int.Parse(Console.ReadLine().Trim());
            getAns(b, amin, q);
        }
    }
    public static void getAns (int [] b,int amin , int q)
    {
        var ans = 0;
        var na = b[b.Length - 1];
        while (true)
        {
            na = b[na];
            var w = na % q;
            if (w == q - 1) { Console.WriteLine(q-1); return; }
            ans = Max(ans, w);
            if (w == 0) na -= 1;
            else na -= w;
            if (na <= 0) break;
        }
        Console.WriteLine(ans);
    }
    public static void setB(int[] a, int[] b)
    {
        var aL = a.Length;
        var bL = b.Length;
        for (int i = 0; i < aL; i++)
            b[a[i]] = a[i];
        for (int i = a[0] + 1; i < bL  ; i++)
            if (b[i] == 0) b[i] = b[i - 1];
    }
}






Measured memory_bytes: 43684
n = gets.to_i
a = Array.new(n){Array.new(n, 2)}
n.times do |i|
  m = gets.to_i
  m.times do
    x, y =  gets.split.map(&:to_i)
    a[i][x-1] = y
  end
end
max = 0
[0, 1].repeated_permutation(n) do |x|
  f = true
  n.times do |i|
    next if x[i] == 0
    n.times do |j|
      next if a[i][j] == 2
      if a[i][j] !=x[j]
        f = false
        break
      end
    end
    break unless f
  end
  max = x.inject(:+) if f && max < x.inject(:+)
end
puts max


Measured memory_bytes: 14824
from scipy.sparse.csgraph import floyd_warshall
import numpy as np

N, M, L = map(int, input().split())
inf = 10**9 + 1
dist = [[inf] * N for i in range(N)]
for i in range(M):
    A, B, C = map(int, input().split())
    dist[A-1][B-1] = dist[B-1][A-1] = C

dist = floyd_warshall(dist, directed=False)
dist = np.where(dist <= L, 1, inf)
dist = floyd_warshall(dist, directed=False)
dist = np.where(dist < inf, dist-1, -1)

Q = int(input())
for i in range(Q):
    s, t = map(int, input().split())
    print(int(dist[s-1, t-1]))


Measured memory_bytes: 19592
#include "bits/stdc++.h"
using namespace std;


/* macro */
#define rep(i,a,b) for(int i=a;i<b;i++)
#define revrep(i,a,b) for(int i = a; i > b; i--)
#define int long long
#define exist(s,e) ((s).find(e)!=(s).end())
#define all(v) (v).begin(), (v).end()
#define each(s,itr) for(auto (itr) = s.begin(); (itr) != s.end(); (itr)++)
#define sum(v) accumulate(all(v), (0LL))
#define pb push_back


/* alias */
template<class T> using vec = vector<T>;
typedef vector<int> vi;
typedef pair<int, int> pi;


/* constant */
const int inf = pow(2, 62);
const int mod = 1e9 + 7;
int dx[8]={1,0,-1,0,-1,1,-1,1};
int dy[8]={0,1,0,-1,-1,-1,1,1};
const string alpha = "abcdefghijklmnopqrstuvwxyz";

/* io_method */
int input(){int tmp;cin >> tmp;return tmp;}
string raw_input(){string tmp;cin >> tmp;return tmp;}
string readline(){string s;getline(cin, s);return s;}
template<class T> void printx(T n){cout << n;}
template<class T, class U> void printx(pair<T, U> p){cout << "(" << p.first << "," << p.second << ")";}
template<class T> void printx(vector<T> v){cout << "{";rep(i,0,v.size()){printx(v[i]);if(i != v.size()-1)printx(",");}cout << "}";}
template<class T> void print(T n){printx(n);cout << endl;}
template<class T> void print(set<T> s){cout << "{";each(s, e){if(e != s.begin()) printx(",");printx(*e);}cout << "}" << endl;}
template<class T, class U> void print(map<T, U> mp){cout << "{";each(mp, e){cout << "(" << e -> first << "," << e -> second << ")";}cout << "}" << endl;}


/* general_method */
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; }




/* main */

vector<int> factors(int n){
    vector<int> facts;
    int i = 1;
    while(i*i < n){
        if(n % i == 0){
            facts.push_back(i);
            facts.push_back(n/i);
        }
        i++;
    }
    int sq = (int)sqrt(n);
    if(sq * sq == n) facts.push_back(sq);
    sort(all(facts));
    return facts;
    
}

vi primefact(int n){

    vi ret;
    int t = n;

    rep(i,2,sqrt(t + 10)){
        if(n % i == 0){
            while(n % i == 0){
                ret.push_back(i);
                n /= i;
            }
        }
    }
    if(n > 1) ret.push_back(n);
    sort(all(ret));

    return ret;

}

signed main(){

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

    
    int n = input();


    vi a; rep(i,0,n) a.pb(input()); sort(all(a));
    vi b; rep(i,0,n) b.pb(input()); sort(all(b));
    vi c; rep(i,0,n) c.pb(input()); sort(all(c));


    int ans = 0;
    for(int e : b){
        ans += distance(a.begin(), lower_bound(all(a), e)) * distance(upper_bound(all(c), e), c.end());
    }

    print(ans);









    




    







    




   

    
    



    




    




    











    

    

    



    
    



    







    

    

    




    



    



    

 
    
    


    

    
   
    













}






    










    




    










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

using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define REP(i, l, n) for(ll i=(l), i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back

ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

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

char alpha[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};

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

int main(){
    int n, k; cin >> n >> k;
    vector<ll> column, row;
    vector<vector<ll>> lis(n, vector<ll>(2));
    REP(i, 0, n){
        cin >> lis[i][0] >> lis[i][1];
        lis[i][0] += 1e9;
        lis[i][1] += 1e9;
    }
    sort(ALL(lis), [](auto &x, auto &y){return x[0] < y[0];});
    map<ll, int> mp, mp1;
    REP(i, 0, n){
        if(mp[lis[i][0]] == 0){
            mp[lis[i][0]] = i;
            column.pb(lis[i][0]);
        }else{
            continue;
        }
    }
    sort(ALL(lis), [](auto &x, auto &y){return x[1] < y[1];});
    REP(i, 0, n){
        if(mp1[lis[i][1]] == 0){
            mp1[lis[i][1]] = i;
            row.pb(lis[i][1]);
        }else{
            continue;
        }
    }
    cout << endl;
    vector<vector<ll> > assyuku(column.size(), vector<ll>(row.size(), 0));
    REP(i, 0, n){
        int ci = mp[lis[i][0]], ri = mp1[lis[i][1]];
        assyuku[ci][ri]++;
    }
    /*REP(i, 0, column.size()){
        REP(l, 0, row.size()){
            cout << assyuku[i][l];
        }
        cout << endl;
    }*/
    ll ans = 5e18;
    REP(i, 0, column.size()){
        REP(l, 0, row.size()){
            REP(j, i, column.size()){
                REP(m, l, row.size()){
                    int count = 0;
                    REP(a, i, j+1){
                        REP(b, l, m+1){
                            count += assyuku[a][b];
                        }
                    }
                    if(count >= k){
                        ll c1 = column[i], c2 = column[j], r1 = row[l], r2 = row[m];
                        chmin(ans, (c1-c2)*(r1-r2));
                    }
                }
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int i,j;
int k[10];
int ck;
int n;

int main(){
	while(1){
		scanf("%d",&n);
		if(n==0)return 0;
		ck=0;
		while(n>=1){
			if(n%8<=3)k[ck++]=n%8;
			else if(n%8<=4)k[ck++]=n%8+1;
			else k[ck++]=n%8+2;
			n/=8;
		}
		for(i=ck-1;i>=0;i--){
			printf("%d",k[i]);
		}
		printf("\n");
	}
}

			

Measured memory_bytes: 1032
#include <iostream> 
#include <vector>
#include <cmath>
#include <string>
#include <sstream>
#include <algorithm>
#include <queue>
#include <stack>
#include <unordered_set>
#include <set>
#include <unordered_map>
#include <map>
#include <iomanip>
#include <cctype>
#include <climits>

using namespace std;

using ii = pair<int, int>;
using vi = vector<int>;
using vii = vector<ii>;
using vvi = vector<vi>;

using ll = long long int;

#define mp(a,b) make_pair(a,b)

const int MOD = 1000 * 1000 * 1000 + 7;

bool res() {
	int n, k;
	cin >> n >> k;
	if (!cin) return false;

	vector<double> v(n);
	for (int i = 0; i < n; ++i) {
		ll num; 
		cin >> num;
		if (num == 1) v[i] = 1;
		else v[i] = (num + 1) / 2.0;
	}

	double sum = 0, msum = 0;
	for (int i = 0; i < k; ++i) sum += v[i];
	msum = sum;

	for (int i = k; i < n; ++i) {
		sum += v[i];
		sum -= v[i - k];
		msum = max(sum, msum);
	}
	
	cout << fixed << msum << '\n';

	return true;
}

int main() {
	while (res()) {}
	return 0;
}

Measured memory_bytes: 1792
#https://note.nkmk.me/python-union-find/
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

def main():
    N,M = list(map(int,input().split()))
    uf = UnionFind(N+1)
    ab = [list(map(int,input().split())) for i in range(M)]

    uf = UnionFind(N+1)
    for i in range(M):
        uf.union(ab[i][0],ab[i][1])
    print(uf.group_count()-2)

if __name__ == '__main__':
    main()


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

const int MAX = 110000;

struct Item {
  string name;
  int time;
};
Item p_list[MAX];

int head;
int tail;

void initialize() {
  head=tail=0;
}

bool isEmpty() {
  return head == tail;
}

bool isfull() {
  return head == (tail + 1) % MAX;
}

int enqueue(Item x) {
  if (isfull()) throw "Exception queue is full";
  p_list[tail] = x;
  if (tail + 1 == MAX) tail = 0;
  else tail ++;
  return 0;

}

Item dequeue() {
  if (isEmpty()) throw "Exception empty queue can't dequeue";
  Item x = p_list[head];
  if (head + 1 == MAX) head = 0;
  else head++;
  return x;
}


int main() {
  int n, q; cin>>n>>q;

  rep(i, n) {
    string tmp_name;
    int tmp_time;
    cin>>tmp_name>>tmp_time;
    Item tmp_item = {tmp_name, tmp_time};
    enqueue(tmp_item);
  }

  int ans = 0;

  while (!isEmpty()) {
    Item tmp_item = dequeue();

    if (tmp_item.time <= q) {
      ans += tmp_item.time;
      cout << tmp_item.name << " " << ans << endl;
    } else {
      ans += q;
      tmp_item.time -= q;
      enqueue(tmp_item);
    }
  }

  return 0;
}


Measured memory_bytes: 7224
import sys
from collections import deque, defaultdict


def bfs01(s, t, links):
    q = deque([(0, s, -1)])  # cost, station, last-company
    visited = set()
    while q:
        d, v, e = q.popleft()
        if v == t:
            return d
        if (v, e) in visited:
            continue
        visited.add((v, e))
        if e == 0:
            q.extend((d + 1, u, c) for c, us in links[v].items() for u in us if (u, c) not in visited)
        else:
            q.extendleft((d, u, e) for u in links[v][e] if (u, e) not in visited)
            if (v, 0) not in visited:
                q.appendleft((d, v, 0))

    return -1


readline = sys.stdin.buffer.readline
read = sys.stdin.buffer.read

n, m = map(int, readline().split())
links = [defaultdict(set) for _ in range(n)]
pqc = list(map(int, read().split()))
for p, q, c in zip(pqc[0::3], pqc[1::3], pqc[2::3]):
    p -= 1
    q -= 1
    links[p][c].add(q)
    links[q][c].add(p)

print(bfs01(0, n - 1, links))


Measured memory_bytes: 216488
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

const ll mod = 1e9 + 7;

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

    ll n;
    cin >> n;
    string s;
    cin >> s;
    ll res = 0;
    REP(i, n - 2) {
        if (s.substr(i, 3) == "ABC") res++;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ", "; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ", "; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ", "; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ", "; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ", "; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ", "; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << ", " << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << ": " << v.second << ", "; os << "}"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << ": " << v.second << ", "; os << "}"; return os; }
template<typename T> void ndarray(vector<T> &vec, int len) { vec.resize(len); }
template<typename T, typename... Args> void ndarray(vector<T> &vec, int len, Args... args) { vec.resize(len); for (auto &v : vec) ndarray(v, args...); }
template<typename T> bool chmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool chmin(T &m, const T q) { if (q < m) {m = q; return true;} else return false; }
template<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first - r.first, l.second - r.second); }
#define f first
#define s second
 
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int len;
    cin >> len;
    int small = INT_MAX, negs = 0;
    long long sum = 0;
    for(int i = 0; i < len; i++) {
        int a;
        cin >> a;
        if(abs(a) < small)
            small = abs(a);
        if(a < 0)
            negs++;
        sum += abs(a);
    }
    if(negs % 2 == 1) {
        cout << sum - small - small;
    } else {
        cout << sum;
    }
}

Measured memory_bytes: 3484
//url:
//problem name: Brick Break

#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
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;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;

int main() {
    int N; cin >> N;
    for(int i = N; i <= 999; i++) {
        string S = to_string(i);
        if(S[0] == S[1] && S[1] == S[2] && S[2] == S[0]) {
            cout << i << endl;
            return 0;
        }
    }
 }


Measured memory_bytes: 256
ln_l = [1,2,3,4,5,6,7,8,9]

def dps(curr_num):
    end_num = curr_num[-1]
    for i in [-1,0,1]:
        added_num = int(end_num) + i
        if added_num == -1 or added_num == 10:
            continue
        curr_num_plus = curr_num + str(added_num)
        ln_l.append(int(curr_num_plus))
        if len(curr_num_plus) < 10:
            dps(curr_num_plus)

def main():
    k = int(input())
    for i in range(1,9+1):
        dps(str(i))
    ln_l.sort()
    print(ln_l[k-1])

if __name__ == "__main__":
    main()

Measured memory_bytes: 17312
N = int(input())
n = 0
l = 0
while n < N:
    l += 1
    n += 26**l
cnt = [26**l for l in range(1, 12)]
n = sum(cnt[:l-1])
k = 1
s = ''
while k < l:
    i = 0
    while n+cnt[l-k-1] < N:
        i += 1
        n += cnt[l-k-1]
    s += chr(97+i)
    k += 1
s += chr(97+N-n-1)
print(s)

Measured memory_bytes: 61816
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;
ll inf=1e18+7;

// この操作では最大公約数を作ることができる（どんなに頑張ってもgcdの倍数しか作れないので，これが最小単位）
// あるa[i]-kがgcdの倍数になってればそれを引けばOK

ll gcd(ll a,ll b){
	if(b==0)return a;
	return gcd(b,a%b);
}

int main(void){
	ll n,k,a[100010],g;
	bool ok=false;
	cin>>n>>k;
	rep(i,n)cin>>a[i];
	g=a[0];
	reg(i,1,n-1)g=gcd(a[i],g);
	rep(i,n){
		if(a[i]>=k && (a[i]-k)%g==0)ok=true;
	}
	cout<<(ok?"POSSIBLE":"IMPOSSIBLE")<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
const int N=1e5+10;
long long a[N];
int main()
{
	cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);
	int d,n;
	cin>>d>>n;
	if(n<=99)
	{
			if(d==0)cout<<n;
	if(d==1)cout<<100*n;
	if(d==2)cout<<10000*n;
	}
else
{
				if(d==0)cout<<n+1;
	if(d==1)cout<<100*(n+1);
	if(d==2)cout<<10000*(1+n);
}

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define PB push_back
#define ZERO (1e-10)
#define INF (1<<29)
#define CL(A,I) (memset(A,I,sizeof(A)))
#define DEB printf("DEB!\n");
#define D(X) cout<<"  "<<#X": "<<X<<endl;
#define EQ(A,B) (A+ZERO>B&&A-ZERO<B)
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
#define IN(n) int n;scanf("%d",&n);
#define FOR(i, m, n) for (int i(m); i < n; i++)
#define REP(i, n) FOR(i, 0, n)
#define F(n) REP(i, n)
#define FF(n) REP(j, n)
#define FT(m, n) FOR(k, m, n)
#define aa first
#define bb second
void ga(int N,int *A){F(N)scanf("%d",A+i);}
int N,X;
char s[128],r[128];
bool cp(char*a,char*b,int L){
    F(L)if(a[i]^b[i])return 0;
    return 1;
}
int main(void){
    scanf("%d%s%s",&N,s,r);
    F(N+1)if(cp(s+N-i,r,i))X=i;
    printf("%d\n",N*2-X);
    return 0;
}


Measured memory_bytes: 256
# coding: utf-8

import numpy as np

if __name__=="__main__":
    n = int(input())
    a = input().split()
    if n%2 == 0:
        index = list(range(2, n+1, 2))
        index.reverse()
        index += list(range(1, n+1, 2))
    else:
        index = list(range(1, n+1, 2))
        index.reverse()
        index += list(range(2, n+1, 2))
    index = np.array(index)
    print(" ".join([a[i-1] for i in index]))


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

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

    int n, m, c;
    cin >> n >> m >> c;

    int b[m];
    for (int i = 0; i < m; ++i) {
        cin >> b[i];    
    }
    int res = 0;
    for (int i = 0; i < n; ++i) {
        int sub_res = c;
        for (int j = 0; j < m; ++j) {
            int a;
            cin >> a;
            sub_res += a * b[j];
        }
        res += sub_res > 0;
    }
    cout << res << '\n';

    return 0;
}


Measured memory_bytes: 256
//ΔABC 070 C
#include<iostream>
#include<cstdio>
#include<fstream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<cmath>
#include<cstring>
#include<cstdlib>
using namespace std;
typedef long long LL;
LL gcd(LL x,LL y)
{
	if(x<y)
		swap(x,y);
	LL r;
	r=x%y;
	while(r){
		x=y;
		y=r;
		r=x%y;
	}
	return y;
}
int main()
{
	LL n,a,b;
	cin>>n>>a;
	n--;
	while(n--){
		cin>>b;
		a=a/gcd(a,b)*b;
	}
	cout<<a<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<stack>
#include<set>
#include<map>
#include<utility>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;

#define MOD 1000000007;

int n, a, b, c;
vector<int> l;

int minCost(int x, int y, int z, int i){
	if(i==n){
		if(!x || !y || !z)
			return 10000;
		return abs(a-x)+abs(b-y)+abs(c-z)-30;
	}
	int minA = minCost(x+l[i], y, z, i+1)+10;
	int minB = minCost(x, y+l[i], z, i+1)+10;
	int minC = minCost(x, y, z+l[i], i+1)+10;
	int minD = minCost(x, y, z, i+1);
	return min({minA, minB, minC, minD});
}

int main(){
	cin >> n >> a >> b >> c;
	for(int i=0; i<n; i++){
		int tmp;
		cin >> tmp;
		l.push_back(tmp);
	}
	cout << minCost(0,0,0,0) << endl;
	return 0;
}

Measured memory_bytes: 256
while True:
    r,c = map(int, input().split())
    if (r|c)==0: break

    num = [0]*c
    for i in range(r):
        instr = input()
        for j in range(c):
            num[j] = (num[j]<<1) + (instr[2*j]=="1")

    maxx = -1
    for i in range(1 << r):
        answer = 0
        for j in range(c):
            oksenbei = bin(num[j]^i).count("1")
            answer += oksenbei if oksenbei*2//r >= 1 else r-oksenbei
        if maxx < answer:
            maxx = answer

    print(maxx)

Measured memory_bytes: 7880
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

int main(void) {
    int N;
    cin >> N;
    vector< pair<int,int> > p(N);
    for(int i=0; i<N; i++) {
        cin >> p[i].first >> p[i].second;
    }

    sort(p.begin(), p.end(), [](auto &lhs, auto &rhs) {return atan2(lhs.first, lhs.second) < atan2(rhs.first, rhs.second);});
    for(int i=0; i<N; i++) {
        p.push_back(p[i]);
    }

    double ans = 0.0;
    for(int i=0; i<N; i++) {
        pair<int,int> sum = make_pair(0, 0);
        for(int j=i; j<i+N; j++) {
            sum.first += p[j].first;
            sum.second += p[j].second;
            double tmp = hypot(sum.first, sum.second);
            ans = max(ans, tmp);
        }
    }

    printf("%.15lf\n", ans);
    return 0;
}


Measured memory_bytes: 512