akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <queue>
using namespace std;

int main(){
    int H,W;
    cin >> H>>W;
    char map[W][H];
    int count=0;
    for(int y=0;y<H;y++){
        for(int x=0;x<W;x++){
            cin >> map[x][y];
            if(map[x][y]=='#'){
                count++;
            }
        }
    }

    queue<int > que;
    int dist[W][H];

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

    fill(dist[0],dist[W],-1);
    dist[0][0]=0;
    que.push(0);


    while(!que.empty()){
        int x=que.front()%W;
        int y=que.front()/W;
        que.pop();
        for(int i=0;i<4;i++){
            if(((x+dx[i])>=W)||((x+dx[i])<0)){
                continue;
            }
            if(((y+dy[i])>=H)||((y+dy[i])<0)){
                continue;
            }

            if((map[x+dx[i]][y+dy[i]]!='#')&&(dist[x+dx[i]][y+dy[i]]==-1)){
                dist[x+dx[i]][y+dy[i]]=dist[x][y]+1;
                que.push(x+dx[i]+W*(y+dy[i]));
            }
        }
    }

    if(dist[W-1][H-1]==-1){
        cout << -1<<endl;
        return 0;
    }
    int ans=W*H-dist[W-1][H-1]-count-1;
    cout << ans<<endl;
    return 0;
}


Measured memory_bytes: 256
/*
ID: alec3
LANG: C++14
PROG: frac1
CLASSIFICATION: flood fill
*/

#include <bits/stdc++.h>
#define check(x) cout<<(#x)<<": "<<x<<" ";
#define io ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ss second
#define ff first
#define pb push_back
#define lb lower_bound
#define ub upper_bound

typedef long long ll;
typedef unsigned long long ull;

int pct(int x) { return __builtin_popcount(x); }

using namespace std;

/*
Start with ans as the smallest possible value and then
every time you find a more optimal pairing in solve, add the
improvement to ans.

In solve, we're keeping a set (ordered) of positions and removing
positions when they are taken by the current most valuable camel.

*/

/*
Finds the optimal ordering of the elements in
the vector so that their value is maximized
*/
// piar: {difference, pos}
ll solve(vector<pair<ll, int>> & in){
    int n = in.size();
    // sort and reverse the input vector
    sort(in.rbegin(), in.rend());

    // create a set to contain camels
    set<int> is;
    // insert all the positions from 1 to n (the length of the input)
    for (int i = 1; i <= n; i++){
        is.insert(i);
    }

    ll ans = 0;
    // loop through the values in in (biggest values first)
    for (auto it : in){
        // set itr to the first number greater than k for
        // each camel in is
        auto itr = is.upper_bound(it.ss);
        // if the first element in the set is greater
        // then the position's already been filled and we can't
        // use the optimal value for that camel
        if (itr == is.begin()) continue;
        // else erase it from the set
        is.erase(prev(itr));
        // and add it to ans
        ans += it.ff;

    }
    return ans;

}

int main()
{
    //ifstream fin("frac1.in");
	//ofstream fout("frac1.out");
	int t;
	cin >> t;
	while (t--){
        int n;
        cin >> n;
        ll ans = 0;

        vector<pair<ll, int>> lc;
        vector<pair<ll, int>> rc;

        for (int i = 0; i < n; i++){
            int k;
            ll l, r;
            cin >> k >> l >> r;

            // more valuable to be on left side
            if (l > r){
                // increment ans by the lowest value it could take on
                ans += r;
                // save it to the left values vector
                lc.push_back({l-r, k});
            }
            else {
                ans += l;
                rc.push_back({r-l, n-k});
            }
        }
        // the lowest possible value + the optimal gain on left side +
        // gain on right side
        cout << ans + solve(lc) + solve(rc) << endl;
	}
	return 0;
}


Measured memory_bytes: 11100
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N, T = mapint()
AB = [list(mapint()) for _ in range(N)]
AB.sort()
maxtime = AB[-1][0]
Bs = [b for a, b in AB]
dp = [0]*(T)

ans = 0
for n in range(N-1):
    a, b = AB[n]
    newdp = [0]*(T)
    for i in range(T):
        if a<=i and i-a<T:
            newdp[i] = max(dp[i], dp[i-a]+b)
    dp = newdp
    ans = max(ans, max(dp)+max(Bs[n+1:]))

print(ans)

Measured memory_bytes: 80180
from collections import deque


def bfs(si, sj, gi, gj):
    visited = set()
    q = deque([(si, sj, {(si, sj)})])
    while q:
        i, j, path = q.popleft()
        for di, dj in (1, 0), (-1, 0), (0, 1), (0, -1):
            ni, nj = i + di, j + dj
            if 0 <= ni < H and 0 <= nj < W and field[ni][nj] == '.' and (ni, nj) not in visited:
                if (ni, nj) == (gi, gj):
                    return path | {(gi, gj)}
                visited.add((ni, nj))
                q.append((ni, nj, path | {(ni, nj)}))
    return set()


H, W = map(int, input().split())
field = [input() for _ in range(H)]
path = bfs(0, 0, H - 1, W - 1)
if path:
    print(sum(field[i][j] == '.' and (i, j) not in path for i in range(H) for j in range(W)))
else:
    print(-1)


Measured memory_bytes: 3820
N, M = map(int, input().split())
ans = ['-1'] * N

if N == 1 and M == 0:
    print(0)
    exit()

for i in range(M):
    s, c = map(int, input().split())
    if ans[s-1] == str(c):
        continue
    elif ans[s-1] == '-1':
        ans[s-1] = str(c)
    else:
        print(-1)
        exit()

if N >= 2 and ans[0] == '0':
    print(-1)
    exit()
elif ans[0] == '-1':
    ans[0] = '1'

ans = ''.join(ans).replace('-1', '0')
print(ans)

Measured memory_bytes: 3188
#include <stdio.h>
#include <math.h>

int main()
{

    double a,b,h,m;
    scanf("%lf", &a);
    scanf("%lf", &b);
    scanf("%lf", &h);
    scanf("%lf", &m);
    double big = 0;
    double small = 0;//動きが。。

    big = 2.0 * M_PI * m / 60.0;
    small = 2.0 * M_PI * (h * 60 + m) / (60 * 12); //分で計算

    double ans = sqrt(a * a + b * b - 2 * a * b * cos(small - big));
   
    printf("%.13f", ans);
        
    printf("\n");
}

