akhauriyash/Code-Regression huggingface dataset:
n, k = map(int, input().split())
p = list(map(int, input().split()))
c = list(map(int, input().split()))

def check(start):
    global k
    i = start
    cnt = 0
    score = 0
    cand = []
    while True:
        i = p[i] - 1
        score += c[i]
        cand.append(score)
        cnt += 1
        if i == start:
            break
    res = - 10 ** 10
    if score >= 0:
        for j, candj in enumerate(cand):
            if k - j - 1 >= 0:
                res = max(res, ((k - j - 1) // cnt) * score + candj)
    else:
        for j, candj in enumerate(cand):
            if k - j - 1 >= 0:
                res = max(res, candj)
    return res

ans = - 10 ** 10

for i in range(n):
    ans = max(ans, check(i))

print(ans)

    

Measured memory_bytes: 82884
#include <stdio.h>
#include <stdlib.h>

int main(void) 
{
	long long int num1, num2, GCD = 0, LCM = 0, i = 0;
	
	while(scanf("%lld %lld", &num1, &num2)!=EOF) 
	{
		LCM = num1*num2;
	
		if(num1 > num2)
			num1 -= num2;
		else
			num2 -= num1;
	
		for(i = 0; i <100; i++)
		{
			if(num2 == 0)
			{
				GCD = num1;
				break;
			}
								
			num1 = num1 % num2;
			
			if(num1 == 0)
			{
				GCD = num2;
				break;
			}
				
			num2 = num2 % num1;
		}				
	
		LCM /= GCD;
	
		printf("%lld %lld\n", GCD, LCM);
	}
	
	return 0;
}


Measured memory_bytes: 1980
//FIRST THINK THEN CODE.

  #include <bits/stdc++.h>


  using namespace std;

  typedef long long ll;

  #define rep(i,a,b) for(ll i=a;i<b;++i)
  #define rrep(i,a,b) for(ll i=a;i>b;--i)
  #define FOR(i,n)  for(ll i=0;i<n;i++)
  #define vi vector<int>
  #define vl vector<ll>
  #define ld long double
  #define vld vector<ld>
  #define vvi vector<vector<int>>
  #define vvl vector<vector<long long>>
  #define vvld vector<vector<ld>>
  #define pii pair<int,int>
  #define pll pair<long,long>
  #define vpii vector<pii>
  #define vpll vector<pll>
  #define ff first
  #define ss second
  #define pb push_back
  #define pf push_front
  #define mp make_pair
  #define lb lower_bound
  #define ub upper_bound
  #define bs binary_search
  #define d1(x) cout<<(x)<<endl
  #define d2(x,y) cout<<(x)<<" "<<(y)<<endl
  #define d3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
  #define d4(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl
  #define PI 3.1415926535897932384626433832795
  #define fix(f,n) fixed<<setprecision(n)<<f
  #define all(x) x.begin(),x.end()
  #define rev(p) reverse(p.begin(),p.end());
  #define endl "\n"
  #define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
  #define popcount(x) __builtin_popcountll(x)
  #define sz(x) ((ll)x.size())
  const ll M=1000000007;
  const ll MM=998244353;
  ll begtime = clock();
  #define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
  //#define _Find_next 
  //#define _Find_first 



  ll newmod(ll a,ll b)
  {
  return ((a%b)+b)%b;
  }


  ll powM(ll a,ll b,ll m )
  { 
  if(a<=0)return 0;
  a%=m;
  if(!b)return 1;
  ll ans=1LL;
  while(b)
  {
  if(b&1)ans=ans*a%m;
  a=a*a%m;
  b>>=1;
  }

  return ans;
  }



  ll poww(ll a,ll b)
  { 

  ll ans=1;
  while(b)
  {
  if(b&1)ans=ans*a;
  a=a*a;
  b>>=1;
  }

  return ans;

  }

  template<typename T,typename F>
  void chmax( T &a,F b){
  if(b>a)a=b;
  }

  template<typename T,typename F>
  void chmin( T &a,F b){
  if(b<a)a=b;
  }



  const ll N=1e5+5;



  int main()
  { 

  IOS;

string s;cin>>s;

ll ret=0;
ll n=sz(s);

FOR(i,n)
{
  ret+=s[i]-'0';
}

if(ret%9){
  cout<<"No";
}
else cout<<"Yes";

  //end_routine();

  return 0;

  }

Measured memory_bytes: 3808
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define endl "\n"
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define F first
#define S second
#define bitcnt(v) __builtin_popcount(v)
#define all(v) v.begin(), v.end()

int n, m;
vector<vector<int>> graph;
vector<int> dp;
vector<bool> vis;

int dfs(int u){
	if(dp[u] != -1) return dp[u];
	vis[u] = 1;
	int ans = 0;
	for(int v : graph[u]){
		ans = max(ans, 1 + dfs(v));
	}
	return dp[u] = ans;
}

void solution(){
	cin >> n >> m;
	graph = vector<vector<int>>(n);
	dp = vector<int>(n,-1);
	vis = vector<bool>(n,0);
	for(int i = 0; i < m; i++){
		int u,v; cin >> u >> v;
		u--, v--;
		graph[u].push_back(v);
	}
	int ans = 0;
	for(int i = 0; i < n; i++){
		if(!vis[i]){
			dfs(i);
		}
	}
	cout << *max_element(all(dp)) << endl;
}	


int main(){ 
	fio;
	int t;
	t = 1;
	// cin >> t;
	for(int i = 1; i <= t; i++){
		// cout << "Case #" << i << ": ";
		solution();
	} 
	return 0;
}

Measured memory_bytes: 11000
#include<stdio.h>

int main(){

   int n;
   double w;
   double h;

   while(scanf("%d,%lf,%lf",&n,&w,&h)!=EOF){

      double bmi;
      bmi = w/(h*h);

      if(bmi>=25){
         printf("%d\n",n);
      }

   }
   

   return 0;
}

Measured memory_bytes: 628
#include <iostream>
#include <algorithm>
using namespace std;
int a[111111][10];
int dp[111111][11];
int main() {
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= 3; j++) {
			cin >> a[i][j];
		}
	}
	for (int i = 1; i <= n; i++) {
		dp[i][1] = max(dp[i-1][2], dp[i-1][3]) + a[i][1];
		dp[i][2] = max(dp[i-1][1], dp[i-1][3]) + a[i][2];
		dp[i][3] = max(dp[i-1][2], dp[i-1][1]) + a[i][3];
	}
	cout << max(dp[n][1], max(dp[n][2], dp[n][3]));
}

