akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define i64 long long
#define input freopen("input.txt", "r", stdin)
#define output freopen("output.txt", "w", stdout)
#define fast_io ios_base::sync_with_stdio(0);cin.tie(0);
#define mp make_pair
#define pb push_back

int main()
{
    fast_io

	string a,b;
	cin >>a>>b;
	string c = a+b;
	int n=0;
	for(int i=0;i<c.size();i++){
        n=n*10+c[i]-48;
	}
	//cout <<n<<endl;
    int sq = sqrt(n);
    if((sq*sq)==n){
        cout <<"Yes"<<endl;
    }
    else {
        cout <<"No"<<endl;
    }
	return 0;
}




Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
#define MAXN 100000
using namespace std;

int n;
struct node
{
    int time,x,y;
}a[MAXN+5];

int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%d%d%d",&a[i].time,&a[i].x,&a[i].y);
    int nx=0,ny=0,nt=0;
    for(int i=1;i<=n;i++)
    {
        int t=abs(a[i].x-nx)+abs(a[i].y-ny);
        if(nt+t>a[i].time)
        {
            printf("No\n");
            return 0;
        }
        else if(nt+t<a[i].time)
        {
            int st=a[i].time-nt-t;
            if(st%2)
            {
                printf("No\n");
                return 0;
            }
        }
        nx=a[i].x,ny=a[i].y,nt=a[i].time;
    }
    printf("Yes\n");
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
#include <iostream>
#include <numeric>
#include <string>
#include <list>
#include <limits>
#include <type_traits>
#include <vector>

using namespace std;

int main(void) {

    int n ,sum = 0;
    cin >> n;


    vector<int> vc(n,0);

    for (int i = 0; i < n; i++ ) {
        cin >> vc[i];
    }

    for (int i = 0; i < n; i++) {
        for (int j = i+1; j < n; j++) {
            sum += vc[i] * vc[j];
        }
    }

    cout << sum;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <functional>
#include <cstring>
#include <string>
#include <map>
#include <set>
#include <unordered_map>
#include <iostream>
#include <sstream>
#include <complex>
#include <cassert>
#include <bitset>

#define enp     puts("**chkchkchkchkchk**")
#define A       first
#define B       second
#define MP      make_pair

using namespace std;

typedef long long ll;
typedef unsigned int uint;

const int INF = 0x60000000;
const int MINF = -1000000000;
const int mod = 1000000007;
const int cons = 100001;
const double pi = 3.141592653589793;
const int sqrtMax = 317;
const int blocks = cons / 3;

ll dp[100001];
ll pos[100001];
int n;
ll e, t;

ll tree[400002];
int lim;

void upd(int pos, ll vl)
{
	pos += lim;
	tree[pos] = vl;

	while (pos > 1)
	{
		pos >>= 1;
		tree[pos] = min(tree[2 * pos], tree[2 * pos + 1]);
	}
}

ll query(int L, int R)
{
	if (L > R)return 1e18;

	L += lim;
	R += lim;
	ll ret = 1e18;

	while (L <= R)
	{
		ret = min(ret, min(tree[L++], tree[R--]));
		L >>= 1;
		R >>= 1;
	}

	return ret;
}

int main() 
{
	scanf("%d%lld%lld", &n, &e, &t);

	memset(tree, 0x3f, sizeof(tree));
	for (lim = 1; lim < n; lim <<= 1);

	for (int i = 1; i <= n; i++)scanf("%lld", &pos[i]);

	upd(0, -2 * pos[1]);

	for (int i = 1; i <= n; i++)
	{
		ll res = 1e18;

		int l = -1;
		int r = i;

		while (l + 1 < r)
		{
			int mid = l + r >> 1;

			if (2 * (pos[i] - pos[mid + 1]) < t)r = mid;
			else l = mid;
		}

		if(r < i)res = min(res, dp[r] - pos[r] + pos[i] + t);
		ll tmp = query(0, l);
		res = min(res, tmp + 3 * pos[i]);
		dp[i] = res;

		if (i == n)break;
		upd(i, dp[i] - pos[i] - 2 * pos[i + 1]);
	}

	printf("%lld\n", e - pos[n] + dp[n]);

	return 0;
}

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

int main() {
	int n, d; cin >> n >> d;
	two_sat ts(n);
	vector<vector<int>> flags(n, vector<int>(2));
	for (int i = 0; i < n; ++i) {
		cin >> flags[i][0] >> flags[i][1];
	}
	for (int i = 0; i < n; ++i) {
		for (int j = i+1; j < n; ++j) {
			for (int k = 0; k < 4; ++k) {
				int f = k/2, g = k%2;
				if (abs(flags[i][f] - flags[j][g]) < d) {
					ts.add_clause(i, f, j, g);
				}
			}
		}
	}
	if (!ts.satisfiable()) {
		cout << "No\n";
	} else {
		cout << "Yes\n";
		vector<bool> ans = ts.answer();
		for (int i = 0; i < n; ++i) cout << flags[i][1^ans[i]] << "\n";
	}
	return 0;
}

Measured memory_bytes: 3728
from collections import deque
import sys
input = sys.stdin.readline

def solve():
  n,q = (int(i) for i in input().split())
  graph = [[] for _ in range(n)]

  for i in range(n-1):
    a,b = (int(i) for i in input().split())
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)
  ans = [0]*n
  
  for i in range(q):
    p,x = (int(i) for i in input().split())
    ans[p-1] += x

  query = deque([(0,-1)])
  while query:
    nowplace,parent = query.popleft()
    nowvalue = ans[nowplace]   
    for node in graph[nowplace]:
      if node == parent:
        continue
      else:
        ans[node] += nowvalue
        query.append([node,nowplace])
      
  print(*ans)
  
solve()

Measured memory_bytes: 65324
#include<stdio.h>

int main()