Measured memory_bytes: 2576
N = int(input())

F = [list(map(int, input().split())) for _ in range(N)]
P = [list(map(int, input().split())) for _ in range(N)]

ans = -float("inf")

for i in range(1, 2**10):
    score = 0
    jonson = [0 for _ in range(10)]

    #jonsonがお店を開く時間を決める
    for j in range(10):
        if ((i >> j)&1):
            jonson[j] = 1
    #他のお店とオープンがかぶっている時間を調べる
    for k in range(N):
        cnt = 0
        for l in range(10):
            if F[k][l] == jonson[l] == 1:
                cnt += 1
        score += P[k][cnt]

    ans = max(score, ans)

print(ans)

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

int main(){
  int n;
  cin>>n;
  vector<vector<int> > to(n),weight(n);
  int a,b,c;
  rep(i,n-1){
    cin>>a>>b>>c;
    to[a-1].push_back(b-1);
    to[b-1].push_back(a-1);
    weight[a-1].push_back(c);
    weight[b-1].push_back(c);
  }
  vector<int> ans(n,-1);
  queue<int> q;
  q.push(0);
  ans[0]=0;
  while(!q.empty()){
    int now = q.front();
    q.pop();
    rep(i,to[now].size()){
      if(ans[to[now][i]] != -1) continue;
      int next = to[now][i];
      int w = weight[now][i];
      ans[next] = (ans[now]+w)%2;
      q.push(next);
    }
  }
  rep(i,n) cout << ans[i] << endl;
}



Measured memory_bytes: 11904
#!/usr/bin/env python3
import sys


def solve(N: int):
    ans = []
    for i in range(1, N+1):
        if i % 3 == 0 or i % 5 == 0:
            continue
        ans.append(i)
    print(sum(ans))
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)

if __name__ == '__main__':
    main()


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

typedef long long LL;

int main(int argc, char** argv)
{
	while(getchar() != '\n');
	int rcnt = 0, gcnt = 0, bcnt = 0, n = 0;
	char c, s[4005];
	while((c = getchar()) != '\n')
	{
		switch(c)
		{
			case 'R': rcnt ++; break;
			case 'G': gcnt ++; break;
			default: bcnt ++;
		}
		s[n++] = c;
	}
	LL res = (LL)rcnt * (LL)gcnt * (LL)bcnt;
	for(int i=0; i<n-2; i++)
		for(int step=1; ; step++)
		{
			int j = i + step;
			int k = j + step;
			if(k >= n) break;
			if(s[i] != s[j] && s[j] != s[k] && s[i] != s[k])
				res --;
		}
	printf("%lld\n", res);
	return 0;
}

Measured memory_bytes: 1592
while (a = gets.chomp) != "-"
  a = a.chars
  n = gets.to_i
    
  for i in 1..n
    s = gets.to_i
    for j in 1..s
      a.push(a.shift)
    end
  end
    
  (0..a.size).each { |h|
    print a[h]
  }
  puts
end

Measured memory_bytes: 8644
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;

namespace atcorder2
{
    class Program
    {
        public static long Read()
        {
            return long.Parse(Console.ReadLine());
        }

        public static long[] Reads()
        {

            return Console.ReadLine().Split().Select(long.Parse).ToArray();
        }


       public static long GCM(long x,long y)
        {
            if (x < y) GCM(y, x);
            long a = x;
            long b = y;
            while (y > 0)
            {
                long z = x % y;
                x = y;
                y = z;
            }
            return a * b / x;
        }



        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            var n = Read();
            var a = Reads();
            var gcm = GCM(a[0], a[1]);
            for (int i = 2; i < n; i++)
            {
                gcm=GCM(gcm, a[i]);
            }

            Console.WriteLine(a.Sum()-n);

            Console.Out.Flush();
        }
    }
}




Measured memory_bytes: 13408
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(a) (long long)((a).size())

int main()
{
    ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
    
    ll n,k;
    cin>>n>>k;
    set<ll> s;
    ll a;
    while(k--)
    {
        cin>>a;
        s.insert(a);
    }
    while(1)
    {
        ll tmp = n;
        ll f = 0;
        while(tmp>0)
        {
            if(s.find(tmp%10)!=s.end()) {f=1;break;}
            tmp/=10;
        }
        if(f) n++;
        else {cout<<n;break;}
    }
}


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

 //bool dp[2][4000001];

signed main(){
   string a;
   cin >>a;
   int k[26]={};
   for(int i=0;i<a.size();i++){
       k[a[i]-'a']++;
   }
   int ans=2;
   for(int i=0;i<26;i++)ans+=k[i]*(a.size() -k[i]);
   cout << ans/2;

    return 0;
}

Measured memory_bytes: 640
import sys
input = sys.stdin.readline
N=int(input())
ki=[[] for f in range(N)]
for i in range(N-1):
 u,v,w = map(int,input().split())
 ki[u-1].append([v-1,w%2])
 ki[v-1].append([u-1,w%2])
stack = [[0,0]]
check = [0]*N #チェック済みリスト
ans=[2]*N
ans[0]=0
while stack != [] :
 a=stack.pop()
 if check[a[0]]==0:
  check[a[0]]=1
  for i in range(len(ki[a[0]])):
   if check[ki[a[0]][i][0]]==0:
    stack.append([ki[a[0]][i][0],(ki[a[0]][i][1]+ans[a[0]])%2])
    ans[ki[a[0]][i][0]]=(ki[a[0]][i][1]+ans[a[0]])%2
for i in ans:
 print(i)


Measured memory_bytes: 42696
#define _CRT_SECURE_NO_WARNINGS
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
int const inf = numeric_limits<int>::max();