Measured memory_bytes: 11832
//自称高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

int main() {
    double ans = 0;
    int tmp;
    int w, h, x,y;
    cin >> w >> h >> x >> y;
    ans = (double)((double)w * (double)h /2.0);
    if(x*2==w && y*2==h)cout << ans << " " << 1 << endl;
    else cout << setprecision(10) << ans << " " << 0 << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
	int a,b;
	scanf("%d%d",&a,&b);
	if(a%3==0 || b%3==0 || (a+b)%3==0){
		printf("Possible\n");
	}else{
		printf("Impossible\n");
	}
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define int           long long
#define pb            push_back
#define x             first
#define y             second
#define sz(v)         (int)v.size()
#define all(x)        (x).begin(),(x).end()
#define PI            3.14159265358979
#define N             1000005

int m[N];

int solve(){
    int n; cin>>n;
    int a[n];
    for(int i=0; i<n; i++){
        cin>>a[i];
        m[a[i]]++;
    }
    int ans=0;
    for(int i=0; i<n; i++){
        bool f=0;
        m[a[i]]--;
        for(int j=1; j*j<=a[i]; j++){
            if(a[i]%j==0){
                int t1=j,t2=a[i]/j;
                if(m[t1]>0||m[t2]>0){
                    f=1; break;
                }
            }
        }
        m[a[i]]++;
        if(!f)
            ans++;
    }
    cout<<ans;
    return 0;
}

signed main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t=1;
    // cin>>t;
    while(t--) solve();
    return 0;
}

Measured memory_bytes: 12920
t1, n1= map(int, input(). split())
t2, n2= map(int, input(). split())
t3, n3= map(int, input(). split())
t4, n4= map(int, input(). split())

i = 1
while i <= 4:
    if t1== 1:
        t1 = 6000
    elif t1 == 2:
        t1 = 4000
    elif t1 == 3:
        t1 = 3000
    elif t1 == 4:
        t1 = 2000

    elif t2 == 1:
        t2 = 6000
    elif t2 == 2:
        t2 = 4000
    elif t2 == 3:
        t2 = 3000
    elif t2 == 4:
        t2 = 2000

    elif t3 == 1:
        t3 = 6000
    elif t3 == 2:
        t3 = 4000
    elif t3 == 3:
        t3 = 3000
    elif t3 == 4:
        t3 = 2000

    elif t4 == 1:
        t4 = 6000
    elif t4 == 2:
        t4 = 4000
    elif t4 == 3:
        t4 = 3000
    elif t4 == 4:
        t4 = 2000
        
    i += 1
    
print(t1*n1)
print(t2*n2)
print(t3*n3)
print(t4*n4)


Measured memory_bytes: 5604
#include <cstdio>
#include <functional>
#include <algorithm>
#include <vector>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iostream>
#include <queue>
#include <math.h>
#include <bits/stdc++.h>
#include <queue>
#include <map>

using namespace std;

#define INF (1ll<<60)
#define INFint (1<<30)
#define MOD 1000000007
#define BOUND 27182818284

typedef long long ll;
typedef long long int lli;
typedef pair<int,int> P;

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

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

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

// gcd
template<typename T>
T gcd(T a, T b){
    if(a==0)
        return b;
    return gcd(b%a,a);
}

// gcd array
int findGCD(int arr[], int n){
    int result = arr[0];
    for (int i=1; i < n; i++)
        result = gcd(arr[i], result);
    return result;
}

template<typename T>
T lcm( T m, T n ){
    // 引数に0がある場合は0を返す
    if ( ( 0 == m ) || ( 0 == n ) )
        return 0;
    return ((m/gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    fill( (T*)array, (T*)(array+N), val );
}


int dx[5]={1,0,-1,0};
int dy[5]={0,1,0,-1};
// v.front() = -BOUND;
// v.back() = BOUND;
bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }
    // 素数である
    return true;
}

int main() {
    int N;
    cin >> N;
    vector<ll>a(N,0);
    rep(i,N){
        cin >> a[i];
    }
    sort(a.begin(),a.end());
    ll aa=1LL<<60, boarder=1LL<<60;
    auto itr=lower_bound(a.begin(), a.end(), a[N-1]/2);
    if(abs(a[N-1]/2-*itr)<boarder && *itr!=a[N-1]){
        aa=*itr;
        boarder=abs(a[N-1]/2-*itr);
    }

    if(itr>a.begin() && abs(a[N-1]/2-*(--itr)) <boarder){
        aa=*itr;
    }

    cout << a[N-1] << " " << aa << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cmath>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

class UnionFind {
  vector<int> par, rank, potential;
public:
  UnionFind(int n) {
    par.resize(n, -1);
    rank.resize(n, 0);
    potential.resize(n, 0);
  }
  int root(int x) {
    if (par[x] < 0)
      return x;
    int r = root(par[x]);
    potential[x] += potential[par[x]];
    return par[x] = r;
  }
  int size(int x) {
    return -par[root(x)];
  }
  int weight(int x) {
    root(x);
    return potential[x];
  }
  bool same(int x, int y) {
    return root(x) == root(y);
  }
  bool unite(int x, int y, int w = 0) {
    w += weight(x);
    w -= weight(y);
    x = root(x);
    y = root(y);
    if (x == y) {
      return false;
    }
    if (rank[x] < rank[y]) {
      swap(x, y);
      w = -w;
    }
    if (rank[x] == rank[y])
      rank[x]++;
    par[x] += par[y];
    par[y] = x;
    potential[y] = w;
    return true;
  }
  int diff(int x, int y) {
    return weight(y) - weight(x);
  }
};

const int MAX = 100010;

int main() {
  int n;
  cin >> n;
  vector<int> x(n), y(n);
  UnionFind uf(MAX*2);
  rep(i, n) {
    cin >> x[i] >> y[i];
    uf.unite(x[i], y[i]+MAX);
  }
  map<int, ll> xnum, ynum;
  rep(i, MAX) {
    xnum[uf.root(i)]++;
    ynum[uf.root(i+MAX)]++;
  }
  ll mx = 0;
  rep(i, MAX*2)
    mx += xnum[i]*ynum[i];
  cout << mx-n << endl;
  return 0;
}

Measured memory_bytes: 28416
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define WHATIS(x) cout << #x << " is " << x << endl;
#define ERROR(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, ll> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << *it << " = " << a << endl;
    err(++it, args...);
}