{
    int n,ara[105],fail,a;
    scanf("%d",&n);
    fail=0;
    for(a=0;a<n;a++){
        scanf("%d",&ara[a]);
        if(ara[a]%2==0){
            if(ara[a]%3&&ara[a]%5){
                fail=1;
            }
        }
    }
    if(fail){
        printf("DENIED\n");
    }
    else{
        printf("APPROVED\n");
    }
    return 0;
}

Measured memory_bytes: 128
# -*- coding: utf-8 -*-

import sys

def main():
    input = sys.stdin.readline
    n = input()
    l = list(map(int, input().split()))
    max_l = max(l)
    l.remove(max_l)
    sum_l = sum(l)
    if max_l < sum_l:
        print("Yes")
    else:
        print("No")
    return


if __name__ == '__main__':
    main()

Measured memory_bytes: 9064
/**
 *
 * @author asa
 */
public class Main {

   
    public static void main(String[] a) {
       for(int i=1;i<10;i++){
       for(int j=1;j<10;j++){
           System.out.println(i+"x"+j+"="+(i*j));
         
     }   
     } 
    }
}

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

int main(){
  cout<<fixed<<setprecision(12);
  double x1,y1,x2,y2;
  cin>>x1>>y1>>x2>>y2;
  double result = sqrt(pow(x1-x2,2)+pow(y1-y2,2));
  cout<<result<<endl;
  return 0;
}



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

namespace contest6
{
    class Program
    {
        static void Main(string[] args)
        {
            //空白で分割する
            string line_origin = Console.ReadLine();
            foreach(var ch in  line_origin.Reverse() )
            {
               Console.Write(ch);
            }
            Console.WriteLine();
        }
    }
}

Measured memory_bytes: 5536
def d_digits_parade(S, MOD=10**9 + 7):
    modulo = 13  # 13で割ったあまりを考えている
    # editorialでは2次元配列を考えているが、こうするとメモリを節約できる
    dp = [0] * modulo  # dp[k]: 13で割ったあまりがkの場合の数
    dp[0] = 1  # 初期値を0とすると、これを13で割ったあまりは0

    # Sを下の桁から見ていく
    # ex. 1?2?3: 0 - 3 - ?3 - 2?3 - ...
    mul = 1
    for c in S[::-1]:
        dp_next = [0] * modulo
        if c == '?':
            for k in range(10):  # ?に対し1桁の数字のすべてを試す
                for j in range(modulo):
                    # k * mul: mulの位がk、j: それより下の桁についてのあまり
                    # なので、このような遷移
                    dp_next[(k * mul + j) % modulo] += dp[j]
                    dp_next[(k * mul + j) % modulo] %= MOD
        else:
            k = int(c)
            for j in range(modulo):
                dp_next[(k * mul + j) % modulo] += dp[j]
                dp_next[(k * mul + j) % modulo] %= MOD
        # a*10**d % modulo = (a*(10**d % modulo)) % modulo なので、先に剰余を取る
        # (多倍長整数を持ち出さなくてよくなる)
        mul = (mul * 10) % modulo
        dp = dp_next
    return dp[5]

S = input()
print(d_digits_parade(S))

Measured memory_bytes: 43628
#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
	int n;
	while(scanf("%d",&n),n){
		int x [510] = {0};
		for(int i = 0; i < n+1; i++){
			scanf("%d",&x[i]);
		}
		
		int ans = 0;
		int y = 0,q = 0;
		
		for(int i = 0; i < n+1; i++){
			bool f = false;//first in
			bool s = false;//first -
			bool b = false;//check
			for(int j = 0; j < n+1; j++){
				if(i == j)continue;
				else if(f == false){
					f = true;
					y = x[j];
				}
				else{
					if(s == false){
						s  = true;
						q = x[j] - y;
						y = x[j];
					}
					else{
						if(q != x[j] - y){
							b = true;
							break;
						}
						y = x[j];
					}
				}
			}
			if(b == false){
				ans = x[i];
				break;
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  // bool f = false; // 奇数のものがあり，先手必勝か
  int a;
  rep(i, N) {
    cin >> a;
    if (a % 2 == 1) {
      cout << "first" << endl;
      return 0;    
    }
  }
  cout << "second" << endl;
}

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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair

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

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


int main() {
    i64 N; cin >> N;
    i64 x = N % 10;
    if (x == 2 || x == 4 || x == 5 || x == 7 || x == 9) {
        cout << "hon" << endl;
    } else if (x == 3) {
        cout << "bon" << endl;
    } else {
        cout << "pon" << endl;
    }

    return 0;
}

Measured memory_bytes: 3636
#include <stdio.h>

int main() {
  int n, l, max = 0, sum = 0;
  scanf("%d", &n);
  for (size_t i = 0; i < n; i++) {
    scanf("%d", &l);
    max = (max < l) ? l : max;
    sum += l;
  }
  if (max < sum - max) {
    printf("Yes\n");
  } else {
    printf("No\n");
  }
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <numeric>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

#define rep(i, N) for(int i = 0; i < N; ++i)

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))

using P = pair<int, int>;

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

    int N, T;
    cin >> N >> T;

    vector< P > vp(N);
    rep (i, N)
    {
        int c, t;
        cin >> c >> t;
        vp[i] = P{c, t};
    }

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

    rep (i, N)
    {
        if (vp[i].second <= T)
        {
            cout << vp[i].first << "\n";
            return 0;
        }
    }

    cout << "TLE\n";

    return 0;
}



Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define int long long
#define pb push_back
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define inp(n) for(i=0;i<n;i++) cin>>A[i];
#define inz(A) memset(A,0,sizeof(A))
#define lb lower_bound
#define ub upper_bound
#define all(v) v.begin(),v.end()
#define T 1000000
#define F first
#define S second
#define pi pair<int,int>
#define vi vector<int>
#define mii map<int,int>
#define vp vector<pair< int,int> >
#define mpi map<pair<int,int> ,int>
#define mip map<int, pair<int,int> >
#define inf INT_MAX
#define inf1 LONGLONG_MAX
#define sz(v) v.size()
#define rep(i,n) for(int i=0;i<n;i++)
#define forn(i,a,b) for(int i=a;i<=b;i++)
#define deb(x) cout<<#x<<"is "<<x<<endl;
#define lower(s) transform(all(s),s.begin(),::tolower)
#define endl "\n"
vector<int>adj [T];
			/*brownsands IIITA*/

