akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define fs first
#define sc second
typedef pair<int,int> P;
int d[11][11],inf=1e7,idd[20][20],w,h,dh[4]={1,0,-1,0},dw[4]={0,1,0,-1};
vector<string> vc;
void bfs(int hh,int ww,int id){
	int dis[20][20];
	rep(i,20) rep(j,20) dis[i][j]=inf;
	queue<P> que;
	que.push(P(hh,ww));
	dis[hh][ww]=0;
	while(!que.empty()){
		P p=que.front();
		que.pop();
		rep(i,4){
			int nh=p.fs+dh[i],nw=p.sc+dw[i];
			if(0<=nh && nh<h && 0<=nw && nw<w && vc[nh][nw]!='x' && dis[nh][nw]==inf){
				que.push(P(nh,nw));
				dis[nh][nw]=dis[p.fs][p.sc]+1;
				if(idd[nh][nw]!=-1) d[id][idd[nh][nw]]=dis[nh][nw];
			}
		}
	}
}
int main(){
	while(true){
		cin >> w >> h;
		if(w==0) break;
		vc.clear();
		rep(i,h){
			string s;
			cin >> s;
			vc.push_back(s);
		}
		rep(i,11) rep(j,11) d[i][j]=inf;
		int cnt=1;
		rep(i,h) rep(j,w){
			if(vc[i][j]=='o'){
				idd[i][j]=0;
			}else if(vc[i][j]=='*'){
				idd[i][j]=cnt;
				cnt++;
			}else idd[i][j]=-1;
		}
		if(cnt==1){
			cout << 0 << endl;
			continue;
		}
		rep(i,h) rep(j,w) if(idd[i][j]!=-1) bfs(i,j,idd[i][j]);
		int a[10];
		rep(i,cnt) a[i]=i;
		int ans=inf;
		do{
			int x=0;
			rep(i,cnt-1) x+=d[a[i]][a[i+1]];
			ans=min(ans,x);
		}while(next_permutation(a+1,a+cnt));
		if(ans==inf) ans=-1;
		cout << ans << endl;
	}
}

Measured memory_bytes: 1236
#include <bits/stdc++.h>
using namespace std;//Nは商品の数　Mは番目