const ll MODBASE = 1000000007LL;
const int MAXN = 200010;
const int MAXM = 100010;
const int MAXK = 510;
const int MAXQ = 200010;


int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    int n, m;
    cin >> n >> m;
    if (n > m) swap(n, m);
    if (m > n+1) {
        cout << 0;
        return 0;
    }
    ll p = 1;
    FOR(i,1,n) p = p * i % MODBASE;
    if (n == m) cout << p * p % MODBASE * 2 % MODBASE;
    else cout << p * p % MODBASE * m % MODBASE;
    return 0;
}

Measured memory_bytes: 256
def get_input():
    while True:
        try:
            yield ''.join(input())
        except EOFError:
            break

N = list(get_input())


for l in range(len(N)):
    c = [4, 1, 4, 1, 2, 1, 2, 1]
    p = [int(i) for i in N[l].split()]
    for i in range(len(p)):
        if p[i] > 9:
            p[i] = 9

    V = 99999999
    score = 99999
    for d in range(8):
        s = 0
        for i in range(8):
            s += max(p[i] - c[(i+d)%8], 0)

        v = 0
        for i in range(8):
            v *= 10
            v += c[(i+d)%8]

        if s < score:
            score = s
            V = v
        elif s == score:
            if v < V:
                V = v

    ans = str(V)
    for i in range(7):
        print(ans[i], end=" ")
    print(ans[7])


Measured memory_bytes: 5728
a =[]
for i in range(3):
    a.append(input().split())
#print(a)
n = int(input())



for k in range(n):
    b = input()
    for i in range(3):
      for j in range(3):
        if(b == a[i][j]):
          a[i][j] = 'maru'

#print(a)          

frag = False


for i in range(3):
     if((a[i][0] == 'maru') and (a[i][1] == 'maru')and(a[i][2] == 'maru')):
        frag = True

for i in range(3):
     if((a[0][i] == 'maru') and (a[1][i] == 'maru')and(a[2][i] == 'maru')):
        frag = True

if((a[0][0] == 'maru')and(a[1][1] == 'maru')and(a[2][2]=='maru')):
    frag = True
if((a[2][0] == 'maru')and(a[1][1] == 'maru')and(a[0][2]=='maru')):
    frag = True
        

if(frag == True):
    print('Yes')
else:
    print('No')






Measured memory_bytes: 3064
n = int(input())
A = list(map(int, input().split()))
F = [int()] * n
F[0] = A[0]
for b in range(1, n):
    F[b] = F[b - 1] + A[b]


res = [0]*4
data = [10 ** 18] * 2
ex = [0]*4
ans = 10 ** 18
s = 0
t = 2
for i in range(1, n - 2):
    bl = [True, True]
    for j in range(s, i):
        res[0] = F[j]
        res[1] = F[i] - F[j]
        if not bl[0]:
            break
        if data[0] > abs(res[1] - res[0]) or j == s:
            s = j
            ex[0] = res[0]
            ex[1] = res[1]
            data[0] = abs(res[1] - res[0])
        else:
            bl[0] = False
    for k in range(t, n):
        res[2] = F[k] - F[i]
        res[3] = F[n - 1] - F[k]
        if not bl[1]:
            break
        if data[1] > abs(res[3] - res[2]) or k == t:
            t = k
            ex[2] = res[2]
            ex[3] = res[3]
            data[1] = abs(res[3] - res[2])
        else:
            bl[1] = False
    ans = min(ans, max(ex) - min(ex))

print(ans)

Measured memory_bytes: 25672
"use strict";
const Main = (input) =>{
   let xs = input.trim().split(' ').map(v=>parseInt(v,10));
   if(xs[0]%2==0){
   console.log(xs[0]/2);
   }else{
   console.log(Math.ceil(xs[0]/2));
   }
}
Main(require('fs').readFileSync('/dev/stdin','utf8'));

Measured memory_bytes: 7372
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func readInts(stdin *bufio.Scanner) []int {
	stdin.Scan()
	text := stdin.Text()
	ss := strings.Split(text, " ")
	ii := make([]int, len(ss))
	for j, s := range ss {
		i, _ := strconv.Atoi(s)
		ii[j] = i
	}
	return ii
}

func main() {
	stdin := bufio.NewScanner(os.Stdin)
	var z []int
	readInts(stdin)
	z = readInts(stdin)
	s := 0
	lz := len(z)
	for i := 0; i < lz-1; i++ {
		for j := i+1; j < lz; j++ {
			s += z[i] * z[j]
		}
	}
	fmt.Println(s)
}

Measured memory_bytes: 640
package main

import (
	"fmt"
	"math"
	"strconv"
	"strings"
)

func main() {
	var n int
	fmt.Scan(&n)

	list := search(n)

	fmt.Println(len(list))
}