void solve()
{  int n,k,s,i;
   cin >> n >> k >> s;
   for(i=0;i<k;i++)
   cout << s << " ";
   if(s==1 || s==1000000000)s=500;
   for(i=k;i<n;i++)
   cout << s+1 << " ";
}
signed main()
{
   boost
        int test=0,t;
		//cin>>t;
		t=1;
		while(test++ <t){
            //cout<<"Case "<<test<<": ";
            solve();
            //cerr << "\nTime : " << (double)clock() / (double)CLOCKS_PER_SEC << "s\n";
               }		
} 
               
			
 

				
		
		




Measured memory_bytes: 24832
import java.util.*;

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

        Scanner sc = new Scanner(System.in);
        double x = 0;
        double y = 0;
        int t = 90;

        while (true) {
            String [] line = sc.nextLine().split(",");
            int r = Integer.parseInt(line[0]);
            int dt = Integer.parseInt(line[1]);

            if (r == 0 && dt == 0) break;

            x += r * Math.cos(Math.toRadians(t));
            y += r * Math.sin(Math.toRadians(t));
            t -= dt;

        }

        System.out.println( (int)x );
        System.out.println( (int)y );


    }
}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin>>s;
	if (s=="Sunny")  cout<<"Cloudy"<<endl;
	else if (s=="Cloudy")  cout<<"Rainy"<<endl;
	else cout<<"Sunny"<<endl;
	return 0;
} 

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