// RMQ
template<class T>
struct SegmentTree {
    int n;
    vector<T> dat;
    SegmentTree(int n_ = 0) : n(n_){
        n = 1;
        while(n < n_) n <<= 1;
        dat.resize(n*2, inf);
    }
    T query(int v, int w, int l, int r){
        if(r <= l || w == 0) return inf;
        if(l + w == r) return dat[v];
        return min(query(v<<1, w/2, l, min(r, w/2)),
                   query(v<<1|1, w/2, max(0, l-w/2), r-w/2));
    }
    void update(int i, T x){
        i += n;
        dat[i] = x;
        for(; i!=1; i>>=1) dat[i>>1] = min(dat[i], dat[i^1]);
    }
    T query(int l, int r){
        return query(1,n,l,r);
    }
    size_t size() const {
        return n;
    }
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    int n, q;
    while(cin >> n >> q){
        SegmentTree<int> st(n);
        while(q--){
            char c;
            int x, y;
            cin >> c >> x >> y;
            if(c == '0'){
                st.update(x,y);
            } else {
                cout << st.query(x,y+1) << endl;
            }
        }
    }
}

Measured memory_bytes: 2052
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
const int maxn=0x7fffff;

int main(){
	string s;
	cin>>s;
	cout<<s[0]<<s.size()-2<<s[s.size()-1];
	return 0;
}


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

using namespace std;