func search(n int) []int {
	d := int(math.Floor(math.Log10(float64(n)))) + 1
	if d < 4 {
		list := []int{}
		for _, p := range []int{357, 375, 537, 573, 735, 753} {
			if p <= n {
				list = append(list, p)
			}
		}
		return list
	}

	m, _ := strconv.Atoi(strings.Repeat("9", d-1))

	prev := search(m)
	list := make([]int, 0, 10*len(prev))

	min, _ := strconv.Atoi(strings.Repeat("9", d-2))

	for _, p := range prev {
		if p < min {
			continue
		}
		for _, q := range []int{3, 5, 7} {
			for i := 0; i < d; i++ {
				f := int(math.Pow10(i))
				r := f*q + p%f + (p/f)*10*f
				if r <= n {
					list = append(list, r)
				}
			}
		}
	}

	set := make(map[int]struct{}, len(list))
	for _, n := range list {
		set[n] = struct{}{}
	}
	newList := make([]int, 0, len(set))
	for p := range set {
		newList = append(newList, p)
	}

	return append(newList, prev...)
}


Measured memory_bytes: 7808
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  char A;
  cin >> A;
  string alp = "abcdefghijklmnopqrstuvwxyz";
  rep(i, alp.size()) {
    if(A == alp.at(i)) {
      cout << alp.at(i + 1) << endl;
    }
  }
}


Measured memory_bytes: 3520
n = int(input())
s = [list(input()) for i in range(n)]

se = set(s[0])
for j in s:
    se &= set(j)

ls = list(se)
ls.sort()

ans = ""
for k in range(len(ls)):
    a_count = 10**6
    char = ls[k]

    for j in s:
        count = j.count(char)
        a_count = min(a_count, count)

    for m in range(a_count):
        ans += char

print(ans)


Measured memory_bytes: 3060
#include <stdio.h>

int min(int a,int b){
	if(a<=b){return a;}
	else{return b;}
}

int a[45];
int b[45];
int c[45];
int dp[45][415][415];