int main()
{
  int k;
  cin >> k;
  int p[32] = {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 << p[k-1] << endl;
}


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

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;

#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) (x).begin(),(x).end()
constexpr auto INF = 5000000000000000;
constexpr auto MOD = 1000000007;


int main() {

	int n,q;
	string s;
	cin >> n >> q;
	cin >> s;
	vi l(q), r(q);
	rep(i, q) {
		cin >> l[i] >> r[i];
		l[i]--;r[i]--;
	}

	vi ac = {},acc = {};

	rep(i, n - 1) {
		if (s[i] == 'A' && s[i + 1] == 'C') {
			ac.push_back(i);
			acc.push_back((i + 1));
		}
	}

	if (ac.size() == 0) { rep(i, q)cout << "0" << endl; return 0; }

	rep(i, q) {
		int st, go;

		if (ac[ac.size() - 1] < l[i]) st = ac.size();
		else st = lower_bound(all(ac), l[i]) -ac.begin();

		if (acc[acc.size() - 1] < r[i]+1) go = acc.size();
		else go = lower_bound(all(acc), r[i]+1) - acc.begin();


		cout << go-st <<endl;
	}
}

Measured memory_bytes: 2300
//#include"cpp_kyopro.h"
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <stdlib.h>
#include <math.h>
using namespace std;
int main() {
	int n, x; cin >> n >> x;
	int l[100], ll = 0, i;
	for (i = 0; i < n; i++) {
		cin >> l[i];
		ll += l[i];
		if (ll > x)break;
	}
	cout << i + 1 << endl;
	return 0;
}

Measured memory_bytes: 256
#16:10
h,w,k = map(int,input().split())
mod = 10 ** 9 + 7
fib = [1,1,2,3,5,8,13,21,34]
now = [1] + [0] * w
if w > 1:
  for _ in range(h):
    last = now
    now = [0 for _ in range(w)]
    for i in range(w):
      if i == 0:
        now[i] += last[i] * fib[w-1] % mod
        now[i+1] += last[i] * fib[w-2] % mod
      elif i == w-1:
        now[i] += last[i] * fib[w-1] % mod
        now[i-1] += last[i] * fib[w-2] % mod
      else:
        now[i] += last[i] * fib[i] * fib[w-1-i] % mod
        now[i-1] += last[i] * fib[i-1] * fib[w-1-i] % mod
        now[i+1] += last[i] * fib[i] * fib[w-2-i] % mod
  print(now[k-1] % mod)
else:
  print(1)

Measured memory_bytes: 3064
#include <iostream>
#include <ctype.h>

using namespace std;

int main() {

	string S, T;
	cin >> S >> T;
	size_t s = S.length(), t = T.length();
	int checker = 1;
	for (int i = 0; i < t; i++) {
		if (islower(T[i]) == 0) {
			checker = 0;
			break;
		}
	}
	for (int i = 0; i < s; i++) {
		if (S[i] != T[i]) {
			checker = 0;
			break;
		}
	}

	if (T.length() == s + 1 && 0 < s && s < 11 && checker) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 3632
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(void)
{
    char s[10000];
    int i, count = 0;
    scanf("%s", s);
    size_t j = strlen(s)-1;
    for (i = 0; i < strlen(s) / 2; i++)
    {
        if (s[i] != s[j])
            count++;
        j--;
    }

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

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

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  int ans{};
  for (int i{a}; i <= b; ++i) {
    if (c % i == 0) ++ans;
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 3108
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,b;
  cin>>a>>b;
  
  if(a==b){
    cout<<"Draw"<<endl;
  }
  else if(a!=b&&a==1){
    cout<<"Alice"<<endl;
  }
  else if(a!=b&&b==1){
    cout<<"Bob"<<endl;
  }
  else if(a>b){
    cout<<"Alice"<<endl;
  }
  else if(a<b){
    cout<<"Bob"<<endl;
  }
}

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

const int LOGMAX = 19;

int n;
vector<vector<pair<int, int>>> g;
vector< vector<ll> > cost;
vector< vector<int> > dp;

vector< pair<int, int> > p;
vector< bool > used;

int t = 0;

vector<int> tin, tout;

void hang(int v) {
    used[v] = true;
    tin[v] = t++;
    for (pair<int, int> par : g[v]) {
        int u = par.first;
        int c = par.second;
        if (!used[u]) {
            p[u] = {v, c};
            hang(u);
        }
    }
    tout[v] = t++;
}

bool is_parent(int a, int b) { // is a parent of b
    return (tin[a] <= tin[b]) && (tout[a] >= tout[b]);
}

int LCA(int a, int b) {
    //cout << "LCA(" << a << "," << b << ") is ";
    if (is_parent(a, b)){
        //cout << a << "\n";
        return a;
    }
    if (is_parent(b, a)) {
        //cout << b << "\n";
        return b;
    }
    for (int i = LOGMAX - 1; i >= 0; --i) {
        int next_a = dp[a][i];
        if (!is_parent(next_a, b)) a = next_a;
    }
    //cout << dp[a][0] << "\n";
    return dp[a][0];
}

ll get_price(int a, int b) {
    int c = LCA(a, b);
    ll res = 0;
    for (int level = LOGMAX - 1; level >= 0; --level) {
        int a_next = dp[a][level], b_next = dp[b][level];
        if (is_parent(c, a_next)) {
            res += cost[a][level];
            a = a_next;
        }
        if (is_parent(c, b_next)) {
            res += cost[b][level];
            b = b_next;
        }
    }
    if (dp[a][0] == c) {
        res += cost[a][0];
    }
    if (dp[b][0] == c) {
        res += cost[b][0];
    }
    return res;
}

ll get_ans(int a, int b, int k) {
    return get_price(a, k) + get_price(k, b);
}

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

    cin >> n;
    g.resize(n);
    cost.resize(n);
    dp.resize(n);
    p.resize(n);
    tin.resize(n);
    tout.resize(n);
    for (int i = 0; i < n; ++i) {
        cost[i].resize(LOGMAX);
        dp[i].resize(LOGMAX);
    }

    used.resize(n, false);

    for (int i = 0; i < n - 1; ++i) {
        int a, b, c;
        cin >> a >> b >> c;
        --a;
        --b;
        g[a].push_back({b, c});
        g[b].push_back({a, c});
    }
    p[0] = {0, 0};
    hang(0);

    for (int i = 0; i < n; ++i) {
        cost[i][0] = p[i].second;
        dp[i][0] = p[i].first;
    }
    for (int level = 1; level < LOGMAX; ++level) {
        for (int i = 0; i < n; ++i) {
            cost[i][level] = cost[i][level - 1] + cost[dp[i][level - 1]][level - 1];
            dp[i][level] = dp[dp[i][level - 1]][level - 1];
        }
    }
    int q, k;
    cin >> q >> k;
    --k;
    for (int i = 0; i < q; ++i) {
        int a, b;
        cin >> a >> b;
        --a;
        --b;
        cout << get_ans(a, b, k) << "\n";
    }
}


Measured memory_bytes: 43264
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;


int main(void)
{
    string s,t;
    cin >> s >> t;
    int n = stoi(s + t);

    bool f = false;

    for (int i = 0;i < n;i++)
    {
        if (n == i * i)
        {
            f = true;
        }
    }

    cout << (f? "Yes" : "No") << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>

using namespace std;
using llng = long long;
template<typename T> using v = vector<T>;
template<typename T> using vv = v<v<T> >;

int main() {
    int H, W; cin >> H >> W;
    v<string> a(H); for (int i=0; i<H; i++) cin >> a[i];

    v<int> bucket(26, 0);
    for (int h=0; h<H; h++) for (int w=0; w<W; w++) bucket[a[h][w]-'a']++;

    int cnt = 0;
    for (int i=0; i<26; i++) {
        cnt += bucket[i] / 4;
        bucket[i] %= 4;
    }

    int block = (H/2) * (W/2);
    if (cnt < block) {
        cout << "No" << endl;
        return 0;
    }

    cnt -= block;
    cnt *= 2;
    for (int i=0; i<26; i++) cnt += bucket[i] / 2;

    int line = (H*W - 4*block) / 2;
    if (cnt < line) {
        cout << "No" << endl;
        return 0;
    }

    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
b = []
for i in range(len(a)):
  b.append([a[i], i, 0])
b.sort()
for i in range(len(b)):
  if i < len(b)/2:
    b[i][2] = b[len(b)//2][0]
  else:
    b[i][2] = b[len(b)//2-1][0]
b.sort(key=lambda x: x[1])
for i in range(len(b)):
  print(b[i][2])

Measured memory_bytes: 43840
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int top,S[1000];
void push(int x){
  S[++top]=x;
}
int pop(){
  top--;
  return S[top+1];
}

int main(){
  int a,b,x;
  top = 0;
  char s[100];

  while(scanf("%s", s) != EOF){
    if ( s[0] == '+' ){
      a=pop();
      b=pop();
      push(a+b);
    } else if ( s[0] == '-' ){
      b=pop();
      a=pop();
      push(a-b);
    } else if ( s[0] == '*' ){
      a=pop();
      b=pop();
      push(a*b);
    } else {
      x = atoi(s);
      push(x);        
    }
  }

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



Measured memory_bytes: 2108
/*
ID: hafiz.i1
TASK: milk2
LANG: C++
*/
#include<bits/stdc++.h>

#define ll long long
#define debug(x) cout<<x<<"DE"<<endl;

using namespace std;



int main()
{
//    freopen("milk2.in", "r", stdin);
//    freopen("milk2.out", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,k;
    cin>>k>>n;
    ll l1[n+2];l1[n+1]=0;
    for(int i=1;i<=n;i++){
        cin>>l1[i];
    }if(k>=n){cout<<0;return 0;}
    sort(l1+1,l1+n+1);
    vector<ll>v;
    for(int i=1;i<n;i++){
        v.push_back(l1[i+1]-l1[i]);
    }
    sort(v.begin(),v.end(),greater<int>());
    ll s=0;
    for(int i=k-1;i<n;i++){
        s+=v[i];
    }
    cout<<s;
}


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

void solve()
{
  int N; cin >> N;
  vector<int> A(N);
  rep(i, N){
      cin >> A[i];
  }

  int now = 0;
  rep(i, N){
      if(A[i] == now  + 1){
        now++;          
      }
  }
  if(now == 0)
  {
      cout << -1;
      return;
  }

    cout << (N - now);

}
int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(11);
  solve();
  return 0; 
}


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

using namespace std;

using int64 = long long;
const int mod = 1e9 + 7;
// const int mod = 998244353;

const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;


template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 > &p) {
  os << p.first << " " << p.second;
  return os;
}

template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
  is >> p.first >> p.second;
  return is;
}

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

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

template< typename T, typename... Ts >
auto make_v(size_t a, Ts... ts) {
  return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...));
}

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}

template< typename F >
struct FixPoint : F {
  FixPoint(F &&f) : F(forward< F >(f)) {}

  template< typename... Args >
  decltype(auto) operator()(Args &&... args) const {
    return F::operator()(*this, forward< Args >(args)...);
  }
};

template< typename F >
inline decltype(auto) MFP(F &&f) {
  return FixPoint< F >{forward< F >(f)};
}


int main() {
  string A, B;
  cin >> A >> B;
  cout << B << A << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define ll long long
#define LEFT(a) ((a)<<1)
#define RIGHT(a) (LEFT(a) + 1)
#define MID(a,b) ((a+b)>>1)
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))