int main() {
	int k;
	cin >> k;
	int N[] = {
		1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 
		15, 2, 2, 5, 4, 1, 4, 1, 51};
	
	cout << N[k-1] << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;

main() {
    int64_t r, d, x;
    cin >> r >> d >> x;

    for(auto _ : irange(0, 10)) {
        x = r * x - d;
        cout << x << endl;
    }
}

Measured memory_bytes: 256
function main(input) {
    input = input.trim().split(" ");
    var n = parseInt(input[0]);
    var k = parseInt(input[1]);
    var cnt = 0;
    while (true) {
        n /= k;
        cnt ++;
        if (n < 1) {
            break;
        } 
    }
    console.log(cnt);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
#include <iostream>

using namespace std;


int main(){
    
    int H, W;

    while(true){
        cin >> H >> W;
        if(H!=0 && W!=0){
            for(int i=0; i<H; i++){
                for(int j=0; j<W; j++){
                    cout << "#";
                }
                cout << endl;
            }
            cout << endl;
        }else{
            break;
        }
    }

    return 0;
}




Measured memory_bytes: 3104
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

long long combination(int n, int r)
{
    if(n < r)
        return 0;
    if(n-r < r)
        r = n-r;
    long long ret = 1;
    for(int i=0; i<r; i++){
        ret *= (n--);
        ret /= i+1;
    }
    return ret;
}

int main()
{
    int n, a, b;
    cin >> n >> a >> b;
    vector<long long> v(n);
    map<long long, int> cnt;
    for(int i=0; i<n; ++i){
        cin >> v[i];
        ++ cnt[v[i]];
    }

    sort(v.rbegin(), v.rend());
    double ans1 = accumulate(v.begin(), v.begin() + a, 0.0) / a;

    for(;;){
        int x = cnt.rbegin()->second;
        if(x >= a)
            break;
        a -= x;
        b = a;
        cnt.erase(--cnt.end());
    }

    int x = cnt.rbegin()->second;
    long long ans2 = 0;
    for(int i=a; i<=min(x,b); ++i)
        ans2 += combination(x, i);

    cout.setf(ios_base::fixed, ios_base::floatfield);
    cout << setprecision(10);
    cout << ans1 << endl << ans2 << endl;

    return 0;
}


Measured memory_bytes: 256
N=int(input())
A=sorted(list(map(int,input().split())))

import bisect
maxval=0
maxpair=None

def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

i=-1
bunshi=A[i]
target=A[i]/2
tarp=bisect.bisect_left(A,target)
diff=10**9+1
if tarp-1>=0:
  diff=abs(target-A[tarp-1])
if abs(target-A[tarp])<diff:
  print(bunshi,A[tarp])
else:
  print(bunshi,A[tarp-1])


Measured memory_bytes: 14436
#include <iostream>

using namespace std;

int main() {
	int n;
	while (cin >> n) {
		long long int counter = 0;
		for (int i = 0; i <= 1000; i++) {
			for (int j = 0; j <= 1000; j++) {
				int k = i+j;
				if (k > n) {
					break;
				} else {
					int l = n-k;
					if (l <= 1000) {
						counter += l+1;
					} else if (l <= 2000) {
						counter += 2001-l;
					}
				}
			}
			if (i > n) {
				break;
			}
		}
		cout << counter << endl;
	}
	return 0;
}

Measured memory_bytes: 1156
#include<bits/stdc++.h>
#define lint long long int 
using namespace std;

int main()
{
        lint x,a,b,c;
        cin>>a>>b>>c>>x;
        lint i,j,k;
        lint count=0;
        for(i=0;i<=a;i++)
        {
                for(j=0;j<=b;j++)
                {
                        for(k=0;k<=c;k++)
                        {
                                if(500*i+100*j+50*k==x)
                                count++;
                        }
                }
        }cout<<count<<endl;
        
        return 0;
}

Measured memory_bytes: 256
import scala.io.StdIn

object Main {
  def main(args: Array[String]){
    val N = StdIn.readInt()
    var res = 0
    for(i <- 0 to N - 1){
      val num = StdIn.readInt()
      if((2 to math.sqrt(num).toInt).forall(num % _ != 0)){
        res = res + 1
      }
    }
    println(res)
  }
}

Measured memory_bytes: 119540
#include <stdio.h>
int main()
{
	int a,b;
	scanf("%d %d",&a,&b);
	if(0>=a&&0<=b)
	{
		printf("Zero");
		return 0;
	}
	if(a>0)
	{
		printf("Positive");
		return 0;
	}
	if(a<0)
	{
		if((b-a)%2==1)
		{
			printf("Positive");
		}
		else
		{
			printf("Negative");
		}
		return 0;
	}
	return 0;
}

Measured memory_bytes: 128
object Main{
  def main(args: Array[String]){
    val input=io.Source.stdin.getLines().mkString("\n")
    println(solve(input).trim())
  }

  def solve(input:String):String={
    val n = input.split("\n")(0).toInt
    val as = input.split("\n")(1).split(" ").map(_.toInt)
    as.zipWithIndex.sortWith(_._1< _._1).map(_._2+1).mkString(" ")
  }
}


Measured memory_bytes: 67404
from sys import stdin
import sys
#import numpy as np
import collections
from functools import cmp_to_key
import heapq

##  input functions for me
def rsa(sep = ''):
    if sep == '' :
        return input().split() 
    else: return input().split(sep)
def rip(sep = ''):
    if sep == '' :
        return map(int, input().split()) 
    else: return map(int, input().split(sep))
def ria(sep = ''): 
    return list(rip(sep))
def ri(): return int(input())
def rd(): return float(input())
def rs(): return input()
##
def main():
    N = ri()
    S = [""] * N
    for i in range(N): S[i] = rs()

    bw = [-1] * N
    q = collections.deque()
    bw[0] = 0
    q.append(0)
    while(len(q) > 0):
        now = q.popleft()
        for nxt in range(N):
            if S[now][nxt] == '0': continue
            if bw[nxt] == -1:
                bw[nxt] = bw[now] ^ 1
                q.append(nxt)
            elif bw[nxt] == bw[now]:
                print(-1)
                sys.exit(0)
    
    inf = int(1e9)
    wf = [[inf] * N for i in range(N)]
    for i in range(N):
        for j in range(N):
            wf[i][j] = 1 if S[i][j] == '1' else inf
            if i == j: wf[i][j] = 0
    for k in range(N):
        for i in range(N):
            for j in range(N):
                wf[i][j] = min(wf[i][j], wf[i][k] + wf[k][j])
    
    ma = 0
    for i in range(N):
        for j in range(N):
            ma = max(ma, wf[i][j])

    print(ma + 1)

if __name__ == "__main__":
    main()


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

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long int

int main(){
ll n,m;
cin>>n>>m;
ll ans=0;
if(2*n<=m){
ans+=n;
m-=2*n;
ans+=m/4;
}else
{
  ans+=m/2;
}


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


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

const int mod  = 1e9 + 7;
long long modpow(long long a, long long n) {
    long long r = 1;
    while(n) {
        r = r * ( (n%2) ? a : 1) % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return r;
}

long long modcomb(int n, int k) {
    if ( n < 0 || k < 0 || k > n) return 0;
    k = min(k, n - k); //nCk = nC(n-k)
    long long p = 1, q = 1;
    while ( k > 0 ) {
        p = p * n-- % mod; // p = n*(n-1)*(n-2)...(n-k+1)
        q = q * k-- % mod; // q = k*(k-1)*(k-2)...1
    }
    // 1/q = q^(p-2) (mod p)
    return p * modpow(q, mod - 2) % mod;
}

int main(){
	int N, K;
	cin >> N >> K;
	for (int i = 1; i <= K; ++i){
		cout << modcomb (N-K+1, i) * modcomb(K-1, i-1) % mod << endl;
	}
}


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

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

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL<<60;
ll gcd(ll a,ll b){
    if(b == 0) return a;
    else return gcd(b,a%b);
}


int main() {
    int k;
    string s;
    cin >> k;
    cin >> s;
    if(s.size() <= k){
        cout << s << endl;
        return 0;
    }
    for (int i = 0; i < k; ++i) {
        cout << s[i];
    }
    cout << "..." << endl;
    return 0;
}

Measured memory_bytes: 3624
#include<iostream>
#include<vector>
using namespace std;
int main() {
	while (1) {
		int n;
		cin >> n;
		if (n == 0)
			break;
		
		vector<char> t(n);
		vector<int> win(n), lose(n), drow(n);
		vector<int> num(n);
		for (int i = 0; i < n; i++)
			num.at(i) = i;

		int score;
		for (int i = 0; i < n; i++) {
			cin >> t.at(i);
			for (int j = 0; j < n - 1; j++) {
				cin >> score;
				switch (score) {
				case(0):win.at(i)++;
				case(1):lose.at(i)++;
				case(2):drow.at(i)++;
				}
			}
		}

		for (int i = 0; i < n-1; i++) {
			for (int j = i+1; j < n; j++) {
				if (win.at(num.at(i)) < win.at(num.at(j))) {
					swap(num.at(i), num.at(j));
				}
			}
		}
		for (int i = 0; i < n - 1; i++) {
			for (int j = i + 1; j < n; j++) {
				if (win.at(num.at(i)) == win.at(num.at(j)) && lose.at(num.at(i)) > lose.at(num.at(j))) {
					swap(num.at(i), num.at(j));
				}
			}
		}
		for (int i = 0; i < n - 1; i++) {
			for (int j = i + 1; j < n; j++) {
				if (win.at(num.at(i)) == win.at(num.at(j)) && lose.at(num.at(i)) == lose.at(num.at(j)) && num.at(i) > num.at(j)) {
					swap(num.at(i), num.at(j));
				}
			}
		}

		for (int i = 0; i < n; i++)
			cout << t.at(num.at(i)) << endl;
	}
}


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

using namespace std;

int main(){
    int N,max=0,a_sum=0;
    int A[100],B[100];

    cin>>N;
        for(int j=0;j<N;j++){
            cin >> A[j];
        }
        for(int j=0;j<N;j++){
            cin >> B[j];
        }
        for(int j=0;j<N;j++){
            a_sum += A[j];
            int tmp = a_sum;
            for(int i=j;i<N;i++){
                tmp += B[i];
            }
            if(max<tmp) max = tmp;
        }
    cout << max;
}

Measured memory_bytes: 256
// Template
#include <bits/stdc++.h>
#define rep_override(x, y, z, name, ...) name
#define rep2(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep3(i, l, r) for (int i = (int)(l); i < (int)(r); ++i)
#define rep(...) rep_override(__VA_ARGS__, rep3, rep2)(__VA_ARGS__)
#define per(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
constexpr int inf = 1001001001;
constexpr ll INF = 3003003003003003003;
template <typename T> inline bool chmin(T& x, const T& y) {if (x > y) {x = y; return 1;} return 0;}
template <typename T> inline bool chmax(T& x, const T& y) {if (x < y) {x = y; return 1;} return 0;}
struct IOSET {IOSET() {cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(15);}} ioset;

// Main
ll a[100000];
const int A = 1000000000, B = 1000000000;
int q;
vector<char> type;
vector<int> I, J, K;

// a[i] = a[j] + a[k]
void add(int i, int j, int k) {
    a[k] = a[i] + a[j];
    ++q;
    type.push_back('+');
    I.push_back(i);
    J.push_back(j);
    K.push_back(k);
}

// a[k] = a[i] < a[j]
void comp(int i, int j, int k) {
    a[k] = a[i] < a[j];
    ++q;
    type.push_back('<');
    I.push_back(i);
    J.push_back(j);
    K.push_back(k);
}

// a[k] = a[i] or a[j]
void OR(int i, int j, int k) {
    add(99998, 99999, k);
    add(k, i, k);
    add(k, j, k);
    comp(99999, k, k);
}

// a[j] = not a[i]
void NOT(int i, int j) {
    comp(99998, i, 99999);
    comp(99999, 100, j);
    add(99997, 99998, 99999);
}

// a[i] = a[j] and a[k]
void AND(int i, int j, int k) {
    NOT(i, 99990); NOT(j, 99991);
    OR(99990, 99991, k); NOT(k, k);
    add(99900, 99901, 99990); add(99900, 99901, 99991);
}

void debug(int l, int r) {
    cout << "[";
    rep(i, l, r) cout << a[i] << ", ";
    cout << "...]\n";
}

void print() {
    cout << q << "\n";
    rep(i, q) cout << type[i] << " " << I[i] << " " << J[i] << " " << K[i] << "\n";
}

int main() {
    a[0] = A; a[1] = B;
    
    OR(0, 1, 1000);
    
    add(100, 1000, 100);
    rep(i, 60) add(100 + i, 100 + i, 101 + i);
    
    add(0, 1000, 197);
    for (int i = 30; i >= 0; --i) {
        add(199, 100 + i, 198);
        comp(198, 197, i + 200);
        rep(j, i) add(i + 200, i + 200, i + 200);
        add(199, i + 200, 199);
        add(99999, 99999, 198);
    }
    add(1, 1000, 297);
    for (int i = 30; i >= 0; --i) {
        add(299, 100 + i, 298);
        comp(298, 297, i + 300);
        rep(j, i) add(i + 300, i + 300, i + 300);
        add(299, i + 300, 299);
        add(99999, 99999, 298);
    }
    
    rep(i, 31) rep(j, 31) {
        AND(i + 200, j + 300, 400);
        rep(k, i + j) add(400, 400, 400);
        add(2, 400, 2);
        add(99999, 99999, 400);
    }
    
    print();
}


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

using namespace std;

const int MAXN = 305;
const int MOD = 998244353;

int n,K,N,ans;
int a[MAXN];
int f[MAXN][MAXN][MAXN];

char s[MAXN];

int main()
{
	scanf("%s%d",s + 1,&K);
	n = strlen(s + 1);
	int cnt = 0;
	for (int i = 1;i <= n;i++)
	{
		if (s[i] == '1')
			cnt++;
		else
		{
			a[++N] = cnt;
			cnt = 0;
		}
	}
	a[++N] = cnt;
	int sum = 0;
	for (int i = 2;i <= N;i++)
		sum += a[i];
	K = min(K,sum);
	f[0][0][0] = 1;
	for (int i = 0;i < N;i++)
		for (int j = 0;j <= K;j++)
			for (int k = 0;k <= j;k++)
				if (f[i][j][k])
				{
					(f[i + 1][j][k] += f[i][j][k]) %= MOD;
					for (int l = 1;l <= a[i + 1] && k + l <= j;l++)
						(f[i + 1][j][k + l] += f[i][j][k]) %= MOD;
					for (int l = 1;j + l <= K;l++)
						(f[i + 1][j + l][k] += f[i][j][k]) %= MOD;
				}
	for (int i = 0;i <= K;i++)
		(ans += f[N][i][i]) %= MOD;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 30812
#include <stdio.h>

int main()
{
	int i, N, A, x[51];
	scanf("%d %d", &N, &A);
	for (i = 1; i <= N; i++) scanf("%d", &(x[i]));
	
	int j, k, sum[51] = {};
	long long dp[51][51][2501] = {};
	for (i = 1; i <= N; i++) sum[i] = sum[i-1] + x[i];
	for (i = 1, dp[0][0][0] = 1; i <= N; i++) {
		for (j = 0; j < i; j++) {
			for (k = 0; k <= sum[i-1]; k++) {
				dp[i][j][k] += dp[i-1][j][k];
				dp[i][j+1][k+x[i]] += dp[i-1][j][k];
			}
		}
	}
	
	long long ans = 0;
	for (j = 1; j <= N; j++) ans += dp[N][j][A*j];
	printf("%lld\n", ans);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 51072
#include <iostream>

using namespace std;
using ll = long long;

int main() {
	int X;
	cin >> X;

	ll ans = X;
	if (ans == 2) {
		cout << ans << endl;
		return 0;
	}

	if (X % 2 == 0) {
		ans += 1;
	}

	while (true) {
		for (int i = 3; ; i += 2) {
			if (i >= ans) {
				cout << ans << endl;
				return 0;
			}
			if (ans % i == 0) {
				break;
			}
		}
		ans += 2;
	}
	return 0;
}


Measured memory_bytes: 3640
//In the name of Allah
#include <bits/stdc++.h>
using namespace std;
#define MAX 10011
#define mod 1000000007
#define inf 1000000000000000
#define ll long long
#define endl '\n'
string s;
int m;
ll dp[MAX][111][2];

int main() {
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>s;
	cin>>m;
	reverse(s.begin(), s.end());
	for(int i = s.size(); i < MAX; i++)s += '0';
	reverse(s.begin(), s.end());

	for(int j = 0 ; j < (int)(s[0] - '0') ; j++) dp[0][j%m][0]++;
	dp[0][(s[0] - '0')%m][1]++; 	

	ll temp;	
	for(int i = 1; i < MAX ; i++){
		for(int k = 0; k < m ;k++){
			if(dp[i-1][k][0]){
				for(int j = 0 ; j < 10 ; j++){
					temp = (j+k)%m;
					dp[i][temp][0] = (dp[i][temp][0] + dp[i-1][k][0])%mod;

				}
			}
			if(dp[i-1][k][1]){
				for(int j = 0; j < (int)(s[i] -'0') ;j++){
					temp = (j + k )%m;
					dp[i][temp][0] = (dp[i][temp][0] + dp[i-1][k][1])%mod;
				}
				temp = (k + (s[i] - '0'))%m; 
				dp[i][temp][1] = (dp[i][temp][1] + dp[i-1][k][1])%mod;
			}
		}
	}
	cout<<(dp[MAX-1][0][0] + dp[MAX - 1][0][1] + mod - 1)%mod;
	return 0; 
} 

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

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> VI;
typedef vector<VI> VVI;

int dice[6][4] = {{1, 2, 4, 3}, {0, 3, 5, 2}, {0, 1, 5, 4}, {0, 4, 5, 1}, {0, 2, 5, 3}, {1, 3, 4, 2}};
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

void solve(int x, int y, VVI &v, VVI &w, int top, int face)
{
    //cout<<x<<" "<<y<<" "<<top<<" "<<face<<endl;
    vector<P> vec;
    int var = -1;
    for (int i = 0; i < 4; i++)
        if (dice[top][i] == face)
            var = i;
    for (int i = 0; i < 4; i++)
    {
        int nx = x + dx[i], ny = y + dy[i];
        if (v[nx][ny] < v[x][y] && dice[top][(i + var) % 4] >= 3)
        {
            vec.push_back(P(dice[top][(i + var) % 4], i * 11 + var));
        }
    }
    if (vec.size() == 0)
    {
        v[x][y]++;
        w[x][y] = top;
        return;
    }
    sort(vec.rbegin(), vec.rend());
    int i = vec[0].second / 11, va = vec[0].second % 11;
    if (i == 0)
        solve(x + dx[i], y + dy[i], v, w, dice[top][(2 + va) % 4], top);
    if (i == 1)
        solve(x + dx[i], y + dy[i], v, w, dice[top][(3 + va) % 4], dice[top][(0 + va) % 4]);
    if (i == 2)
        solve(x + dx[i], y + dy[i], v, w, dice[top][(0 + va) % 4], 5 - top);
    if (i == 3)
        solve(x + dx[i], y + dy[i], v, w, dice[top][(1 + va) % 4], dice[top][(0 + va) % 4]);
    return;
}

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

    int n;
    while (true)
    {
        cin >> n;
        if (n == 0)
            break;
        std::vector<int> res(6, 0);
        VVI top(200, vector<int>(200, -1)), num(200, vector<int>(200, 0));
        for (int i = 0; i < n; i++)
        {
            int t, f;
            cin >> t >> f;
            t--;
            f--;
            solve(100, 100, num, top, t, f);
        }
        for (int i = 0; i < 200; i++)
            for (int j = 0; j < 200; j++)
                if (top[i][j] != -1)
                    res[top[i][j]]++;
        for (int i = 0; i < 6; i++)
        {
            cout << res[i];
            if (i == 5)
                cout << endl;
            else
                cout << " ";
        }
    }
}


Measured memory_bytes: 3280
#include        "algorithm"
#include        "iostream"
#include        "numeric"
#include        "iomanip"
#include        "cstring"
#include        "math.h"
#include        "bitset"
#include        "string"
#include        "vector"
#include        "ctime"
#include        "queue"
#include        "stack"
#include        "map"
#include        "set"

#include        "ext/pb_ds/assoc_container.hpp" // Common file
#include        "ext/pb_ds/tree_policy.hpp" // Including tree_order_statistics_node_update
#include        "ext/pb_ds/detail/standard_policies.hpp"

using namespace std;
using namespace __gnu_pbds;


#define          f first
#define          lgn 25
#define          endl '\n'
#define          sc second
#define          N (int)2e5+5
#define          pb push_back
#define          mod 1000000007
#define          ld long double
#define          vi vector<int>
#define          eb emplace_back
#define          vpii vector<pii>
#define          mii map<int,int>
#define          int long long 
#define          pii pair<int,int>
#define          pq priority_queue
#define          BLOCK (int)sqrt(N)
#define          test(x) while(x--)
#define          all(x) begin(x),end(x)
#define          allr(x) rbegin(x),rend(x)
#define          fo(i,a,n) for(int i=a;i<n;i++)
#define          rfo(i,n,a) for(int i=n;i>=a;i--)
#define          FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define          time() cerr << "Time : " << (double)clock() / (double)CLOCKS_PER_SEC << "s\n"
#define          PI acos(-1.0)
#define 		 bug(...)       __f (#__VA_ARGS__, __VA_ARGS__)

typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update > 
OS ;

template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{
     const char* comma = strchr (names + 1, ',');
     cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}

inline void INP()
{
	#ifndef ONLINE_JUDGE
	    freopen("input.txt","r",stdin);   
	    freopen("output.txt","w",stdout);
	#endif 
}

const int inf = 0x3f3f3f3f;
const int INF = 0x3f3f3f3f3f3f3f3f;

int n,m,k,q,p;
string s;
vi adj[N];
int vis[N],par[N],a[N];

void go()
{
	cin >> n >> p >> s;
	mii mp;
	mp[0] = 1;
	int ans = 0;

	if( p == 2 or p == 5 )
	{
		fo(i,0,n)
		{
			int d = s[i] - '0';
			if( d%p == 0 ) ans += ( i + 1 );
		}
		cout << ans << endl;
		return;
	}

	int no = 0 , po = 1;

	rfo(i,n-1,0)
	{
		int d = s[i] - '0';
		no = (no + d*po )%p;
		mp[no]++;
		po = ( po*10 )%p;
	}

	for( auto j : mp )
	{
		ans += ( j.sc)*( j.sc -1 )/2;
	}
	cout << ans << endl;
}

int32_t main()
{
	//INP(); 
	FAST;     
	int t=1; 
	// cin>>t;
	test(t) go();
}

 

Measured memory_bytes: 6292
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int l;
	cin>>l;
	int s=l;
	int n=0;
	int a[61];
	int p=0;
	while(s)
    {
    	a[++n]=s%2;
    	if(a[n]==1) ++p;
    	s/=2;
	}
	cout<<n<<" "<<2*(n-1)+p-1<<endl;
	int now=1;
	int cnt=1;
	for(int i=n-1;i>=1;--i)
	{
		now++;
		cout<<now-1<<" "<<now<<" "<<0<<endl;
		cout<<now-1<<" "<<now<<" "<<cnt<<endl;
		cnt*=2;
		if(a[i]==1) cout<<1<<" "<<now<<" "<<cnt++<<endl;
	}
	return 0;
 } 

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

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

    if (500 * K >= X)
    {
        cout << "Yes" << endl;
    }
    else
    {
        {
            cout << "No" << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 256
# import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial, gcd
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10 ** 7)
enu = enumerate
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep="\n")

a, b = map(int, input().split())

val = (a+b+2-1)//2
print(val)


Measured memory_bytes: 65360
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <math.h>
#include <set>
#include <map>
#include <numeric>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define _printV(vec) for(int i = 0; i < SZ(vec); i++){cout << vec[i];if (i==SZ(vec)-1){cout<<endl;}else{cout << " ";}}
#define printV(vec) cout<<#vec<<":";_printV(vec)
#define _printA(arr,n) for(int i = 0; i < n; i++){cout << arr[i];if (i==n-1){cout<<endl;}else{cout << " ";}}
#define printA(arr) cout<<#arr<<":";_printA(arr,sizeof(arr)/sizeof(arr[0]))
#define LLINF = (1LL<<62)
#define puts(var) cout<<#var<<":"<<var<<" "
typedef long long ll;

struct mypair_t {
  int int1;
  int int2;
};

// int1のみ用いてソート
bool cmp(const mypair_t &left, const mypair_t &right){
  return left.int2 < right.int2;
}

int main()
{
  int N,M;
  cin >> N >> M;
  vector<mypair_t> A(M);
  REP(m,M){
    cin >> A[m].int1 >> A[m].int2;
  }

  sort(A.begin(),A.end(),cmp);

  int cut = A[0].int2;
  int count = 1;
  for(int i=1;i<M;i++){
    if (cut > A[i].int1){
      continue;
    }
    else{
      cut = A[i].int2;
      count++;
    }
  }
  // 
  // cout << "===" <<endl;
  // REP(m,M){
  //   cout << A[m].int1 << " " << A[m].int2 << endl;
  // }

  cout << count << endl;

  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using lint     = long long;
const lint inf = 1LL << 60;
const lint mod = 1000000007;

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

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    lint n, m;
    cin >> n >> m;
    vector<lint> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    lint ok    = 0;
    lint ng    = 200001;
    auto check = [&](lint mid) {
        lint cnt = 0;
        for (int i = 0; i < n; ++i) {
            cnt += a.end() - lower_bound(a.begin(), a.end(), mid - a[i]);
        }
        return cnt >= m;
    };
    while (abs(ok - ng) != 1) {
        lint mid               = (ok + ng) / 2;
        (check(mid) ? ok : ng) = mid;
    }
    vector<lint> cum(n, 0);
    cum[n - 1] = a[n - 1];
    for (int i = n - 2; i >= 0; --i) {
        cum[i] = cum[i + 1] + a[i];
    }
    lint cnt = 0;
    lint ret = 0;
    for (int i = 0; i < n; ++i) {
        lint c = a.end() - lower_bound(a.begin(), a.end(), ok - a[i]);
        if (c != 0) {
            cnt += c;
            ret += a[i] * c + cum[n - c];
        }
    }
    ret -= (cnt - m) * ok;
    cout << ret << "\n";
    return 0;
}

Measured memory_bytes: 1920
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cmath>
#include<cstring>
#include<ctime>
#include<cstdlib>
using namespace std;
typedef long long ll;
#define N 1000000

int main(){
    ios::sync_with_stdio(false);
    int l,r,d,i,s=0;
    cin>>l>>r>>d;
    for(i=l;i<=r;i++){
        if(i%d==0)
            s++;
    }
    cout<<s;
    return 0;
}


Measured memory_bytes: 3632
# 初期入力
from bisect import bisect_right
import sys
input = sys.stdin.readline  #文字列では使わない
N,T = (int(i) for i in input().split())
cost_time =[]
time =[]
for i in range(N):
    c,t = (int(j) for j in input().split())
    cost_time.append((c,t))
    time.append(t)


time.sort()
ind =bisect_right(time,T)
if ind ==0:
    ans ="TLE"
else:
    cost_time.sort(key =lambda x:x[1])
    ans1 =[]
    for i in range(ind):
        ans1.append(cost_time[i][0])
    ans =min(ans1)    
print(ans)

Measured memory_bytes: 9096
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {if(b>a) return b; else return a;}
int min(int a, int b) {if(b<a) return b; else return a;}


signed main() {
    int H, W, D;
    vi px(90001, 0), py(90001, 0);
    cin >> H >> W >> D;
    rep(i, H) rep(j, W) {
        int a;
        cin >> a;
        py[a] = i;
        px[a] = j;
    }

    vi d(90001, 0);
    //|R-L|がDの倍数であることが保証されているため、D以下の各マスからDずつ
    //増加させていったときの累積和をとっておく。
    FOR(i, D+1, H*W+1) {
        d[i] = d[i-D] + abs(px[i]-px[i-D]) + abs(py[i]-py[i-D]);
    }

    int Q;
    cin >> Q;
    vi L(Q), R(Q);
    rep(i, Q) cin >> L[i] >> R[i];
    rep(i, Q) {
        cout << d[R[i]]-d[L[i]] << endl;
    }

    return 0;
}

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

#include <iostream>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> d(k);
  vector<int> p(n, 0);
  for (int i = 0; i < k; ++i) {
    cin >> d[i];
    for (int j = 0; j < d[i]; ++j) {
      int a;
      cin >> a;
      p[a - 1]++;
    }
  }

  int cnt = 0;
  for (auto pi : p) {
    if (pi == 0) {
      cnt++;
    }
  }
  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 3600
#define _CRT_SECURE_NO_WARNINGS
#include<cstdio>
#include<cmath>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<utility>
#include<iomanip>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<map>
#include<list>
#include<set>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define repp(i,k,n) for(int i=k;i<(int)n;i++)
#define F first
#define S second
using namespace std;
const int dx[4] = { 0, 1, 0, -1 }, dy[4] = { 1, 0, -1, 0 };
const int dX[8] = { 0, 1, 1, 1, 0, -1, -1, -1 }, dY[8] = { 1, 1, 0, -1, -1, -1, 0, 1 };
struct XY
{
	int x;
	int y;
};
int in()
{
	int x;
	cin >> x;
	return x;
}

/*
(char)'1' - (int)48 = (int)1;
　1111181
*/
////////////////////////////////////////////////////



int main()
{
	int e;
	while (cin>>e&&e)
	{
		int ans = e;
		for (int z = 0; z*z*z <= e; z++)
		{
			int y = (int)sqrt(e - z*z*z);
			ans = min(ans, y + z + (e - z*z*z - y*y));
		}

		cout << ans << endl;


	}
}

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

using namespace std;

class Heap{
private:
 vector<long> node;
public:
 Heap(){ node.push_back(0);};

 void print(){
  long n = node.size();
  for(long i = 1; i < n; ++i)
   cout << " " << node[i];
  cout << endl;
 };
 
 void insert(long num){
  node.push_back(num);
 };

 long left(long i){ return (2 * i); };
 long right(long i){ return (2 * i + 1); };
 long parent(long i){ return (i / 2); };

 void maxHeapify(long i){
  long l = left(i);
  long r = right(i);
  long nodeSize = node.size() - 1;
  long largest = 0;

  if(l <= nodeSize && node[l] > node[i]){
   largest = l;
  }else{
   largest = i;
  }

  if(r <= nodeSize && node[r] > node[largest])
   largest = r;
  
  if(largest != i){
   long buf = node[i];
   node[i] = node[largest];
   node[largest] = buf;
   maxHeapify(largest);
  }
  
 };

 void buildMaxHeap(){
  long nodeSize = node.size() - 1;
  for(long i = nodeSize; i > 0; --i)
   maxHeapify(i);
 };
protected:
};

int main(){
 Heap heap;
 long n = 0; cin >> n;

 for(long i = 0; i < n; ++i){
  long num = 0; cin >> num;
  heap.insert(num);
 }

 heap.buildMaxHeap();
 heap.print();

 return 0;
}

Measured memory_bytes: 7252
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int S = sc.nextInt();
		for (int j = 0; j < S; ++j) {
			long[] input = new long[9];
			for (int i = 0; i < 9; ++i) {
				// 10進数に変換しておく
				input[i] = Long.parseLong(sc.next(), 16);
			}

			long key = 0;
			for (int i = 0; i < 32; ++i) {
				long sum = 0;
				for (int q = 0; q < 8; ++q) {
					sum += input[q] ^ key;
				}

				if ((sum & (1L << (i + 1) - 1)) != ((input[8] ^ key) & (1L << (i + 1) - 1))) {
					// keyの後ろからi桁目を0として計算した時に、sumとinput[8]の下i桁が等しくならなかった場合、
					// keyのi桁目を1にする
					key |= (1L << i);
				}
			}
			System.out.println(Long.toString(key, 16).toLowerCase());
		}

		sc.close();
	}
}

Measured memory_bytes: 22368
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  int n,a,s1;
  cin >> n >> a ;
  s1 = n % 500;
  if(s1 <= a)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;   
 
}

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

typedef long lint;
typedef long long llint;
typedef pair<int, int> pint;
typedef pair<long long, long long> pllint;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const llint INF = 1<<21;
// static const llint MOD = 1e9 + 7;

bool compPair(const pint& arg1, const pint& arg2) { return arg1.first > arg2.first; }
template<class T> void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b) { if (a > b) { a = b; } }