int main(){

	int N,Ma,Mb;

	scanf("%d %d %d",&N,&Ma,&Mb);

	int i,j,k;

	for(i=0;i<N;i++){
		scanf("%d %d %d",&a[i],&b[i],&c[i]);
	}

	for (i = 0; i <= 40; i++) {
		for (j = 0; j <= 400; j++) {
			for (k = 0; k <= 400; k++) {
				dp[i][j][k] = 10000;
			}
		}
	}

	dp[0][0][0]=0;

	for(i=0;i<N;i++){
		for(j=0;j<=400;j++){
			for(k=0;k<=400;k++){
				if(dp[i][j][k]==10000){continue;}
				dp[i+1][j][k]=min(dp[i+1][j][k],dp[i][j][k]);
				dp[i+1][j+a[i]][k+b[i]]=min(dp[i+1][j+a[i]][k+b[i]],dp[i][j][k]+c[i]);
			}
		}
	}

	int ans=10000;
	for(i=1;;i++){
		if(Ma*i>400||Mb*i>400){break;}
		ans=min(ans,dp[N][Ma*i][Mb*i]);
	}

	if(ans==10000){printf("-1\n");}
	else{
	printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 28928
def main():
    (N,Y) = map(int,input().split())
    x = 0
    y = 0
    z = 0
    flag = False

    for x in range(int(Y/10000)+1):
        for y in range(int((Y-10000*x)/5000)+1):
            z = (Y - (10000*x) - (5000*y)) / 1000
            if x+y+z == N:
                flag = True
            if flag: break
        if flag: break
    if flag: print("%d %d %d"%(x,y,z))
    else: print("-1 -1 -1")
    return


main()


Measured memory_bytes: 3060
n = int(input())
s = input()
begin = 0
end = 0
for i in range(n):
    if s[i] == "(":
        begin += 1
    if s[i] == ")":
        if begin > 0:
            begin -= 1
            continue
        end += 1
print("("*end + s + ")"*begin)

Measured memory_bytes: 38384
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>

using namespace std;


void solve() {
    int N; string s;
    cin >> N >> s;
    int cnt = 0;
    for (int i = 0; i < N-2; i++) {
        if (s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C') cnt++;
    }

    cout << cnt << endl;
}


int main() {
    solve();
    return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
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;
}
void print() { cout << "\n"; }
template <class T> void print(const T &x) { cout << x << "\n"; }
template <class T, class... Args> void print(const T &x, const Args &... args) {
    cout << x << " ";
    print(args...);
}
template <class T> void printVector(const vector<T> &v) {
    for(const T &x : v) {
        cout << x << " ";
    }
    cout << "\n";
}
using ll = long long;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
constexpr int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<ll> a(n);
    map<ll, vector<int>> mp;
    for(int i = 0; i < n; i++) {
        cin >> a[i];
        mp[i - a[i]].emplace_back(i);
    }
    ll ans = 0;
    for(int i = 0; i < n; i++) {
        const auto &v = mp[i + a[i]];
        ans += v.end() - upper_bound(ALL(v), i);
    }
    print(ans);
}

Measured memory_bytes: 38924
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
//#include<algorithm>
//#include<cmath>
using namespace std;
int main() {
	int ans,b;
	char op;
	while (cin >> ans >> op >> b) {
		switch (op) {
		case'+':ans += b; break;
		case'-':ans -= b; break;
		case'*':ans *= b; break;
		case'/':ans /= b; break;
		case'?':return 0;
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3080
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
    char str[11];
    char three[3];
    int num,min=1000,sa,len,i,j=0;

    scanf("%s",str);
    len = strlen(str);
    while(j<len-2){
        strncpy(three, str+j,3);
        three[3] = '\0';
        num = atoi(three);
        sa = 753 - num;
        if(sa<0){
            sa *= -1;
        }
        if(sa < min){
            min = sa;
        }
        j++;
    }

        printf("%d",min);
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int mod=1e9+7;
int main(){
	int n,m;
	cin>>n>>m;
	int a[n][m];
	char c[n+1][m+1];
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++)
		{
			cin>>c[i][j];
		}
	}
	int i=0;
	while(c[i][0]=='.'&&i<n){
		a[i][0]=1;
		i++;
	}
	while(i<n){
		a[i][0]=0;
		i++;
		}
		i=0;
	while(c[0][i]=='.'&&i<m){
		a[0][i]=1;
		i++;
	}
	while(i<m){
		a[0][i]=0;
		i++;
		}
	for(int i=1;i<n;i++){
		for(int j=1;j<m;j++){
			if(c[i][j]=='.')
			a[i][j]=(a[i-1][j]+a[i][j-1])%mod;
			else{
				a[i][j]=0;
				}
			}
		}
	
		cout<<a[n-1][m-1];
}


Measured memory_bytes: 5120
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<int,int> P;
LL mod=1000000007;
LL LINF=1LL<<60;
const int INF=1<<30;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};


const int M_N=400000;

struct BIT{
    //1-indexed
    LL bit[M_N+1],n;
    //iまでの総和を返す
    LL sum(int i){
        LL s=0;
        while(i>0){
            s+=bit[i];
            i=i&(i-1);
        }
        return s;
    }
    //iにx加算する
    void add(int i,LL x){
        while(i<=n){
            bit[i]+=x;
            i+=i&-i;
        }
    }

};

int main(){
    int n;cin >> n;
    vector<int> a(n);
    vector<int> b(n+1,0);
    BIT bit;
    bit.n = n+1;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        b[a[i]]++;
    }
    vector<int> c;
    for (int i = 0; i < n+1; i++) {
        if(b[i]>0){
            bit.add(b[i],1);
            int t = b[i];
            while(t--) c.pb(b[i]);
        }
    }
    sort(ALL(c));
    for (int k = 1; k <= n; k++) {
        int l=0,r=n/k+1;
        while(abs(r-l)>1){
            int m = (r + l) / 2;
            int sum = m*(bit.sum(n) - bit.sum(m));
            sum += upper_bound(ALL(c),m) - c.begin();
            if(sum >= k * m) l = m;
            else r = m;
        }
        cout << l << endl;
    }
    return 0;
}



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

int main() {
  int N; cin >>N;
  vector<int> T(N);
  rep(i,0,N) cin >>T[i];
  vector<int> Copy(T.size());
  int M; cin >>M;
  rep(i,0,M) {
    int P,X; cin >>P >>X;
    copy(T.begin(),T.end(),Copy.begin());
    Copy[P-1]=X;
    int sum=accumulate(Copy.begin(),Copy.end(),0);
    cout <<sum <<endl;
  }
  return 0;
}


Measured memory_bytes: 256
from itertools import combinations
N,K = map(int,input().split())
A = list(map(int,input().split()))
cmin = 10**12
for x in combinations(range(1,N),K-1):
    C = A[:]
    B = [0]
    B += x
    B = sorted(B)
    cnt = 0
    for i in range(1,K):
        j0 = B[i-1]
        j1 = B[i]
        h = 0
        for j in range(j0,j1):
            h = max(h,C[j])
        if C[j1]<=h:
            cnt += h+1-C[j1]
            C[j1] = h+1
    cmin = min(cmin,cnt)
print(cmin)

Measured memory_bytes: 41328
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <numeric>
#include <cmath>
#include <iomanip> //cout << fixed << setprecision(15) << << endl;
#include <cassert>
//#include "atcoder/all"

using namespace std;
//using namespace atcoder;

typedef long long ll;

#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define P pair<int,int>

int mx8[] = {0,0,1,-1,-1,1,-1,1};
int my8[] = {-1,1,0,0,-1,-1,1,1};
int mx4[] = {1,-1,0,0};
int my4[] = {0,0,-1,1};

const int MOD = 1000000007;

int main() {
    ios::sync_with_stdio(false);

    string s; cin >> s;
    int n = s.size();
    int score = 0;

    for(int i = 0; i < n; i+=2)
    {
        if(s[i] == 'p') score--;
    }
    for(int i = 1; i < n; i+=2)
    {
        if(s[i] == 'g') score++;
    }

    cout << score << endl;
}

Measured memory_bytes: 3776
import sys
S=input()

def allbitCalc(N):
    allbit = []
    for i in range(2**N):
        bit = [0] * N
        for j in range(N):
            if (i >> j) & 1:
                bit[j] = 1
        allbit.append(bit)
    return allbit

def split(S,bit):
    n=len(S)
    terms=[]
    cnt=1;s=int(S[n-1])
    for i,b in enumerate(bit):
        if b==0:
            s+=int(S[n-i-2])*10**cnt
            cnt+=1
        else:
            terms.append(s)
            s=0;cnt=0
            s+=int(S[n-i-2])*10**cnt
            cnt+=1

    terms.append(s)
    return(sum(terms))
        
summ=0
allb=allbitCalc(int(len(S))-1)
for ab in allb:
    tmp=split(S,ab)
    summ+=tmp

print(summ)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
using lint = long long int;
 lint digit(lint);

int main(){

    int a[3][3];
    for(int i = 0; i < 3; ++i){
        for(int j = 0; j < 3; ++j){

            cin >> a[i][j];

        }
    } 

    int n; 
    
    cin >> n;

    for(int i = 0; i < n; ++i){
        int b;
        cin >> b;
        for(int j = 0; j < 3; ++j){
            for(int k = 0;k  < 3; ++k){
                if(a[j][k] == b)a[j][k] = 0;
            }
        } 
    }

    if(a[0][0] == a[0][1] && a[0][1] == a[0][2]
    || a[1][0] == a[1][1] && a[1][1] == a[1][2]
    || a[2][0] == a[2][1] && a[2][1] == a[2][2]
    || a[0][0] == a[1][0] && a[1][0] == a[2][0]
    || a[0][1] == a[1][1] && a[1][1] == a[2][1]
    || a[0][2] == a[1][2] && a[1][2] == a[2][2]
    || a[0][0] == a[1][1] && a[1][1] == a[2][2]
    || a[0][2] == a[1][1] && a[1][1] == a[0][2]
    )cout << "Yes" << endl;
    else cout << "No" << endl;


}
lint digit(lint num){
    lint dig = 0;
    while(num){
        num /= 10;
        ++dig;
    }
    return dig;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e9
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;

signed main(){
    string s;
    int k;
    cin >> s >> k;
    int cnt=k;
    for (int i = 0; i < s.size(); i++)
    {
        if(s[i]=='a') continue;
        if(cnt==0) break;
        if(26-(s[i]-'a')<=cnt){
            cnt-=26-(s[i]-'a');
            s[i]='a';
            //cerr<<(int)(s[i]-'a')<<"a"<<endl;
        }
        //cerr<<cnt<<endl;
    }
    
    if(cnt>0)
    s[s.size()-1]=(s[s.size()-1]-'a'+cnt)%26+'a';
    
    cout<<s<<endl;
    return 0;
}

Measured memory_bytes: 512
use std::io::*;

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let n: usize = itr.next().unwrap().parse().unwrap();
    let a: Vec<usize> = (0..n - 1)
        .map(|_| itr.next().unwrap().parse().unwrap())
        .collect();

    let mut ans = vec![0usize; 200020];
    for i in 0..n - 1 {
        ans[a[i] - 1] += 1;
    }
    let mut out = Vec::new();
    for i in 0..n {
        writeln!(out, "{}", ans[i]).ok();
    }
    stdout().write_all(&out).unwrap();
}


Measured memory_bytes: 6820
#include <stdio.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int n, m, sx, gx;
char f[32][16];

int simulate(int h, int x) {
    while (h < m) {
        if (x > 0 && f[h][x-1] == '1') x--;
        else if (x < n-1 && f[h][x] == '1') x++;
        h++;
    }
    return x;
}

void solve() {
    if (simulate(0, sx) == gx) {
        printf("%d\n", 0);
        return ;
    }
    int x = sx;
    rep (i, m) {
        if ((x == 0 || f[i][x-1] != '1') && (x == n-1 || f[i][x] != '1')) {
            if (x-1 >= 0 && (x-1 == 0 || f[i][x-2] != '1')) {
                if (simulate(i+1, x-1) == gx) {
                    printf("%d %d\n", i+1, x);
                    return ;
                }
            }
            if (x+1 < n && (x+1 == n-1 || f[i][x+1] != '1')) {
                if (simulate(i+1, x+1) == gx) {
                    printf("%d %d\n", i+1, x+1);
                    return ;
                }
            }
        }
        if (x > 0 && f[i][x-1] == '1') x--;
        else if (x < n-1 && f[i][x] == '1') x++;
    }
    printf("%d\n", 1);
}

int main() {
    for (;;) {
        scanf("%d", &n);
        if (n == 0) return 0;
        scanf("%d%d%d", &sx, &gx, &m);
        sx--, gx--;
        rep (i, m) scanf("%s", f[i]);
        solve();
    }
    return 0;
}

Measured memory_bytes: 0
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 2e5 + 10;
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	LL n;
	cin >> n;
	LL ans = n / 11;
	if (ans * 11 >= n) cout << ans * 2 << endl, exit(0);
	if (ans * 11 + 6 >= n) cout << ans * 2 + 1 << endl, exit(0);
	cout << ans * 2 + 2 << endl;
	return 0;
}

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