int main() {
  int N, M;
  cin >> N >> M;
  
  vector<int> vec(N);
    for (int i = 0; i < N; i++){
      cin >> vec.at(i);
    }
  
  int S = 0;//Sは総得票
  for (int i = 0; i < N; i++){
    S += vec.at(i);
  }
  
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());//大きい順
  if(vec.at(M-1) * 4 * M < S){//M番目に大きいやつがTより小さい
    cout << "No" << endl;
  }
  else {
    cout << "Yes" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define N 3050
int n;
const double EPS = 1e-10;
double memo[N][N],p[N];

bool equal(double a , double b) {
    return fabs(a - b) <= EPS;
}

double dp(int curr , int head) {
    if (curr > n) return head > (n / 2) ? 1 : 0;
    double &sol = memo[curr][head];
    if (!equal(sol , -1)) return sol;
    return sol = dp(curr + 1 , head + 1) * p[curr] + dp(curr + 1 , head) * (1 - p[curr]);
}

int main() {
    scanf("%d" , &n);
    for (int i = 1 ; i <= n ; i++)
        scanf("%lf" , &p[i]);
    for (int i = 0 ; i < N ; i++)
        for (int j = 0 ; j < N ; j++)
            memo[i][j] = -1;
    printf("%.10lf\n" , dp(1 , 0));
}


Measured memory_bytes: 73088
import math
N = int(input())
p = list(map(int, input().split()))

m = 0
count = 0
for i in range(N):
    if p[i] == i+1:
        m += 1
        if i == N-1:
            count += math.ceil(m/2)
    else:
        count += math.ceil(m/2)
        m = 0
print(count)


Measured memory_bytes: 13812
n, m = map(int, input().split())

x = 0
for i in range(n + m):
    for j in range(n + m):
        if i == j:
            continue
        x1 = i < n
        x2 = j < n
        if (x1 and x2) or (not x1 and not x2):
            x += 1
print(x // 2)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 int N;
  cin >> N ;
  vector<int> P(N);
  for(int i=0;i<N;i++){
    cin >>P.at(i);}

  sort(P.begin(), P.end());
  reverse(P.begin(), P.end());
  int sumA=0;
  for(int i=0;i%2==0 && i<N;i+=2){
  sumA +=P.at(i);
  
  }
int sumB=0;
   for(int i=1;i%2==1 && i<N;i+=2){
  sumB +=P.at(i);
  
  }
  int AA=sumA-sumB;
  cout << AA <<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, z, n) for(int i = z; i < n; i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
//const int INF = 1<<29;
//const int MODINF = 1000000007;
using namespace std;

int main(){
    int64_t H, W;
    cin >> H >> W;
    int64_t S_fin = H * W;
    rep(w, 0, W + 1){
        int64_t S_1 = H * w;
        int64_t S_2 = (H/2) * (W - w);
        int64_t S_2_2 = ((H + 1)/2)*(W - w);
        int64_t S_3 = ((W - w)/2) * H;
        int64_t S_3_2 = ((W - w + 1) / 2) * H;
        int64_t S_dif_1 = max(abs(S_1 - S_2), abs(S_1 - S_2_2));
        int64_t S_dif_2 = max(abs(S_1 - S_3), abs(S_1 - S_3_2));
        int64_t S_dif = min(S_dif_1, S_dif_2);
        //cout << "w " << w << " S " << S_dif << endl;
        S_fin = min(S_fin, S_dif);
    }
    swap(H, W);
    rep(w, 0, W + 1){
        int64_t S_1 = H * w;
        int64_t S_2 = (H/2) * (W - w);
        int64_t S_2_2 = ((H + 1)/2)*(W - w);
        int64_t S_3 = ((W - w)/2) * H;
        int64_t S_3_2 = ((W - w + 1) / 2) * H;
        int64_t S_dif_1 = max(abs(S_1 - S_2), abs(S_1 - S_2_2));
        int64_t S_dif_2 = max(abs(S_1 - S_3), abs(S_1 - S_3_2));
        int64_t S_dif = min(S_dif_1, S_dif_2);
        //cout << "w " << w << " S " << S_dif << endl;
        S_fin = min(S_fin, S_dif);
    }
    cout << S_fin << endl;
}

Measured memory_bytes: 256
package main

import (
  "fmt"
  "strconv"
)

func pow(args ...int) int {
  x, y := args[0], args[1]
  res := 1
  if len(args) == 3 {
    mod := args[2]
    for y != 0 {
      if y & 1 == 1 {res = res * x % mod}
      y >>= 1
      x = x * x % mod
    }
  }  else {
    for y != 0 {
      if y & 1 == 1 {res *= x}
      y >>= 1
      x *= x
    }
  }
  return res
}

func main() {
  var n int 
  fmt.Scan(&n)
  l := len(strconv.Itoa(n))
  cnt := 0
  for i := 0; i < l; i += 2 {
    if i == l - 1 {
      cnt += n - pow(10, i) + 1
    } else {
      cnt += pow(10, i + 1) - pow(10, i)
    }
    
  }
  fmt.Println(cnt)
}

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

typedef long long ll;

int a,b,c,d,e;
int arr[100];

void answer(){
	cin >> a >> b >> c >> d >> e;
	arr[0] = a;
	arr[1] = b;
	arr[2] = c;
	arr[3] = d;
	arr[4] = e;
	for (int i = 0 ; i < 5 ; ++i){
		if ( arr[i] == 0){
			cout << i+1;
		}
 	}
 	}

int main (){
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	answer(); 
return 0 ;
}



Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define ve vector
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
const int mod = 1000000007;

struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
 
  // for prime mod
    mint inv() const {
        return pow(mod-2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res/=a;
    }
};

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

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

int main(){
    int n;
    cin >> n;
    ve<ll> a(n);
    rep(i,n) cin >> a[i];
    ve<ll> so(1e6);
    rep(i,n){
        ll ai = a[i];
        ll sqrta = sqrt(ai);
        for(int j = 2; j <= sqrta; j++){
            if(ai%j == 0){
                ll cnt = 0;
                while(ai%j==0){
                    ai /= j;
                    cnt++;
                }
                if(cnt>so[j]) so[j] = cnt;
            }
        }
        if(ai != 1){
            if(so[ai]==0)so[ai]++;
        }
    }
    mint lcm=1;
    for(int i = 2; i < 1e6+1; i++){
        lcm *= mint(i).pow(so[i]);
    }
    mint ans=0;
    rep(i,n){
        ans += lcm/mint(a[i]);
    }
    cout << ans.x << endl;
    return 0;
}

Measured memory_bytes: 8192
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <set>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
#define PB_VEC(Itr1,Itr2) (Itr1).insert((Itr1).end(),(Itr2).begin(),(Itr2).end())
#define UNIQUE(Itr) sort((Itr).begin(),(Itr).end()); (Itr).erase(unique((Itr).begin(),(Itr).end()),(Itr).end())
#define BOUND(Itr,val) lower_bound((Itr).begin(),(Itr).end(),(val))
typedef long long ll;

int main(){
    
    int a,b,h;
    cin>>a>>b>>h;
    cout<<(a+b)*h/2<<endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <algorithm>
using namespace std;

int N;
long long int A[200007];


int GetDigit(long long int num){
    int digit = 0;
    
    /* 桁数を計算 */
    while(num!=0){
        num = num / 10;
        ++digit;
    }

    return digit;
}

int main(){
    cin >> N;
    long long int ans = 1;

    for(int i = 1;i < N+1;i++){
        cin >> A[i];

        // 10^18 超えているか調査 1000 * 10 = 10000
        if(A[i] == 0){
            cout << "0" << endl;
            exit(0);
        }
    }
        for(int i = 1;i < N+1;i++){

        if(ans * A[i] != 1000000000000000000){

            if(GetDigit(ans) + (GetDigit(A[i]) - 1) >= 19){
                cout << "-1" << endl;
                exit(0);
            }

            if(ans * A[i] > 1000000000000000000){
                cout << "-1" << endl;
                exit(0);
            }
        }

        ans *= A[i];
    }


    cout << ans << endl;
}

Measured memory_bytes: 4420
from typing import Counter


n = int(input())
lis = list(map(int, input().split()))
mod  =10**9+7

ans = 0
if n % 2 == 0:
    b = Counter(lis)
    flag = 1
    for i in b.values():
        if i == 2:
            pass
        else:
            flag = 0
            break
    if flag:
        ans = 2**(n//2)
        print(ans % mod)
    else:
        print(0)
else:
    lis = sorted(lis)
    lis = lis[1:]
    b = Counter(lis)
    flag = 1
    for i in b.values():
        if i == 2:
            pass
        else:
            flag = 0
            break
    if flag:
        ans = 2**(n//2)
        print(ans % mod)
    else:
        print(0)


Measured memory_bytes: 21376
import java.util.Scanner;


public class Main {

	public static Scanner scanner = new Scanner(System.in);
	public static void main(String[] args) {
		String s = scanner.next();
		int mod = 0;
		for(int i=0; i<s.length(); i++) {
			int n = ((int)(s.charAt(i) - '0'));
			mod += n;
		}
		
		if(Long.valueOf(s) % mod == 0)
			System.out.println("Yes");
		else
			System.out.println("No");
	}

}


Measured memory_bytes: 21716
// This amazing code is by Eric Sunli Chen.
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
template<typename T> bool get_int(T &x)
{
	char a=getchar();
	bool neg=false;
	x=0;
	for(; (a>'9'||a<'0')&&a!='-'&&a!=EOF; a=getchar());
	if(a=='-')neg=true,a=getchar();if(a==EOF)return false;
	for(; a<='9'&&a>='0'; a=getchar())x=x*10+a-'0';
	if(neg)x=-x;return true;
}
template<typename T> void print_int(T x)
{
	if(x<0)putchar('-'),x=-x;
	short a[20]= {},sz=0;
	while(x>0)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1; i>=0; i--)putchar('0'+a[i]);
}
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define get1(a) get_int(a)
#define get2(a,b) (get1(a)&&get1(b))
#define get3(a,b,c) (get1(a)&&get2(b,c))
#define printendl(a) print_int(a),puts("")
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int,int> pii;
const int inf=0x3f3f3f3f;
const LL Linf=1ll<<61;
const double pi=acos(-1.0);
 
const int mod=1e9+7;
const int rev2=(mod+1)/2;
 
struct data
{
	int a[3];
	data(int t1=0,int t2=0,int t3=0){a[0]=t1;a[1]=t2;a[2]=t3;}
	void clear(){a[0]=a[1]=a[2]=0;}
	data comb(const data&b)
	{
		data ret;
		for(int i=0;i<3;i++)for(int j=0;j<3;j++)
		{
			int k=min(2,i+j);
			ret.a[k]=(ret.a[k]+1ll*a[i]*b.a[j])%mod;
		}
		return ret;
	}
	void reduce(){a[0]+=a[2];if(a[0]>=mod)a[0]-=mod;a[2]=0;}
};
vector<int> g[200111];
vector<data> q[200111];
int n;
void dfs(int x)
{
	int mx=-1;
	for(auto v:g[x]){dfs(v);if(mx==-1||q[mx].size()<q[v].size())mx=v;}
	if(mx!=-1)swap(q[x],q[mx]);
	int tmx=0;
	for(auto v:g[x])
	{
		tmx=max(tmx,(int)q[v].size());
		for(int i=(int)q[x].size()-1;i>=(int)q[x].size()-(int)q[v].size();i--)
			q[x][i]=q[x][i].comb(q[v][i-q[x].size()+q[v].size()]);
	}
	for(int i=(int)q[x].size()-1;i>=(int)q[x].size()-tmx;i--)q[x][i].reduce();
	q[x].pb(data(rev2,rev2,0));
}
int main()
{
	get1(n);for(int i=1,p;i<=n;i++){get1(p);g[p].pb(i);}
	dfs(0);
	int p=1,ans=0;for(int i=0;i<=n;i++)p=p*2%mod;
	for(auto&x:q[0])ans=(ans+1ll*p*x.a[1])%mod;
	printendl(ans);
	return 0;
}

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

N, K = map(int, input().split())
A = list(map(int, input().split()))

dist = [0]*N
dist[0] = 0
cnt = 0
cp = 0
while cnt < N+10:
    if cnt == K:
        print(cp + 1)
        exit()
    np = A[cp]-1
    if np == cp: # ikidomari
        print(np+1)
        exit()
    elif dist[np]>0 or np == 0: # loop
        lstep = cnt - dist[np] + 1
        cp = np
        break
    dist[np] = cnt + 1
    cp = np
    cnt += 1

K -= dist[cp]
K %= lstep
cnt = 0
while cnt < K:
    np = A[cp]-1
    cp = np
    cnt += 1
    
print(cp+1)

Measured memory_bytes: 33860
#include <cstdint>
#include <iostream>

template <std::uint32_t mod>
class modint
{
    using i64 = std::int64_t;
    using u32 = std::uint32_t;
    using u64 = std::int64_t;

    static_assert(mod < (u32(1) << 31), "mod must be less than 2**31");

public:
    u32 v;

    constexpr modint(const i64 x = 0) noexcept
        : v(x < 0 ? mod - 1 - -(x + 1) % mod : x % mod) {}
    constexpr modint operator+(const modint rhs) const noexcept
    {
        return modint(*this) += rhs;
    }
    constexpr modint operator-(const modint rhs) const noexcept
    {
        return modint(*this) -= rhs;
    }
    constexpr modint operator*(const modint rhs) const noexcept
    {
        return modint(*this) *= rhs;
    }
    constexpr modint operator/(const modint rhs) const noexcept
    {
        return modint(*this) /= rhs;
    }
    constexpr modint &operator+=(const modint rhs) noexcept
    {
        v += rhs.v;
        if (v >= mod)
            v -= mod;
        return *this;
    }
    constexpr modint &operator-=(const modint rhs) noexcept
    {
        if (v < rhs.v)
            v += mod;
        v -= rhs.v;
        return *this;
    }
    constexpr modint &operator*=(const modint rhs) noexcept
    {
        v = u64(v) * rhs.v % mod;
        return *this;
    }
    constexpr modint &operator/=(const modint rhs) noexcept
    {
        *this *= rhs.pow(mod - 2);
    }
    constexpr modint pow(u32 exp) noexcept
    {
        modint self(*this), ret(1);
        while (exp != 0)
        {
            if (exp % 2 != 0)
                ret *= self;
            self *= self;
            exp /= 2;
        }
        return ret;
    }
};

template <std::uint32_t mod>
std::istream &operator>>(std::istream &is, modint<mod> &rhs)
{
    std::int64_t v;
    is >> v;
    rhs = modint<mod>(v);
    return is;
}

template <std::uint32_t mod>
std::ostream &operator<<(std::ostream &os, const modint<mod> &rhs)
{
    os << rhs.v;
    return os;
}

#include <vector>

int main()
{
    using mint = modint<998244353>;
    using std::vector;

    int a, b, c, d;
    std::cin >> a >> b >> c >> d;

    vector<vector<mint>> dp(c + 1, vector<mint>(d + 1));

    for (int i = a; i <= c; ++i)
    {
        for (int j = b; j <= d; ++j)
        {
            if (i == a && j == b)
            {
                dp[i][j] = 1;
                continue;
            }
            dp[i][j] = dp[i - 1][j] * j + dp[i][j - 1] * i -
                       dp[i - 1][j - 1] * (i - 1) * (j - 1);
        }
    }

    std::cout << dp[c][d] << std::endl;
}


Measured memory_bytes: 38512
inf = 10 ** 9 + 1
x, y, a, b, c = map(int, input().split())

r = [int(i) for i in input().split()] + [inf]
g = [int(i) for i in input().split()] + [inf]
m = [int(i) for i in input().split()]
r.sort()
g.sort()
m.sort(reverse=True)
i = -x-1
j = -y-1
S = 0

for k in range(c):
    if r[i] <= g[j]:
        if m[k] > r[i]:
            S += m[k]
            i += 1
        else:
            break
    else:
        if m[k] > g[j]:
            S += m[k]
            j += 1
        else:
            break

S += sum(r[i:-1]) + sum(g[j:-1])
print(S)

Measured memory_bytes: 23072
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cstdint>
#include <cmath>
#include <functional>
#include <limits>
#include <cassert>
#include <bitset>

using namespace std;

/* template */

using ll = long long;

void debug_out() { std::cout << std::endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cout << "debug: "; debug_out(__VA_ARGS__)
#else
#define debug(...) 
#endif

#define rep(i, a, n) for (int i = (int)(a); i < (int)(n); i++)
#define rrep(i, a, n) for (int i = ((int)(n-1)); i >= (int)(a); i--)
#define Rep(i, a, n) for (long long i = (long long)(a); i< (long long)(n); i++)
#define RRep(i, a, n) for (long long i = ((long long)(n-1ll)); i>=(long long)(a); i--)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}

struct Edge{
    int to;
    ll weight;
    Edge(int t, ll w) : to(t), weight(w){ }
};

struct edge{
    int from;
    int to;
    ll weight;
    edge(int f,int t,ll w) : from(f), to(t), weight(w){ }
};


using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;
using edges = vector<edge>;

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

template <class T>
T lcm(T a, T b){
    return (a*b)/gcd(a,b);
}

bool isPalindrome(string s){
    string t = s;
    reverse(all(t));
    return s==t;
}

constexpr ll LNF = 1LL<<60;

constexpr int INF = 1e9+7;

const double PI=3.14159265358979323846;


vector<int> dx = {-1,0,1,0,-1,1,-1,1};
vector<int> dy = {0,-1,0,1,1,-1,-1,1};

/* template */

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n; ll x; cin >> n >> x;
    vector<ll> a(n);
    ll ans = 0ll;
    rep(i,0,n){
        cin >> a[i];
        ans += a[i];
    }
    rep(i,1,n){
        ll s = 0;
        ll last = a[n-1];
        rrep(j,1,n){
            chmin(a[j],a[j-1]);
            s += a[j];
        }
        chmin(a[0],last);
        s += a[0];
        chmin(ans,s+x*i);
    }
    cout << ans << endl;
} 

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
#include <tuple>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
#define modulo 1000000007 // 10^9 + 7
#define INF 1000000000 // 10^9
#define LLINF 1LL<<60


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

	int N, K;
	cin >> N >> K;
	vector<vector<ll>> T(N);
	for (int i = 0; i < N; i++) {
		int tmp; cin >> tmp;
		ll d; cin >> d;
		T[tmp - 1].push_back(d);
	}

	for (int i = 0; i < N; i++) sort(T[i].begin(), T[i].end(), greater<ll>());

	vector<ll> X; // 各味のうち最もおいしさが大きいもの
	vector<ll> Y; // 各味のうちおいしさが2番手以降のもの全て
	for (int i = 0; i < N; i++) {
		int n = T[i].size();
		if (n > 0) {
			X.push_back(T[i][0]);
			for (int j = 1; j < n; j++)Y.push_back(T[i][j]);
		}
	}

	sort(X.begin(), X.end(), greater<ll>());
	sort(Y.begin(), Y.end(), greater<ll>());

	vector<ll> SX(X.size()); // SX[i] : Xのうちの先頭(i+1)個のおいしさの総和
	if (X.size() > 0) SX[0] = X[0];
	for (int i = 1; i < X.size(); i++) SX[i] = SX[i - 1] + X[i];

	vector<ll> SY(Y.size()); // SY[i] : Yのうちの先頭(i+1)個のおいしさの総和
	if (Y.size() > 0) SY[0] = Y[0];
	for (int i = 1; i < Y.size(); i++) SY[i] = SY[i - 1] + Y[i];

	ll ans = 0LL;
	for (ll i = 1; i <= X.size(); i++) {
		// 味をi種類としたときの最大満足度を求めていく
		if (K - i <= SY.size()) ans = max(ans, SX[i - 1] + i * i + (K - i > 0 ? SY[K - i - 1] : 0)); // i*iが桁溢れしないようにする
	}

	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 7412
fn main() {
    let n = read();
    let ans = solve(n);
    write(ans);
}

fn read() -> i32 {
    let mut l1 = String::new();
    std::io::stdin().read_line(&mut l1).ok();
    let n: i32 = l1.trim().parse().unwrap();

    n
}

fn write(a: u64) {
    println!("{}", a);
}

fn solve(n: i32) -> u64 {
    let mut w = 0u64;
    for c in 1..=n {
        if c % 3 != 0 && c % 5 != 0 {
            w += c as u64;
        }
    }

    return w;
}

Measured memory_bytes: 2116
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<set>

using namespace std;

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

	int count = 0;
	for (int i = 0; i < N; i++) {
		int h;
		cin >> h;
		if (h >= K) {
			count++;
		}
	}
	cout << count << endl;
	
}


Measured memory_bytes: 3620
#include <iostream>
#include <utility>
using namespace std;
int main(void){
    int x, y;
    
    for(int i=0; i<=10000; i++){
    cin >> x >> y;
    
    if(x==0 && y==0){
        break;
    }
    
    if(x>y){
        
        swap(x,y);
    
    }
    
    cout << x <<" "<< y << endl;
    }
}


Measured memory_bytes: 3060
#include<iostream>
#define int long long
using namespace std;
const int maxn=200010;
int n;
int a[maxn];
signed main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    int ans=0;
    int l=0,sum=0,yihuo=0;
    for(int i=1;i<=n;i++)
    {
        while(l+1<=n && (yihuo^a[l+1])==(sum+a[l+1]))
        {
            yihuo^=a[l+1];
            sum+=a[l+1];
            l++;
        }
        ans+=l-i+1;
        yihuo^=a[i];
        sum-=a[i];
    }
    cout<<ans<<endl;
    return 0;
}


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

int main() {
  int H,W;
  cin >> H >> W;
  
  vector<vector<char>> masu(H,vector<char>(W));
  
  for (int i=0; i<H; i++) {
    for (int j=0; j<W; j++) {
      cin >> masu.at(i).at(j);
    }
  }
  
  vector<vector<int>> A(H,vector<int>(W));
  
  for (int i=0; i<H; i++) {
    int I=0, count=0;
    
    while (I<W && masu.at(i).at(I) == '.') {
      count ++;
      I ++;
    }
    
    if (count == W) {
      for (int j=0; j<W; j++) {
        A.at(i).at(j) = 1;
      }
    }
  }
  
  for (int i=0; i<W; i++) {
    int I=0, count=0;
    
    while (I<H && masu.at(I).at(i) == '.') {
      count ++;
      I ++;
    }
    
    if (count == H) {
      for (int j=0; j<H; j++) {
        A.at(j).at(i) = 1;
      }
    }
  }
  
  for (int i=0; i<H; i++) {
    int C=0;
    
    for (int j=0; j<W; j++) {
      if (A.at(i).at(j) == 1) {
        C ++;
      }
    }
    
    if (C == W) {
      continue;
    }
    
    for (int j=0; j<W; j++) {
      if (A.at(i).at(j) == 0) {
        cout << masu.at(i).at(j);
      }
    }
    
    cout << endl;
  }
}

Measured memory_bytes: 3632
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
input:
acac
acm

output:
2
"""

import sys


def solve():
    dp = [[0] * (len_w2 + 1) for _ in range(len_w1 + 1)]

    for i in range(len_w1 + 1):
        for j in range(len_w2 + 1):
            if not i:
                dp[i][j] = j
            elif not j:
                dp[i][j] = i

            elif w1[i - 1] == w2[j - 1]:
                dp[i][j] = dp[i - 1][j - 1]

            else:
                dp[i][j] = min(dp[i][j - 1], dp[i - 1][j], dp[i - 1][j - 1]) + 1

    return dp[-1][-1]


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    w1, w2 = _input
    len_w1, len_w2 = len(w1), len(w2)
    print(solve())

Measured memory_bytes: 43720
#include <iostream>
#include <iomanip>
#include <random>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <sstream>
#include <bitset>
#include <cassert>
#include <fstream>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
	#define DBG(X) cout << #X << "=" << (X) << endl;
#else
	#define DBG(X)
	#define endl '\n'
#endif
 
using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld  = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int INT_INF = (int)(2e9);
const ll  LL_INF  = (ll)(2e18);

const ll mod = 1e9 + 7;
const int NIL = -1;
static mt19937 _g(time(nullptr));

inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for(auto el: v) cout << el << " "; return os; }

const int MAX_VALUE = 51;
const int MAX_N = 100;

bool cango(ll x, ll y, ll msk)
{
	if(x == y)
		return 0;

	if(y > x)
		return false;

	for(ll k = 1; k < MAX_VALUE; ++k)
	{
		if(x % k == y && ((msk >> k) & 1LL) > 0)
			return true;
	}

	return false;
}

int a[MAX_N], b[MAX_N], n;
int met[MAX_VALUE], mark = 13;
int q[MAX_VALUE], qsz;

bool check(ll msk)
{
	for(int i = 0; i < n; ++i)
	{
		int start = a[i], finish = b[i];

		++mark;
		qsz = 0;

		q[qsz++] = start;
		met[start] = mark;

		for(int j = 0; j < qsz; ++j)
		{
			int v = q[j];

			for(int u = 0; u < MAX_VALUE; ++u)
			{
				if(met[u] != mark && cango(v, u, msk))
				{
					met[u] = mark;
					q[qsz++] = u;
				}
			}
		}

		if(met[finish] != mark)
			return false;
	}

	return true;
}

void solve()
{
	cin >> n;

	for(int i = 0; i < n; ++i)
		cin >> a[i];

	for(int i = 0; i < n; ++i)
		cin >> b[i];

	ll msk = 0;

	for(ll k = 1; k < MAX_VALUE; ++k)
		msk |= (1LL << k);

	if(!check(msk))
	{
		cout << NIL << endl;
		return;		
	}

	for(ll k = MAX_VALUE - 1; k > 0; --k)
	{
		ll msk2 = msk ^ (1LL << k);

		if(check(msk2))
			msk = msk2;
	}

	cout << msk << endl;
}

int main()
{
	fast_io();
	solve();

	return 0;
}


Measured memory_bytes: 256
s = gets.chomp.chars
h = []
ans = 0
[true, false].repeated_permutation(s.length - 1) do |b|
  h = []
  h << s[0]
  for i in 0..s.length-2
    h << '+' if b[i]
    h << s[i + 1]
  end
  ans += eval(h.join)
end
puts ans

Measured memory_bytes: 2044
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>
#include <stdexcept>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define FOR(i, place_to_place, done) for (int i = (place_to_place); i < (done); ++i)
#define all(place_to_place) (place_to_place).begin(), (place_to_place).end()
#define x first
#define y second
#define debug(place_to_place) cout << (place_to_place) << endl
namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;
template <class T>
bool chmax(T &place_to_place, const T &b)
{
	if (place_to_place < b)
	{
		place_to_place = b;
		return 1;
	}
	return 0;
}
template <class T>
bool chmin(T &place_to_place, const T &b)
{
	if (place_to_place > b)
	{
		place_to_place = b;
		return 1;
	}
	return 0;
}

ll M = 1000000007;

void solve()
{
	int n;
	ll K;
	cin >> n >> K;
	vector<int> place_to_place(n+1);
	vector<int> time_to_place;// 1 indexed
	time_to_place.push_back(1);
	rep(i, n)
	{
		cin >> place_to_place[i+1];
	}
	int here = 1;
	map<int, int> place_to_time; // place_to_time[place]=now
	place_to_time[1] = 0;
	int cycle_time = 0;
	int last_visit_time = 0;
	//bool dag = false;
	int now = 0;
	while (1)
	{
		now++;
		here = place_to_place[here];

		if (place_to_time[here])
		{
			last_visit_time = place_to_time[here];
			cycle_time = now - place_to_time[here];
			break;
		}
		else
		{
			place_to_time[here] = now;
		}
		
		time_to_place.push_back(here);
	}
	vector<int> cycle;// 0-indexed [last_visit_time, nextvisit)
	//time_to_place
	rep(i, cycle_time)
	{
		cycle.push_back(time_to_place[i + last_visit_time]);
	}
	int destination = 0;
	//  K = time
	//	last_visit_time = now 
	if (K >= last_visit_time)
	{
		K -= last_visit_time;
		K %= cycle_time;
		destination = cycle[K];
	}
	else
	{
		destination = time_to_place[K];
	}
	cout << destination << endl;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	solve();
	return 0;
}


Measured memory_bytes: 14980
#include <stdio.h>
int main()
{
    char a,b,c;
    c='D';
    scanf("%c %c",&a,&b);
    if(a=='H')
        if(b=='H')
        c='H';
    if(a=='D')
        if(b=='D')
        c='H';
    printf("%c\n",c);
    return 0;
}


Measured memory_bytes: 128
a = input()
b = input()

def solve(a,b,n,i):
    if n == i:
        return(print("EQUAL"))
    if a[i] >b[i]:
        print("GREATER")
    elif b[i]>a[i]:
        print("LESS")
    else:
        solve(a,b,n,i+1)

if len(a)>len(b):
    print("GREATER")
elif len(b)>len(a):
    print("LESS")
else:
    solve(a,b,len(a),0)


Measured memory_bytes: 38384
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>
#include <chrono>
#include <random>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define FIND(s, e) ((s).find(e) != (s).end())
#define EB emplace_back

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

VT<VT<string>> S;

int main(void) {
    int H, W;
    cin >> H >> W;
    S.resize(H, VT<string>(W));
    for_each(ALL(S), [](VT<string> &v) {
        for_each(ALL(v), [](auto &e){cin >> e;});
    });
    REP(i, H)REP(j, W) {
        if (S[i][j] == "snuke") {
            cout << (char)('A' + j) << i + 1 << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(b);i>(a);--i)
#define eper(i,a,b) for(int i=((int)(a));i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF (1<<30)-1
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

ll x, y;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
    cin >> x >> y;
    ll ans = 0, t = x;
    while (t <= y) {
        t *= 2;
        ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
#include<iomanip>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;
typedef pair<LL,int> LP;
const int INF=1<<30;
const LL MAX=1e9+7;

void array_show(int *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(LL *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n'));
}
void print_YES_NO(bool answer){cout<<(answer?"YES":"NO")<<endl;}
void print_Yes_No(bool answer){cout<<(answer?"Yes":"No")<<endl;}
void print_POSSIBLE_IMPOSSIBLE(bool answer){cout<<(answer?"POSSIBLE":"IMPOSSIBLE")<<endl;}

int dp[10005];
int t[4][2];

int main(){
	int n,m;
	int i,j,k;
	int a,b,c;
	cin>>n;
	for(i=0;i<2;i++){
		for(j=0;j<4;j++)cin>>t[j][i];
	}
	for(j=0;j<10005;j++)dp[j]=INF;
	dp[0]=0;
	for(i=0;i<4;i++){
		for(j=0;j<=n;j++){
			for(k=1;k<=t[i][1];k++){
				dp[j+k]=min(dp[j+k],dp[j]+t[i][0]);
			}
		}
		//array_show(dp,n+1);
	}
	cout<<dp[n]<<endl;
}



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

int main()
{
	int n, hp=0;
	cin>>n;
	while(1)
	{
		if(n>=500)
		{
			hp += 1000;
			n -= 500;
		}
		else if(n>=5)
		{
			hp += 5;
			n -= 5;
		}
		if(n<5) break;
	}
	cout<<hp;
	
	
	return 0;
}


Measured memory_bytes: 256
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include<bits/stdc++.h>
using namespace __gnu_pbds;
using namespace std;
#define int long long
#define ll  long long
#define ull unsigned long long 
#define ff first 
#define ss second
#define eb(x) emplace_back(x)
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define start_routine() int begtime = clock();
#define end_routine() int endtime = clock(); \
                      cerr << "" << "Time elapsed: " << \
                      (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n"; \
                      return 0
#define testcase(t) int t;cin>>t;while(t--)
#define mp(x,y) make_pair(x,y)
#define in(x) insert(x)
#define rep(i,a,b)  for (__typeof((b)) i=(a);i<=(b);i++)
#define nrep(i,a,b)  for (__typeof((b)) i=(b);i>=(a);i--)
#define PI 3.14159265358979323846
#define SP(x) setprecision(x)
#define reflex ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define M 998244353
#define sz(a) (int)a.size()
#define endl "\n"
#define all(v) v.begin(), v.end()
#define UNIQUE(x) x.resize(distance(x.begin(), unique(all(x))))
#define mem(arr,val) memset(arr,val,sizeof(arr)) //For "0" and "-1"                  
#define inp0(a,n) rep(i,0,n-1) cin>>a[i];
#define inp1(a,n) rep(i,1,n) cin>>a[i]; 
#define prll(x) printf("%lld",x)
#define nth_ele(v,n) nth_element(v.begin(), v.begin()+n ,v.end())//O(N)
#define DEBUG(x) cerr << (#x) << ": " << (x) << endl
#define DEBUGV(x) for(auto IT:x) cout<<IT.ff<<" "<<IT.ss<<endl; cout<<endl;
#define minheap priority_queue <int, vector<int>, greater<int>>
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
ll gcd(ll n1, ll n2){if(n2!=0) return gcd(n2, n1%n2);else return n1;}
ll powerM(ll a,ll b){if(b==0) return 1LL;  if(b==1) return a%M; ll x=powerM(a,b/2)%M; if(b&1){return ((((a%M)*(x%M))%M)*(x%M))%M;}return ((x%M)*(x%M))%M;}
ll power(ll a,ll b){if(b==0) return 1;  if(b==1) return a; ll x=power(a,b/2); if(b&1){return ((((a)*(x)))*(x));}return ((x)*(x));}
 
const ll INF = (ll)2e18+77; 
const int SIZE = 200005;


vector<int> adj[SIZE];
signed main(){
    int n,m;
    cin>>n>>m;
    bool yes=true;
    rep(i,1,m){
        int x,y;
        cin>>x>>y;
        adj[x].pb(y);
        adj[y].pb(x);
    }
    int par[n+3];
    mem(par,-1);

    int l[n+5];
    mem(l,0);
    queue <int> q;
    l[1]=1;
    q.push(1);
    while(q.empty()!=1){
        int y=q.front();
        q.pop();
        for(int k=0;k<adj[y].size();k++){
            if(l[adj[y][k]]==0){
                par[adj[y][k]] = y;
                l[adj[y][k]]=l[y]+1;
                q.push(adj[y][k]);
            }
        }
    }

    rep(i,2,n){
        if(par[i]==-1) yes=false;
    }
    if(yes){
        cout<<"Yes\n";
        rep(i,2,n) cout<<par[i]<<endl;
    }
    else cout<<"No\n";

} 

Measured memory_bytes: 16112
#include<algorithm>
#include<bitset>
#include<climits>
#include<cmath>
#include<cstdlib>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<string>
#include<time.h>
#include<tuple>
#include<utility>
#include<vector>

using namespace std;
const long mod = 1000000007;
long gcd(long x, long y) { if (x > y) { return gcd(y, x); } long r; while (y != 0) { r = x % y; x = y; y = r; }return x; }
long lcm(long x, long y) { return(x / gcd(x, y)) * y; }

int main() {

	long res = 0;
	string S, T; cin >> S >> T;

	for (int i = 0; i < 3; i++) if (S[i] == T[i]) res++;
	cout << res << endl;

}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int i,j,w,h;
	while(1)
	{
	scanf("%d%d",&w,&h);
	if(w==0&&h==0)break;
	for(i=0;i<w;i++)
	  {
		for(j=0;j<h;j++)
		{
         if(i==0||i==w-1||j==0||j==h-1)
         {
         	printf("#");
         }
         else
         {
         	printf(".");
         }
		}
		printf("\n");
	   }
	   printf("\n");
    }
    return 0;
}

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

using namespace std;

#define rep(i, a, b) for (auto i = (a); i < (b); ++i)
#define rrep(i, a, b) for (auto i = (a); i > (b); --i)
template <typename T>
bool chmax(T &a, T b) { return a < b ? (a = b, true) : false; }

map<int, int> idx;

void solve(int &r, int &n)
{
  int height[50];
  fill(height, height + 50, 0);
  rep(i, 0, n) {
    int lx, rx, h; cin >> lx >> rx >> h;
    rep(j, lx, rx) {
      chmax(height[idx[j]], h);
    }
  }
  double ok = 0., ng = 21.;
  rep(cnt, 0, 50) {
    double mid = (ok + ng) / 2;
    auto check = [&](double mid) {
      rep(i, -20, 20) {
        double circle1 = (r * r <= i * i ? 0. : sqrt(r * r - i * i) - (r - mid));
        double circle2 = (r * r <= (i + 1) * (i + 1) ? 0. : sqrt(r * r - (i + 1) * (i + 1)) - (r - mid));
        double ch = max(circle1, circle2);
        if (height[idx[i]] < ch) return false;
      }
      return true;
    };
    if (check(mid)) ok = mid;
    else ng = mid;
  }
  cout << ok << endl;
}

int main()
{
  int r, n;
  rep(i, -20, 21) {
    idx[i] = i + 20;
  }
  while (cin >> r >> n)
  {
    if (r == 0 && n == 0) break;
    solve(r, n);
  }
}


Measured memory_bytes: 3232
#include<stdio.h>
#include<math.h>
int main(void){

    int a,b;
    scanf("%d %d",&a,&b);
    long long int A=0,B=0;
    for(int k=0;k<b;k++){
        A += a*pow(10,k); 
    }
    for(int k=0;k<a;k++){
        B += b*pow(10,k); 
    }
    //printf("%d",A);
  	if(a<b){
    	printf("%lld",A);
    }else{
    	printf("%lld",B);
    }
    return 0;
}

Measured memory_bytes: 128
n, m = [int(x) for x in input().split()]
img_a = [input() for _ in range(n)]
img_b = [input() for _ in range(m)]

found = False
for a in range(n - m + 1):
    border = 0
    isok = True
    while isok and not found:
        for b in range(m):
            if img_b[b] in img_a[b+a][border:]:
                if b == 0:
                    index = img_a[a].index(img_b[0], border)
                current_index = img_a[b+a].index(img_b[b], border)
                if current_index == index:
                    continue
                elif current_index > index:
                    border = current_index
                    break
                else:
                    border = index
                    break
            else:   # if not substring in string.
                isok = False
                break

        else: # if not loop broken.
            ans = "Yes"
            found = True
            break
    if found:
        break
else: # if not 'found==True' even after last loop, then it means B is not in A.
    ans = "No"
        
print(ans)

Measured memory_bytes: 3064
#include <stdio.h>
#include <iostream>
#include <vector>
#include <utility>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define mp make_pair
typedef long long Int;

int N, M, Q;
vector<pair<int, Int> > g[200000];
Int hi[200000], cy[64];
bool vis[200000];

void add(Int b) {
    for (int x = 63; b; x--) if (b&(1LL<<x)) {
        if (cy[x] == 0) { cy[x] = b; return ; }
        b ^= cy[x];
    }
}

void rec(int at, int pre, Int bit) {
    if (vis[at]) {
        add(bit^hi[at]);
        return ;
    }
    vis[at] = 1;
    hi[at] = bit;
    rep (i, g[at].size()) {
        const int to = g[at][i].first;
        if (to == pre) continue;
        rec(to, at, bit^g[at][i].second);
    }
}

void build() {
    rec(0, -1, 0);
}

Int solve(int u, int v) {
    Int ans = hi[u]^hi[v];
    for (int x = 63; x >= 0; x--) if (!(ans&(1LL<<x))) ans ^= cy[x];
    return ans;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> N >> M >> Q;
    rep (i, M) {
        int f, t;
        Int p;
        cin >> f >> t >> p;
        g[f].push_back(mp(t, p));
        g[t].push_back(mp(f, p));
    }
    build();
    rep (_, Q) {
        int a, b;
        cin >> a >> b;
        cout << solve(a, b) << endl;
    }
    return 0;
}

Measured memory_bytes: 16660
#include <stdio.h>

int Both(int a, int b,int x, int y){
    return (a*x) + (b*y);
}

int minHalf (int a, int b, int c, int x, int y){
    int difference;
    difference = x - y;
    
    int half_cost, both_cost;
    if(difference > 0){
        half_cost = c * (y * 2);
        both_cost = a * difference;
    } else if (difference == 0){
        half_cost = 0;
        both_cost = (a * x) + (b * y);
    } else {
        difference = difference * (-1);
        half_cost = c * (x * 2);
        both_cost = b * difference;
    }
    return half_cost + both_cost;
}

int maxHalf (int c, int x, int y){
    return c * (x > y ? x : y) * 2;
}

typedef struct {
    int both;
    int min_half;
    int max_half;
}ans;

int main(void){
    // Your code here!
    int a,b,c,x,y;
    scanf("%d %d %d %d %d",&a,&b,&c,&x,&y);
    
    ans answer, *p;
    p = &answer;
    
    p->both = Both(a,b,x,y);
    p->min_half = minHalf(a,b,c,x,y);
    p->max_half = maxHalf(c,x,y);
    if(answer.min_half < answer.max_half){
        printf("%d", answer.both < answer.min_half ? answer.both : answer.min_half);
    }else{
        printf("%d", answer.both < answer.max_half ? answer.both : answer.max_half);
    }
    
}



Measured memory_bytes: 128
#include<iostream>

using namespace std;

int main(void) {
    string s;
    int min = -1, max = -1;

    cin >> s;

    for (int i = 0; i <= s.length(); i++) {
        if (s[i] == 'A' && min == -1) {
            min = i;
        }

        if (s[i] == 'Z') {
            max = i;
        }
    }

    cout << max - min + 1 << endl;
}


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

int main() {
  int N;
  cin >> N;
  string s;
    cin >> s;
  sort(s.begin(),s.end());
  int count=0;
  for(int i=0;i<N;i++) {
    if (s.at(i)=='B'){
      count++;
    }
    else {
      break;
    }
  }
  if (count >= N-count){
    cout << "No" << endl;
  }
  else {
    cout << "Yes" << endl;
  }
}

Measured memory_bytes: 256
// Created by martinezdiego on 19/5/19

#include <bits/stdc++.h>

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  int r = n % 100, l = n / 100;
  if (1 <= l and l <= 12) {
    if (1 <= r and r <= 12)
      cout << "AMBIGUOUS" << '\n';
    else
      cout << "MMYY" << '\n';
  }
  else if (1 <= r and r <= 12) 
    cout << "YYMM" << '\n';
  else
    cout << "NA" << '\n';
  return 0;
}


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

using namespace std;

#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define mmp make_pair
#define st first
#define nd second
#define rd third
#define ll long long
#define pii pair <int, int>
#define tri pair <pii, int>
#define itr pair <int, pii>
#define PQ priority_queue
#define all(v) (v).begin(), (v).end()
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); i++)
#define FOR(i, a, n) for (int (i) = (a); (i) < (int)(n); i++)
#define FORN(i, a, n) for (int (i) = (a); (i) > (int)(n); i--)
#define Rep(i, n) for (int (i) = 0; (i) <= (int)(n); i++)
#define For(i, a, n) for (int (i) = (a); (i) <= (int)(n); i++)
#define Forn(i, a, n) for (int (i) = (a); (i) >= (int)(n); i--)
#define FORD(i, n) for (int (i) = (int)(n) - 1; i>= 0; i--)
#define rep(i, n) for (int (i) = 1; (i) <= (int)(n); i++)
#define EACH(it, a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)

#define DEBUG(x) cout << #x << " = " << (x) << endl;
#define PR(a, n) {cout << #a << " = "; FOR(_, 1, n) cout << a[_] << ' '; puts(""); }
#define PRO(a, n) { cout << #a << " = "; REP(_, n) cout << a[_] << ' '; puts(""); }
#define pi 3.1415926535897932384626433832795028841971
//#define LOCAL

const int INF = 1 << 30;
const int N = 1005;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};

inline ll read()
{
	ll x = 0; int f = 1, c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + (c ^ 48);
	return x * f;
}

ll h; 

ll dfs(ll x)
{
	if (x == 1) return 1; 
	
	ll res = dfs(x / 2) * 2 + 1; 
	return res; 
}

int main()
{
	#ifdef LOCAL
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif
	
	h = read(); 
	printf("%lld", dfs(h)); 
	
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;

int main(){
	int n,k;
	cin>>n>>k;
	int x[101010]={};
	int t=-1;
	FOR(i,0,n){
		cin>>x[i];
		if(t==-1&&x[i]>=0)t=x[i];
	}
	int anst=2*mod;
	FOR(i,0,n-k+1){
		int l=i,r=i+k-1,ans=0;
		if(x[l]>=0){
			ans=x[r];
		}else if(x[r]<=0){
			ans=-x[l];
		}else{
			int rr=x[r],ll=-x[l];
			ans=rr+ll+min(ll,rr);
		}
		anst=min(ans,anst);
		//cerr<<i<<" "<<anst<<endl;
	}
	cout<<anst;

    return 0;
}


Measured memory_bytes: 1272