using namespace std;

ll POWER (ll x, ll y, ll mod){
    ll ans = 1, c = x;
    while (y){
        if ((y & 1) == 1)
            ans = ans * c % mod;
        c = c * c % mod;
        y /= 2;
    }
    return ans;
}

const int N = 2e5 + 6, MOD = 1e9 + 7;
const double C = 1;

int n;
ll a[N], b[N];
set < pair < ll, ll > > S;
set < pair < ll, ll > >::iterator I, it;
int main()
{
    ios::sync_with_stdio(false);
    cin>>n;
    for (int i = 1; i <= n; i++)
        cin>>a[i];
    for (int i = 1; i <= n; i++)
        cin>>b[i];
    S.insert ({0, 0});
    for (int i = 1; i <= n; i++){
        I = S.upper_bound ({a[i], 0});
        I--;
        ll x = (*I).S + b[i];
        S.insert ({a[i], x});
        while (1){
            I = S.find ({a[i], x});
            it = I;
            it++;
            if (it == S.end())
                break;
            if ((*I).S < (*it).S)
                break;
            S.erase (it);
        }
    }
    I = S.end();
    I--;
    cout<<(*I).S<<endl;
    return 0;
}


Measured memory_bytes: 15872
#include <iostream> 
#include <cstdio> 
#include <fstream> 
#include <algorithm> 
#include <cmath> 
#include <deque> 
#include <vector> 
#include <queue> 
#include <string> 
#include <cstring> 
#include <map> 
#include <stack> 
#include <set> 
using namespace std;
typedef long long ll;
const int maxn = 210000;
int main()
{
	ll n, ans = 0;
	cin >> n;
	cout << 3 * n * n;
}

Measured memory_bytes: 256
import functools

import os

INF = float('inf')


def inp():
    return int(input())


def inpf():
    return float(input())


def inps():
    return input()


def inl():
    return list(map(int, input().split()))


def inlf():
    return list(map(float, input().split()))


def inls():
    return input().split()


def debug(fn):
    if not os.getenv('LOCAL'):
        return fn

    @functools.wraps(fn)
    def wrapper(*args, **kwargs):
        print('DEBUG: {}({}) -> '.format(
            fn.__name__,
            ', '.join(
                list(map(str, args)) +
                ['{}={}'.format(k, str(v)) for k, v in kwargs.items()]
            )
        ), end='')
        ret = fn(*args, **kwargs)
        print(ret)
        return ret

    return wrapper


s = list(input())
s.sort()
if s == list('abc'):
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3572
#include<bits/stdc++.h>
#define int long long
#define ld long double
#define fi first
#define se second
#define vll vector<int>
#define pii pair<int,int>
#define vvll vector< vector<int> >
#define pb push_back
#define sz(v) (int)(v).size()
#define inf 1e10
#define md 1000000007
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b) for(int i=a;i<b;++i)
#define tel(a){cout<<a<<"\n";}
#define tell(a,b){cout<<a<<" | "<<b<<"\n";}
#define telll(a,b,c){cout<<a<<" | "<<b<<" | "<<c<<"\n";}
#define teln(v,n){cout<<"v- ";rep(o,0,n)cout<<v[o]<<" ";cout<<"\n";}
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;

#define M 2010
     

int32_t main(){
    IOS;
    
    int n,k;cin>>n>>k;
    int a[n];
    rep(i,0,n)cin>>a[i];
    int lo=1,hi=inf,mid,ans;
    while(lo<=hi){
    	mid=(lo+hi)>>1;
    	int cnt=0;
    	rep(i,0,n)cnt+=(a[i]-1)/mid;
    	if(cnt<=k)hi=mid-1,ans=mid;
    	else lo=mid+1;
    }
    cout<<ans;
    
   	
	
    return 0;
}