int main() {
  string s,t;
  cin >> s >> t;
  int n = s.length();
  int m = t.length();
  sort(s.begin(),s.end());
  sort(t.rbegin(),t.rend());
  bool ok = false;
  rep(i,min(n,m)) {
    if(s[i] < t[i]) {
      ok = true;
      break;
    } else if(s[i] > t[i]) {
      break;
    }
    if (i == min(n, m)-1 && n < m) {
      ok = true;
      break;
    }
  }

  if(ok) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3640
/**
*    author:  Taichicchi
*    created: 09.09.2020 20:16:19
**/

#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
typedef long long ll;

int main() {
    ll X, Y;
    cin >>X >> Y;

    string ans = "No";

    if(Y % 2 == 0){
        for(int i = 0; i <= X ; ++i) {
            if(i * 4 + (X - i) * 2 == Y){
                ans = "Yes";
                break;
            }
        }
    }

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

Measured memory_bytes: 3632
module.exports=function(t){var e={};function n(r){if(e[r])return e[r].exports;var i=e[r]={i:r,l:!1,exports:{}};return t[r].call(i.exports,i,i.exports,n),i.l=!0,i.exports}return n.m=t,n.c=e,n.d=function(t,e,r){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:r})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var i in t)n.d(r,i,function(e){return t[e]}.bind(null,i));return r},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=0)}([function(t,e,n){"use strict";var r=n(1);n(2)(r.readFileSync("/dev/stdin","utf8"))},function(t,e){t.exports=require("fs")},function(t,e,n){"use strict";var r=n(3),i=n(5);t.exports=function(t){var e=new r(t);i(e)}},function(t,e,n){"use strict";var r=n(4);t.exports=class{constructor(t){var e=t.trim().split(/\s+/g);this.inp=new r(e)}inr(){return this.inp.deq()}in(){return parseInt(this.inp.deq(),10)}fin(){this.inp.clear()}}},function(t,e,n){"use strict";t.exports=class{constructor(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];this.size=t.length,this.items=t,this.ind=0}enq(t){this.size+=1,this.items.push(t)}deq(){var t=this.items[this.ind];return this.size-=1,this.ind+=1,t}clear(){this.items=[],this.size=0,this.ind=0}}},function(t,e,n){"use strict";t.exports=function(t){var e=t.inr(),n="";"A"==e&&(n+="T"),"T"==e&&(n+="A"),"G"==e&&(n+="C"),"C"==e&&(n+="G"),console.log(n)}}]);

Measured memory_bytes: 20424
#include <iostream>
using namespace std;
int main(void){
    
    int x,y;
    
    while(1){
        cin >> x >> y;
        if(x==0 && y==0)break;
        if(x<=y){
        cout << x << " " << y << endl;
    }else {
        cout << y << " " << x <<endl;
    }
}


 return 0;   
}