int main(void) {
    int n;
    cin >> n;

    vector<int> a(n);
    for(int in=0;in<n;in++) {
        cin >> a.at(in);
    }

    sort(a.begin(), a.end());

    cout << a.at(n-1) - a.at(0) << endl;
    return 0;
}


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

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

int main() {
	int r;
	cin >> r;

	cout << 3*r*r << endl;





    return 0;
}



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

def f(a, b):
    if b % a == 0:
        return b // a * 2 * a - a
    return 2 * (b // a) * a + f(b % a, a)

def main():
    N, X = map(int, input().split())
    print(N + f(X, N-X))

if __name__ == '__main__':
    main()

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,M;
vector<pair<int,int>> add[101010];
vector<ll> del[101010];
ll dp[101010];
multiset<ll> D;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>M;
	FOR(i,M) {
		cin>>x>>y>>r;
		add[x].push_back({y,r});
	}
	D.insert(0);
	del[1].push_back(0);
	for(i=1;i<=N;i++) {
		if(D.empty()) return _P("-1\n");
		dp[i]=*D.begin();
		FORR(a,del[i]) D.erase(D.find(a));
		FORR(a,add[i]) {
			D.insert(dp[i]+a.second);
			del[a.first].push_back(dp[i]+a.second);
		}
	}
	
	cout<<dp[N]<<endl;
	
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 11904
#include <stdio.h>

int main(void){
	long L;
	while( scanf(" %ld", &L) * L != 0 ){
		int i, ans=0, flag=0;
		long m, n, now=0;
		
		for(i=0; i<12; i++){
			scanf(" %ld %ld", &m, &n);
			now+=m-n;
			if(flag==0 && now>=L) {
				ans = i+1;
				flag=1;
			}
		}
		
		if(ans==0) printf("NA\n");
		else printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 612
#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

#define EPS 1e-10
#define INF 1000000
#define mp make_pair
#define pb push_back

typedef vector<int> vi;
typedef vector<vi> vii;
typedef pair<int,int> pii;
typedef long long ll;

int main() {
	int n;
	cin >> n;
	vi data(n), costs(201, 0);
	for (int i = 0; i < n; i++) {
		cin >> data[i];
	}

	for (int i = 0; i < n; i++) {
		int x = data[i];
		for (int y = -100; y <= 100; y++) {
			int diff = (x - y) * (x - y);
			costs[y+100] += diff;
		}
	}

	int ans = INF;
	for (int i = 0; i < costs.size(); i++) {
		ans = min(ans, costs[i]);
	}
	cout << ans << endl;
}


Measured memory_bytes: 256