Measured memory_bytes: 5168
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<math.h>
#include<vector>
#include<queue>
#include<map>
#include<stack>
#include<fstream>
#include<stdlib.h>
#include<set>
#include<climits>
#include<cmath>  
#include<memory.h> 
#include<sstream>
#include<time.h>
#include<iomanip>
using namespace std;
const unsigned long long BIGEST=1000000000000000000+1000000000000000000;
const long long BIGER=1000000000000000000;
const int BIG=1000000000;
const long long MOD=1000000007;
const long long LMOD=154590409516822759;
//const long long LMOD=1000000007;
#define Fi first
#define Se second
#define P2 pair
#define Pii pair<int,int>
#define Pll pair<long long,long long>
#define Cb make_pair
#define ll long long
#define Ull unsigned long long
#define Sf scanf
#define Pf printf
#define Pb push_back
#define Psh push
#define Stc stack
#define Vct vector
#define Ret return
#define Re0 return 0
#define Sz size
#define Is insert
#define Que queue
#define Emp empty
#define Fro front
#define Rv reverse
#define Er erase
#define Bg begin
#define Srt sort
#define Pq priority_queue
#define Ins insert
#define Ite iterator
#define Cnt count
#define Cot continue
#define Beg begin
int main()
{
	ll a,b,c;
	cin>>a>>b>>c;
	if(abs(b-c)%2!=0)
	{
		cout<<min((a-b+a-c+1)/2,(b-1+c-1+1)/2);
	}
	else
	{
		cout<<abs(b-c)/2;
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>

using namespace std;

int main(){
   int ans1 = 0, ans2=0;
   char c;
   int i = 0;
   while(cin >> c){
      int p = i%2;
      int n = c - '0';
      if(n^p){
         ans1++;
      }
      else{
         ans2++;
      }
      i++;
   }

   cout << min(ans1, ans2) << endl;
}

Measured memory_bytes: 256
#include <cmath>
#include <vector>
#include <stdio.h>
#include <iostream>
#include <algorithm>
using namespace std;


//-----------------------------------------
string judging(vector<int> sorted_box, int n){

    string ans;
    int max_l = sorted_box[n-1];
    int sum_l = 0;

    for(int i=0; i<=n-2; i++){
        sum_l += sorted_box[i];
    };

    if(max_l < sum_l){
        ans = "Yes";
    }else{
        ans = "No";
    };

    return ans;
}


int main() {
    int N; cin >> N;
    string out;

    vector<int> data;
    for(int i=0; i<N; i++){
        int L; cin >> L;
        data.push_back(L);
    };

    sort(data.begin(), data.end());
    out = judging(data, N);

    cout << out << endl;
    return 0;
}





Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string a,b;
  cin >> a >> b;
  if (a[0]==b[2]&&a[1]==b[1]&&a[2]==b[0]){
    cout << "YES" << endl;
  }
  else {
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int main(){
	char s[110];
	for(int i=0;i<110;i++){
		s[i]='#';
	}
	scanf("%s\n",s);
	int n=0;
	for(int i=0;i<110;i++){
		if(s[i]!='#'){
			n++;
		}
	}
//	printf("%s%d\n",s,n);
	n--;
	if((s[0]=='k'&&s[1]=='e'&&s[2]=='y'&&s[3]=='e'&&s[4]=='n'&&s[5]=='c'&&s[6]=='e')||
		(s[0]=='k'&&s[1]=='e'&&s[2]=='y'&&s[3]=='e'&&s[4]=='n'&&s[5]=='c'&&s[n-1]=='e')||
		(s[0]=='k'&&s[1]=='e'&&s[2]=='y'&&s[3]=='e'&&s[4]=='n'&&s[n-2]=='c'&&s[n-1]=='e')||
		(s[0]=='k'&&s[1]=='e'&&s[2]=='y'&&s[3]=='e'&&s[n-3]=='n'&&s[n-2]=='c'&&s[n-1]=='e')||
		(s[0]=='k'&&s[1]=='e'&&s[2]=='y'&&s[n-4]=='e'&&s[n-3]=='n'&&s[n-2]=='c'&&s[n-1]=='e')||
		(s[0]=='k'&&s[1]=='e'&&s[n-5]=='y'&&s[n-4]=='e'&&s[n-3]=='n'&&s[n-2]=='c'&&s[n-1]=='e')||
		(s[0]=='k'&&s[n-6]=='e'&&s[n-5]=='y'&&s[n-4]=='e'&&s[n-3]=='n'&&s[n-2]=='c'&&s[n-1]=='e')||
		(s[n-7]=='k'&&s[n-6]=='e'&&s[n-5]=='y'&&s[n-4]=='e'&&s[n-3]=='n'&&s[n-2]=='c'&&s[n-1]=='e')){
		printf("YES\n");
	}else{
		printf("NO\n");
	}
}

Measured memory_bytes: 128
n = gets.to_i
array = gets.split.map(&:to_i)
drink_stocks = gets.to_i

drink_data = drink_stocks.times.map { gets.strip.split.map(&:to_i) }
n = 0

sum = array.inject(&:+)

drink_stocks.times do
  p sum - array[drink_data[n][0] - 1] + drink_data[n][1]
  n += 1
end

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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout<<setprecision(32);

	int n, m;
	cin>>n>>m;
	map<int, int> mp;
	ll cur = 0, ans = 0;
	mp[0] = 1;
	for(int i = 0; i < n; i++){
		int x; cin>>x;
		cur = (cur + x)%m;
		ans += mp[cur];
		mp[cur]++;
	}
	cout<<ans<<endl;

	return 0;
}

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

int main(){
	int N;
	scanf("%d", &N);
	double dN = N*2;
	int m = sqrt(dN);
	if(m*(m+1)>>1 != N){
		printf("No\n");
		return 0;
	}
	printf("Yes\n%d\n", m+1);
	int S[m][m];
	for (int i = 0; i < m; ++i) S[i][0] = i + 1;
	for (int i = 0; i < m - 1; ++i){
		for (int j = 0; j <= i; ++j)S[j][i+1] = S[i+1][j+1] = m + (i*(i+1)>>1) + j+1;
	}
	printf("%d", m);
	for (int i = 0; i < m; ++i) printf(" %d", i+1);
	printf("\n");
	for (int i = 0; i < m; ++i){
		printf("%d", m);
		for (int j = 0; j < m; ++j) printf(" %d", S[i][j]);
		printf("\n");
	}
	return 0;
}

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

def g(n):
    b = format(-n, 'b')
    ret = [0] * (len(b) + 2)
    for i, x in enumerate(reversed(b)):
        if x == '0': continue
        if i & 1:
            if ret[i]:
                ret[i] = 0
                ret[i+2] = ret[i+1] = 1
            else:
                ret[i] = 1
        else:
            if ret[i]:
                ret[i] = 0
            else:
                ret[i] = ret[i + 1] = 1
    ret = ret[::-1]
    return ret[ret.index(1):]

def f(n):
    b = format(n, 'b')
    ret = [0] * (len(b) + 2)
    for i, x in enumerate(reversed(b)):
        if x == '0': continue
        if i & 1:
            if ret[i]:
                ret[i] = 0
            else:
                ret[i] = ret[i + 1] = 1
        else:
            if ret[i]:
                ret[i] = 0
                ret[i+2] = ret[i+1] = 1
            else:
                ret[i] = 1
    ret = ret[::-1]
    return ret[ret.index(1):]

if N == 0:
    print(0)
elif N > 0:
    print("".join([str(x) for x in f(N)]))
else:
    print("".join([str(x) for x in g(N)]))

Measured memory_bytes: 3192
n, m = map(int, input().split())
x = list(map(int, input().split()))
x.sort()
l = [x[i]-x[i-1] for i in range(1,m)]
l.sort(reverse=True)
ans = x[m-1] - x[0]
if n >= m:
    print(0)
else:
    for i in range(n-1):
        ans -= l[i]
    print(ans)

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

#define be begin
#define en end
#define pb push_back
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
#define REP2(i,s,n) for(int (i)=(s);(i)<(n);(i)++) 

template<typename T> using V = vector< T >;
using Vi = V<int>;

int main(){
    int n;
    Vi d;
    cin>>n;
    REP(i,n){
        int tmp;
        cin>>tmp;
        d.pb(tmp);
    }
    int total=0;
    REP2(i,0,n){
        REP2(j,i+1,n){
            total+=d[i]*d[j];
        }
    }
    cout<<total<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0;i<n;++i)
#define REP(i, k, n) for(int i=k; i<=n; ++i)
#define REPR(i, k, n) for(int i=k; i>=n; --i)
#define MAX 2001
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define r return
typedef long long ll;
typedef long long int lli;
typedef unsigned long long ull;
typedef unsigned int long long uill;
int main(){

	ios::sync_with_stdio(0);
	cin.tie(0);
	set<char> s1;
	vector<int> v;
	int cnt=0;
	int flag=1;
    int a,b,c,d;

    cin>>a>>b>>c>>d;

     int ma = max(a,c);
     int mi = min(b,d);

    
    cout << max(0, mi-ma) << "\n";

   //50 55 25 40



  // ----------50------55----
  // ---25-40------

    return 0;


}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
#define endl '\n'
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define rf(i,a,b) for(int i=a;i>=b;i--) 
#define fast_io ios_base::sync_with_stdio(0);
#define show(x) cout<<x<<endl;
#define pret(x) cout<<x<<endl; return 0;
#define disp(x) cout<<x<<" ";
#define let(x,y) cout<<x<<" "<<y<<endl;
ll MOD=1e9+7;
ll MAX=9223372036854775807;

ll dp[112][15],fib[20];

int main(){
    fast_io;
    int h,w,k;
    cin>>h>>w>>k;
    fib[2]=2,fib[3]=3;
    fib[0]=1,fib[1]=1;
    fo(i,4,19) fib[i]=(fib[i-1]+fib[i-2])%MOD;
    dp[h+1][1]=1;
    rf(i,h,1){
    	// {
    		// int j=2;
    	fo(j,1,w) {
    // show(dp[1][k]);
    		dp[i][j] = (dp[i+1][j]*((fib[j-1]*fib[w-j])%MOD))%MOD;
    // show(dp[1][k]);
    		if(j+1<=w) dp[i][j] = (dp[i][j] + dp[i+1][j+1]*((fib[j-1]*fib[w-j-1])%MOD))%MOD;
    // show(dp[1][k]);
    		if(j-1>0) dp[i][j] = (dp[i][j] + dp[i+1][j-1]*((fib[j-2]*fib[w-j])%MOD))%MOD;
    // show(dp[1][k]);
    	}
    }
    show(dp[1][k]);
    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Main {
    public static void main(String[] args) {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        String input;
        List<Integer> inputList = new ArrayList<Integer>();

        try {
            int max = 0;
            while((input = reader.readLine()) != null) {
                int tmp = Integer.parseInt(input);
                inputList.add(tmp);
                if(tmp > max){
                    max = tmp;
                }
            }
            boolean[] prime = new boolean[max];
            prime[0] = false;
            for(int i=1; i<max; i++){
                prime[i] = true;
            }
            for(int i=1; i<max; i++){
                if(prime[i]){
                    for(int j=i+i+1; j<max; j=j+i+1){
                        prime[j] = false;
                    }
                }
            }
            for(int i=0; i<inputList.size(); i++){
                int count = 0;
                for(int j=0; j<inputList.get(i); j++){
                    if(prime[j]){
                        count++;
                    }
                }
                System.out.println(count);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

Measured memory_bytes: 22492
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


struct Info{
	int start,end;
};


int main(){

	int N;
	scanf("%d",&N);

	Info info[N];
	for(int i = 0; i < N; i++){
		scanf("%d %d",&info[i].start,&info[i].end);
	}

	bool watched[N];
	for(int i = 0; i < N; i++)watched[i] = false;

	int count = 0;
	int  min_end,min_index;

	for(int day = 1; day <= 31; day++){

		min_end = BIG_NUM;

		for(int i = 0; i < N; i++){
			if(watched[i])continue;
			if(info[i].end < day || info[i].start > day)continue;

			if(min_end > info[i].end){
				min_end = info[i].end;
				min_index = i;
			}
		}

		if(min_end != BIG_NUM){
			count++;
			watched[min_index] = true;
		}
	}

	printf("%d\n",100*count+50*(31-count));

}

Measured memory_bytes: 3228
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <ctime>
using namespace std;
 
#define rep(i,a,n) for(int i=a; i<n; i++)
#define repr(i,a,n) for(int i=a; i>=n; i--)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 999999999
 
#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
 
typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long int ll;
 
typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;
 
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int const MOD = 1000000007;
 
namespace std {
    bool operator<(const P a, const P b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}
 
int main() {
    int a,b;
    bool first = true;
    while(cin >> a >> b) {
        if(a == 0 && b == 0) break;
        if(!first) cout << endl;
        first = false;
        vector<int> ans;
        rep(i,a,b+1) {
            if(i % 400 == 0) ans.pb(i);
            else if(i % 100 != 0 && i % 4 == 0) ans.pb(i);
        }
        if(ans.empty()) cout << "NA" << endl;
        else {
            rep(i,0,ans.size()) cout << ans[i] << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1228
#include<bits/stdc++.h>
using namespace std;
using Graph=vector<vector<int>>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
typedef long long ll;
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;
}
int main(){
    ll N;cin>>N;
    vector<ll>A(N);
    rep(i,N){
        cin>>A[i];
    }
    ll sum=0;
    for(int i=1;i<N;i++){
        if(A[i]<A[i-1]){
            int k=A[i-1]-A[i];
            A[i]+=k;
            sum+=k;
        }
    }
    cout<<sum<<endl;
}

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

int n;
vector<int> vec, vec2;
int dp[1000005], dp2[1000005];

int main(void)
{
    for(long long x, i = 1; (x = i*(i+1)*(i+2)/6, x) <= 1000000; i++){
        if(x % 2) vec2.push_back(x);
        vec.push_back(x);
    }
    
    for(int i = 0; i <= 1000000; i++) dp[i] = dp2[i] = 1e9;
    dp[0] = dp2[0] = 0;
    for(int i = 0; i < 1000000; i++){
        for(int j = 0; j < vec.size(); j++){
            if(i+vec[j] <= 1000000) dp[i+vec[j]] = min(dp[i+vec[j]], dp[i]+1);
        }
        for(int j = 0; j < vec2.size(); j++){
            if(i+vec2[j] <= 1000000) dp2[i+vec2[j]] = min(dp2[i+vec2[j]], dp2[i]+1);
        }
    }
    
    while(cin >> n, n){
        cout << dp[n] << " " << dp2[n] << endl;
    }
    return 0;
}



Measured memory_bytes: 10924
#include<set>
#include<cstdio>
#include<algorithm>
#include<iostream>
using namespace std;
int main()
{
	set<int> st;
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		int t;
		cin>>t;
		st.insert(t);
	}
		cout<<st.size()<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll         = long long;
constexpr ll MOD = 1000000007;
#define REP(i, n) for (ll i = 0; i < (n); i++)
#define REP2(i, x, n) for (ll i = x; i < (n); i++)
const long long INF = numeric_limits<long long>::max();
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;
}
int main() {
    ll N;
    cin >> N;

    if (N == 1) {
        cout << 1 << endl;
        return 0;
    }
    ll value = 1;
    while (value < N) {
        value <<= 1;
    }
    if (value != N) {
        value >>= 1;
    }
    cout << value << endl;
    return 0;
}

Measured memory_bytes: 3620
function main(input) {
  const inputs = input.split('\n')
  const [X] = inputs[0].split(' ')
  let hap = 0
  hap += Math.floor(X / 500) * 1000
  hap += Math.floor((X % 500) /5) * 5
  console.log(hap)
}
main(require("fs").readFileSync("/dev/stdin", "utf8"));



Measured memory_bytes: 7372
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
using namespace std;
#define INF 100000000

typedef long long ll;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};

const int MAXN = 5200;
vector<int> table[MAXN];

int main(void) {
    int N, M;
    cin >> N >> M;
    for (int i = 0; i < MAXN; i++) {
        table[i].resize(i+20);
    }
    while (M--) {
        int a, b, x;
        cin >> a >> b >> x;
        table[a][b]++;
        table[a][b+1]--;
        table[a+x+1][b]--;
        table[a+x+2][b+1]++;
        table[a+x+1][b+x+2]++;
        table[a+x+2][b+x+2]--;
    }
    // 左から右
    for (int i = 0; i < MAXN-100; i++) {
        for (int j = 1; j < i+10; j++) {
            table[i][j] += table[i][j-1];
        }
    }
    // 右上から左下
    for (int i = 1; i < MAXN-100; i++) {
        for (int j = 0; j < i+10; j++) {
            table[i][j] += table[i-1][j];
        }
    }
    // 左上から右下
    for (int i = 1; i < MAXN-100; i++) {
        for (int j = 1; j < i+10; j++) {
            table[i][j] += table[i-1][j-1];
        }
    }
    int ans = 0;
    for (int i = 0; i < MAXN; i++) {
        for (int j = 0; j < i+10; j++) {
            if (table[i][j] > 0) ans++;
        }
    }
    cout << ans << endl;
//    for (int i = 0; i < 10; i++) {
//        for (int j = 0; j < 10; j++) {
//            cout << table[i][j] << "\t";
//        }
//        cout << endl;
//    }
    return 0;
}

Measured memory_bytes: 54584
#include<iostream>
#include<vector>
using namespace std;
int main() {
	int N;
	cin >> N;
	vector<int>d(N);
	for (int i = 0;i < N;++i) {
		cin >> d[i];
	}
	int ans = 0;
	for (int i = 0;i < N;++i) {
		for (int j = i + 1;j < N;++j) {
			ans += d[i] * d[j];
		}
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 256