Measured memory_bytes: 2976
import sys
input = sys.stdin.readline
import random
import time
import copy
from operator import itemgetter
time0=time.time()

D=int(input())
C=[0]+list(map(int,input().split()))
S=[0]+[[0]+list(map(int,input().split())) for i in range(D)]


CI=sorted([(v,i) for i,v in enumerate(C)],key=itemgetter(0),reverse=True)
CHO=[i for v,i in CI[:4]]

CHOICES=[[0]]
for i in range(1,D+1):
    SI=sorted([(v,i) for i,v in enumerate(S[i])],key=itemgetter(0),reverse=True)
    CHOICES.append([i for v,i in SI[:4]])
    
ANS=0
T=[0]
LAST=[0]*27
for day in range(1,D+1):
    SCORE=[-1<<30]*27
    for j in range(1,27):
        SC=0
        SC+=S[day][j]

        for k in range(1,27):
            if j==k:
                continue
            SC-=C[k]*(day-LAST[k])
        SCORE[j]=SC

    choose=SCORE.index(max(SCORE))
    T.append(choose)
    LAST[choose]=day

ANS=0
LAST=[[0]*27 for i in range(D+1)]
for day in range(1,D+1):
    for j in range(1,27):
        LAST[day][j]=LAST[day-1][j]
    t=T[day]
    ANS+=S[day][t]
    LAST[day][t]=day

    for j in range(1,27):
        ANS-=C[j]*(day-LAST[day][j])

MAX=ANS
MAXT=copy.deepcopy(T)
d=0
after_t=0

while time.time()-time0<1.8:
    BT=copy.deepcopy(T)
    BLAST=copy.deepcopy(LAST)
    BANS=ANS
    
    d=random.randint(1,D)
    after_t=random.choice(CHO+CHOICES[d])

    before_t=T[d]

    ANS+=S[d][after_t]-S[d][before_t]

    T[d]=after_t

    memolast=[]

    for day in range(d,D+1):
        if T[day]!=before_t:
            ANS+=C[before_t]*(day-LAST[day][before_t])
            memolast.append((day,before_t,LAST[day][before_t]))
            LAST[day][before_t]=LAST[day-1][before_t]
            ANS-=C[before_t]*(day-LAST[day][before_t])
        else:
            break

    ANS+=C[after_t]*(d-LAST[d][after_t])
    memolast.append((d,after_t,LAST[d][after_t]))
    LAST[d][after_t]=d

    for day in range(d+1,D+1):    
        if T[day]!=after_t:
            ANS+=C[after_t]*(day-LAST[day][after_t])
            memolast.append((day,after_t,LAST[day][after_t]))
            LAST[day][after_t]=LAST[day-1][after_t]
            ANS-=C[after_t]*(day-LAST[day][after_t])

    if ANS*10000<MAX*9998:
        T=BT
        ANS=BANS
        for dd,tt,ll in memolast:
            LAST[dd][tt]=ll
    elif ANS>MAX:
        MAX=ANS
        MAXT=copy.deepcopy(T)

print(*MAXT[1:])


Measured memory_bytes: 179428
#include<string>
#include<string.h>
#include<map>
#include<set>
#include<vector>
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
int cnta,cntb,cntc;
int main()
{
    string s;
    cin>>s;
    for(int i=0;i<s.size();i++){
        if(s[i]=='a')cnta++;
        if(s[i]=='b')cntb++;
        if(s[i]=='c')cntc++;
        }
    if(cnta==1 && cntb==1 && cntc==1)cout<<"Yes";
    else cout<<"No";
system("pause");
return 0;
}

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



class Point {
public:
  double x;
  double y;
  double z;
  Point(double x, double y, double z) : x(x), y(y), z(z) {}
  Point() {}
};

typedef Point Vector;

int n;
Point s[500];
bool looked[500];

double dot(Vector &a, Vector &b) {
  return a.x*b.x + a.y*b.y + a.z*b.z;
}

double norm(Vector &a) {
  return pow(a.x, 2.0)+pow(a.y, 2.0)+pow(a.z, 2.0);
}

double dist(Vector &a) {
  return sqrt(norm(a));
}

void solve(Vector &t, double &rad) {
  for(int i = 0; i < n; ++i) {
    if(looked[i]) continue;
    double ds = dist(s[i]);
    double cos1 = dot(t, s[i])/(dist(t)*ds);
    double the = acos(cos1);
    if(the > M_PI/2.0) continue;
    if(rad == M_PI/2.0) {
      looked[i] = true;
      continue;
    }
    double d = ds*cos1;
    double R = abs(d*tan(rad));
    double r = abs(ds*sin(the));
    if(r <= R) {
      looked[i] = true;
    }
  }
}

main() {
  while((cin >> n) && n) {
    int cnt = 0;
    int m;
    double rad;
    Vector t;
    for(int i = 0; i < n; ++i) cin >> s[i].x >> s[i].y >> s[i].z;
    fill(looked, looked+n, false);
    cin >> m;
    for(int i = 0; i < m; ++i) {
      cin >> t.x >> t.y >> t.z >> rad;
      solve(t, rad);
    }

    for(int i = 0; i < n; ++i) cnt += (looked[i]) ? 1 : 0;

    cout << cnt << endl;
  }
}

Measured memory_bytes: 996
#include<iostream>
#include<fstream>
#include<sstream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<string>
#include<cmath>
#include<cstdio>
#include<cassert>
using namespace std;

#define REP(i,m,n) for(int i=(m); i<(int)(n); i++)
#define RREP(i,m,n) for(int i=(int)(n-1); i>=m; i--)
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) RREP(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aut(r,v) __typeof(v) r = (v)
#define each(it,o) for(aut(it,(o).begin()); it!=(o).end(); ++it)
#define reach(it,o) for(aut(it,(o).rbegin()); it!=(o).rend(); ++it)
#define fi first
#define se second
#define debug(...) {cerr<<"[L"<<__LINE__<<"] "; _debug(__VA_ARGS__);}

template<typename T1, typename T2> ostream& operator<<(ostream& o, const pair<T1, T2>& p)
{return o<<"("<<p.first<<", "<<p.second<<")";}
template<typename T>string join(const vector<T>&v, string del=", ")
{stringstream s;rep(i,v.size())s<<del<<v[i];return s.str().substr(del.size());}
template<typename T>ostream& operator<<(ostream& o, const vector<T>&v)
{if(v.size())o<<"["<<join(v)<<"]";return o;}
template<typename T>ostream& operator<<(ostream& o, const vector<vector<T> >&vv)
{int l=vv.size();if(l){o<<endl;rep(i,l){o<<(i==0?"[ ":",\n  ")<<vv[i]<<(i==l-1?" ]":"");}}return o;}
template<typename T>ostream& operator<<(ostream& o, const set<T>& st)
{vector<T> v(st.begin(),st.end());o<<"{ "<<join(v)<<" }";return o;}
template<typename T1, typename T2>ostream& operator<<(ostream& o, const map<T1, T2>& m)
{each(p,m){o<<(p==m.begin()?"{ ":",\n  ")<<*p<<(p==--m.end()?" }":"");}return o;}
inline void _debug(){cerr<<endl;}
template<class First, class... Rest>
void _debug(const First& first, const Rest&... rest){cerr<<first<<" ";_debug(rest...);}

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

const double PI = (1*acos(0.0));
const double INF = 0x3f3f3f3f;
const double INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;
const double mod = 1e9 + 7;

inline void finput(string filename) {
    freopen(filename.c_str(), "r", stdin);
}

int n, m;
string str;
int S[100010];

int main(){
    ios_base::sync_with_stdio(0);
    // finput("./input");

    cin >> n >> m;
    cin >> str;
    S[0] = 0;
    rep(i,n+1) S[i+1] = S[i] + (str[i] == '0' ? 1 : 0);

    bool reachable = true;
    vi d;
    int p = n+1;
    while(p > 1){
        int ok = p;
        int ng = max(p - m - 1, 0);
        while(ok - ng > 1){
            int mid = (ok + ng) / 2;
            if(S[mid] - S[ng] > 0) ok = mid;
            else ng = mid;
        }
        if(ok == p){
            reachable = false;
            break;
        }
        d.push_back(p - ok);
        p = ok;
    }

    reverse(all(d));
    if(reachable) cout << join(d, " ") << endl;
    else cout << "-1" << endl;
    return 0;
}

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

int main()
{
    char a,b;
    cin >> a >> b;
    if(a=='H'){
        if(b=='H'){
            cout << 'H';
        }else{
            cout << 'D';
        }
    }else{
        if(b=='H'){
            cout << 'D';
        }else{
            cout << 'H';
        }
    }
    
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        // 入力
        long[] tmp = Console.ReadLine().Split().Select(long.Parse).ToArray();

        long a = tmp[0];
        long p = tmp[1];
        long ans = (a*3 + p)/2;

        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 11476
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		// 問題数
		int N = Integer.parseInt(scn.next());
		// 問題を解くのにかかる時間
		int[] T = new int[N];
		int sum = 0;
		for (int i = 0; i < N; i++) {
			T[i] = Integer.parseInt(scn.next());
			sum += T[i];
		}
		// ドリンクの種類数
		int M = Integer.parseInt(scn.next());
		for (int i = 0; i < M; i++) {
			// P番目
			int P = Integer.parseInt(scn.next());
			// X秒になる
			int X = Integer.parseInt(scn.next());
			System.out.println(sum - T[P - 1] + X);
		}
	}
}

Measured memory_bytes: 22996
#include<stdio.h>
main(void){
	int a,b;
	char op;
	while(1){
		scanf("%d %c %d",&a,&op,&b);
		if(op=='+'){
			printf("%d\n",a+b);
		}else if(op=='-'){
			printf("%d\n",a-b);
		}else if(op=='*'){
			printf("%d\n",a*b);
		}else if(op=='/'){
			printf("%d\n",a/b);
		}else if(op=='?'){
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 600
def solve():
    N, M = map(int, input().split())
    A = [list(map(int, input().split())) for _ in range(M)]

    ans = 10000
    for i in range(0, 1000):
        s = str(i)
        c = 0
        if len(s) != N: continue
        for a, b in A:
            
            if s[a-1] == str(b):
                c += 1
        if c == M:
            ans = min(ans, i)
    
    if ans == 10000:
        ans = -1
        
    return ans

print(solve())

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  string s; cin >> s;
  long long sum=0;
  for(char x:s) sum += x-'0';
  if(sum%9==0) cout << "Yes\n";
  else cout << "No\n";
  return 0;
}



Measured memory_bytes: 3732
#include <iostream>
#include <cmath>
using namespace std;
#define N_MAX 100000
#define ANS_DIV 998244353

int main()
{
    int nums[N_MAX+1] = {};
    int n;
    int maxNum = 0;
    cin >> n;
    for(int i = 0; i < n; ++i)
    {
        int t;
        cin >> t;
        if(i == 0
        && t != 0)
        {
            cout << 0 << endl;
            return 0;
        }
        ++nums[t];
        maxNum = max(t,maxNum);
    }

    if(nums[0] != 1)
    {
        cout << 0 << endl;
        return 0;
    }

    long long int ans = 1;
    for(int i = 1; i <= maxNum; ++i)
    {
        if(nums[i] == 0)
        {
            cout << 0 << endl;
            return 0;
        }
        long long int t = 1;
        for(int j = 0; j < nums[i]; ++j)
        {
            t = t * nums[i-1] % ANS_DIV;
        }
        ans = ans * t % ANS_DIV;
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt(); 
    int[] d = new int[N];  
    for (int i=0; i < N ;i++) {
      d[i] =  sc.nextInt();
    }
    Arrays.sort(d);
    if(d[N/2] == d[N/2-1]){
      System.out.println(0);
    }else{
      System.out.println(d[N/2] - d[N/2-1] );
    }

  }
}



Measured memory_bytes: 49032