akhauriyash/Code-Regression huggingface dataset:
#include <set>
#include <array>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <vector>
#include <tuple>
#include <string>
#include <math.h>
#include <time.h>
#include <bitset>
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <limits>
#include <climits>
#include <numeric>
#include <functional>

#define lnd '\n'
// #define reverse(i, n) for(ll i = n-1; i >= 0; --i)
#define from(i, n) for (ll i = 0; i < n; ++i)
#define loop(i, n) for(ll i = 0; i < n; i++)
#define REPN(i, n) for (ll i = 1; i <= n; ++i)
#define ALL(s) (s).begin(), (s).end()
#define rALL(s) (s).rbegin(), (s).rend()
#define sz(s) (int)(s).size()
#define mk make_pair
#define pb push_back
#define sqr(s) ((s) * (s))

using namespace std;

typedef long long ll;
typedef long long int lli;
typedef long double ld;
typedef unsigned long long ull;
typedef unsigned int ui;

template <class T>
T GCD (T a, T b) {
  if(a == 0) return b;
  return GCD(b%a, a);
}

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

template <class T>
T modpow(T x, T p){
    T res = 1;
    while(p > 0){
        if(p&1) res *= x;
        x *= x;
        p /= 2;
    }
    return res;
}

template <class T>
T modpow(T x, T p, ll mod){
    T res = 1;
    while(p > 0){
        if(p&1) res = (res*x)%mod;
        x = (x*x)%mod;
        p /= 2;
    }
    return res%mod;
}

template <class T>
void print(T a[], ll n){
    for (ll i = 0; i < n; i++) std::cout << a[i] << ' ';
    cout << endl;
}

template<class T>
void printc(T c){
    for(auto const& v: c) std::cout << v << ' ';
    cout << endl;
}

struct HASH{
  size_t operator()(const pair<long,long>&x)const{
    return hash<long long>()(((long long)x.first)^(((long long)x.second)<<32));
  }
};

bool pair_sort(const pair<int, int> &p1, const pair<int,int> &p2){
    if(p1.first != p2.first) return p1.first < p2.first;
    else return p1.second < p2.second;
}

const int INF = std::numeric_limits<int>::max();
const ll M_INF = std::numeric_limits<ll>::min();
const ll LL_INF = std::numeric_limits<ll>::max();

void solution();
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solution();
    return 0;
}

ll result[200005] = {0};
void fact(ll n) {
   if (n >= 0) {
      result[0] = 1;
      for (ll i = 1; i <= n; ++i) {
         result[i] = i * result[i - 1];
      }
   }
}

void dfs(ll n, ll m, ll i, vector<ll> &v){
  if(i == n){
  }else{
    for(int k = 1; k <= m; k++){
      v.push_back(k);
      dfs(n, m, i+1, v);
      v.pop_back();
    }
  
  }
}

void solution(){
  ll x;
  cin >> x;
  map<ll, ll> a, b;
  for(int i = 0; i <= 100000; i++){
    a[pow(i, 5)]= i;
    b[pow(-i, 5)] = -i;
  }

  // for(auto it: a) cout << it.first << ":" << it.second << endl;
  for(auto it: a){
    for(auto it2: b){
      ll tmp = it.first - it2.first;
      if(tmp == x){
        cout << it.second << " " << it2.second << endl;
        return;
      }

      tmp = it.first + it2.first;
      if(tmp == x){
        cout << it.second << " " << -1*it2.second << endl;
        return;
      }
    }
  }
}     



Measured memory_bytes: 4500
mod=10**9+7
 
def framod(n, a=1):
  for i in range(1,n+1):
    a=a * i % mod
  return a
  
def power(n, r):
  if r == 0: return 1
  if r%2 == 0:
    return power(n*n % mod, r//2) % mod
  if r%2 == 1:
    return n * power(n, r-1) % mod
  
def comb(n, k):
  a=framod(n)
  b=framod(k)
  c=framod(n-k)
  return (a * power(b, mod-2) * power(c, mod-2)) % mod
  
N, K=map(int, input().split())
for i in range(1, K+1):
  if N-K+1>=i and K-1>=i-1:
    print((comb(N-K+1, i)*comb(K-1, i-1))%mod)
  else:
    print(0)

Measured memory_bytes: 51052
import scala.io.{StdIn => in}

object Main extends App {
  val out = new java.io.PrintWriter(System.out)
  val Array(n, m) = in.readLine.split(" ").map(_.toInt)

  case class id(i: Int, p: Int, x: Int)

  val city = Iterator.continually(in.readLine)
    .take(m)
    .map(_.split(" "))
    .zipWithIndex
    .map(a => new id(a._2.toInt, a._1(0).toInt, a._1(1).toInt))
    .toArray

  val sortedCity = city
    .sortBy(c => c.x.toInt)
    .sortBy(c => c.p.toInt)
    .scanLeft((0, 0, 0)) { (acc, city) =>
        if(acc._2 == city.p) (city.i, acc._2, acc._3 + 1)
        else (city.i, city.p, 1)
      }
    .tail
    .sortBy(_._1)

  sortedCity.foreach { id =>
        val p = Array.fill(6-rec(0, id._2))('0').mkString
        val x = Array.fill(6-rec(0, id._3))('0').mkString
        out.println(p + id._2.toString + x + id._3.toString)
      }
  out.flush

  def rec(cnt:Int, v: Int):Int = {
    if(v == 0) cnt
    else rec(cnt+1, v / 10)
  }
}

Measured memory_bytes: 127152
#include<bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define taskname "A"
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
const int maxn = 1e5 + 5;
const int mod = 1e9 + 7;

int n , m , a , b;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    if(fopen(taskname".INP" , "r"))
        freopen(taskname".INP","r",stdin),
        freopen(taskname".OUT","w",stdout);
    cin >> n >> m;
    ll res = 0 , res1 = 0 , sum = 0 , sum1 = 0;
    for(int i = 1 ; i <= n ; ++i){
        cin >> a;
        res += (ll)a * (i - 1) - sum;
        sum += a;
    }
    for(int i = 1 ; i <= m ; ++i){
        cin >> b;
        res1 += (ll)b * (i - 1) - sum1;
        sum1 += b;
    }
    cout << (res % mod) * (res1 % mod) % mod;
}


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

// int gcd(int x,int y,int z){
//     for(int i=min(min(x,y),z);i>0;i=i-1){
//         int n=x%i;
//         int m=y%i;
//         int l=z%i;

//         if((n==0&&m==0)&&l==0){
//             return i;
//         }
//     }
//     return 1;
// }




int main(){
    int K;
    cin >> K;
    int sum=0;

    for(int a=1;a<=K;a++){
        for(int b=1;b<=K;b++){
            for(int c=1;c<=K;c++){
                sum+=gcd(gcd(a,b),c);
            }
        }
    }

    cout << sum << endl;
}

Measured memory_bytes: 3644
#include <stdio.h>
#define N 1000

int main(void){
    char num[N];
    int i,sum;
    
    for(;;){
        scanf("%s",&num);
        if(num[0]=='0') break;
        sum=0;
        
        for(i=0;num[i]!='\0';i++){
            sum+=num[i]-'0';
        }
        printf("%d\n",sum);
    }
    return 0;
}


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

typedef long long ll;
const ll mod = 1e9+7;

int main(){
    ll n, k;
    cin >> n >> k;
    ll ans = 0;
    auto f = [](ll x)->ll{
        return x*(x+1)/2%mod;
    };
    for(ll i = n+1; i >= k; i--){
        ans += f(n+1)-f(n+1-i) - f(i)+1+mod+mod;
        ans %= mod;
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
    int n, k, r, s, p;
    string t;
    cin >> n >> k >> r >> s >> p >> t;

    int ans = 0;
    for(int i=0; i<k; i++){
        int j = i;
        int count = 0;
        while(j < n){
            if(j - k >= 0 && t[j] == t[j-k]) count += 1;
            else count = 0;

            if(count % 2 == 0){
                if(t[j] == 'r') ans += p;
                if(t[j] == 's') ans += r;
                if(t[j] == 'p') ans += s;
            }
            j += k;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#include<list>
#include<unordered_map>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
// #define int ll
using namespace std;
const int INF (1 << 30);
const ll LLINF (1LL << 55LL);
const int MOD = 1000000007;
const int MAX = 510000;
const double pi = acos(-1);
const double eps = 1e-9;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll n,p[100010],a[100010],b[100010];
    ll A,B;
    cin>>n;
    rep(i,n){
        cin>>p[i];
        p[i]--;
    }
    a[p[0]]=1,b[p[0]]=1;
    rep2(i,1,n){
        a[p[i]]=20000*(p[i]-p[i-1])+a[p[i-1]];
        b[p[i]]=i+2-a[p[i]];
    }
    if(a[0]<=0){
        A=1-a[0];
        rep(i,n){
            a[i]+=A;
        }
    }
    if(b[n-1]<=0){
        B=1-b[n-1];
        rep(i,n){
            b[i]+=B;
        }
    }
    rep(i,n){
        cout<<a[i]<<" ";
    }
    cout<<endl;
    rep(i,n){
        cout<<b[i]<<" ";
    }
    cout<<endl;/*
    rep(i,n){
        cout<<a[p[i]]+b[p[i]]<<" "; 
    }
    cout<<endl;*/
    return 0;
}

Measured memory_bytes: 2816
def main():
	n = int(input())
	arr = []
	dictionary = {}
	cnt = 0
	for _ in range(n):
		arr.append(str(input()))
	for i in range(n):
		l = list(arr[i])
		l.sort()
		arr[i] = ''.join(str(l))
	for i in range(n):
		if arr[i] in dictionary:
			dictionary[arr[i]]+=1
			cnt+=dictionary[arr[i]]
		else:
			dictionary[arr[i]]=0
	print(cnt)
	



main()

Measured memory_bytes: 92632
// C++ 14
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <algorithm>
#include <queue>
#include <stack>

#define ll long long
#define loop(x, start, end) for(int x = start; x < end; x++)
#define loopdown(x, start, end) for(int x = start; x > end; x--)

using namespace std;


int main(void) {
  int n, v, c, l;
  cin >> n;

  int mat[n][n];

  loop(i,0,n) {
    loop(j,0,n) {
      mat[i][j] = 0;
    }
  }

  loop(i, 0, n) {
    cin >> v >> c;
    loop(j,0,c) {
      cin >> l;
      mat[v-1][l-1] = 1;
    }
  }

  loop(i,0,n) {
    loop(j,0,n) {
      if (j) cout << " ";
      cout << mat[i][j];
    }
    cout << endl;
  }
}



Measured memory_bytes: 3088
#include <stdio.h>

int main (){
    long long int n;
    scanf ("%lld", &n);
    long long int arr[n];
    for (long long int i = 0; i < n; i++){
        scanf ("%lld", &arr[i]);
    }
    
    for (long long int i = 0; i < n; i++){
        if (arr[i] == 0){
            printf("0");
            return 0;
        }
    }
    
    long long int sum = 1;
    for (long long int i = 0; i < n; i++){
        if (arr[i] <= 1000000000000000000 / sum){
            sum *= arr[i];
        }
        else {    
        printf ("-1");
        return 0;
        }
    }
    
    printf ("%lld", sum);
    return 0;
}


Measured memory_bytes: 2508
fun main(args: Array<String>){
    val MOD = 1000000007L
    val dp = Array<LongArray>(100005) { LongArray(13) }
    val s = next().toCharArray()
    var n = s.count()
    dp[0][0] = 1
    for (i in 0 until n) {
        val c = if (s[i] == '?') -1 else s[i] - '0'
        for (j in 0 until 10) {
            if (c != -1 && c != j) continue
            for (ki in 0 until 13) {
                dp[i + 1][(ki * 10 + j) % 13] += dp[i][ki]
            }
        }
        for (j in 0 until 13) dp[i + 1][j] %= MOD
    }
    val res = dp[n][5]
    println(res)
}
fun next() = readLine()!!


Measured memory_bytes: 71992
class Sum2D:
    def __init__(self,h,w):
        self.height=h
        self.width=w
        self.data=[[0]*(self.width+1) for _ in range(self.height+1)]
    def add(self,x,y,v):
        self.data[x][y]+=v
    def build(self):
        for x in range(self.height):
            for y in range(self.width):
                self.data[x+1][y+1]+=self.data[x+1][y]
                self.data[x+1][y+1]+=self.data[x][y+1]
                self.data[x+1][y+1]-=self.data[x][y]
    def query(self,p,q):
        return self.data[q][q]+self.data[p][p]-self.data[p][q]-self.data[q][p]

import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**9)
n,m,q=map(int,input().split())
S=Sum2D(n,n)
for _ in range(m):
    l,r=map(int,input().split())
    S.add(l,r,1)
S.build()
for _ in range(q):
    l,r=map(int,input().split())
    print(S.query(l-1,r))

Measured memory_bytes: 13576
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
signed main(){
  int N; cin>>N;
  cout<<(N-2)*180<<endl;
  }


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <sstream>
#include <math.h>
#include <algorithm>
#include <queue>
using namespace std;
//for (int i = 0; i < N; i++){}
//for (int i = 0; i < N; i++){}

int main() {
    int A, B;
    cin >> A >> B;

    int sums = 0;
    if(A>B){
        sums += A;
        A--;
    }else{
        sums += B;
        B--;
    }
    if(A>B){
        sums += A;
        A--;
    }else{
        sums += B;
        B--;
    }
    cout << sums << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int cnt=0,n,s;
void func(int sum,int depth,int x){
    int i;
    if(depth>n){
        if(sum==s){
            cnt++;
        }
        return;
    }
    for(i = x;i < 10;i++){
        if(sum+i>s)return;

        func(sum+i,depth+1,i+1);
    }
}
int main(void){
    while(scanf("%d %d",&n,&s),n || s){
        cnt = 0;
        func(0,1,0);
        printf("%d\n",cnt);
    }
    return 0;
}

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

int main(){
  double a,b,h,m,ans=0;
  cin>>a>>b>>h>>m;
  double z,x,c;
  z=h*2*3.141592653589793/12+m*2*3.141592653589793/720;
  x=m*2*3.141592653589793/60;
  c=z-x;
  if(c<3.141592653589793)c=2*3.141592653589793-c;
  c=cos(c);
  ans=sqrt(a*a+b*b-2*a*b*c);
  cout <<setprecision(10)<<ans;
}

Measured memory_bytes: 4228
import math

n,d = map(int,input().split())
x = []
for i in range(n):
  p = list(map(int,input().split()))
  x.append(p)

dis = []
ans = []

for i in range(n):
  r = math.sqrt(x[i][0]**2 + x[i][1]**2)
  dis.append(r)
  if dis[i] <= d:
    ans.append(dis[i])
    
print(len(ans))

Measured memory_bytes: 54508
use proconio::input;
use proconio::marker::{Bytes, Chars, Isize1, Usize1};

fn main() {
    input! {
        x: usize
    }

    let ans = {
        let mut ans = 0;
        for i in 0..=7 {
            if 400 + 200*i <= x && x < 600 + 200*i {
                ans = 8-i;
            }
        }
        ans
    };

    println!("{}",ans)
}


Measured memory_bytes: 2128
#include <stdio.h>

int main(void)
{
	int n, mk, rk;
	int i, j;
	int ch[4][13];

	for (i = 0; i < 4; i++)
		for (j =0; j < 13; j++)
			ch[i][j] = 0;

	scanf("%d", &n);

	for (i = 0; i < n * 2; i++)
	{
		mk = getchar();
		scanf("%d", &rk);

		if (mk == 83) 
			ch[0][rk - 1] = 1;
		else if (mk == 72)
			ch[1][rk - 1] = 1;
		else if (mk == 67)
			ch[2][rk - 1] = 1;
		else if (mk == 68)
			ch[3][rk - 1] = 1;
	}

	for (i = 0; i < 4; i++)
		for (j = 0; j < 13; j++)
			if (ch[i][j] == 0)
			{
				if (i == 0)	
					printf("S %d\n", j + 1);
				else if (i == 1)
					printf("H %d\n", j + 1);		
				else if (i == 2)
					printf("C %d\n", j + 1);
				else if (i == 3)
					printf("D %d\n", j + 1);
			}
	
	return 0;
}

Measured memory_bytes: 600
package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	nVerts := scanInt(sc)
	graph := make([][]int, nVerts+1)

	for i := 0; i < nVerts; i++ {
		u := scanInt(sc)
		nDegrees := scanInt(sc)

		graph[u] = make([]int, nDegrees)
		for d := 0; d < nDegrees; d++ {
			graph[u][d] = scanInt(sc)
		}
	}

	starts := make([]int, nVerts+1)
	ends := make([]int, nVerts+1)
	time := 1

	var dfs func(u int)
	dfs = func(u int) {
		if starts[u] > 0 {
			return
		}

		starts[u] = time
		time += 1

		for _, v := range graph[u] {
			dfs(v)
		}

		ends[u] = time
		time += 1
	}

	for i := 1; i <= nVerts; i++ {
		dfs(i)
	}

	w := bufio.NewWriter(os.Stdout)
	for i := 1; i <= nVerts; i++ {
		fmt.Fprintf(w, "%d %d %d\n", i, starts[i], ends[i])
	}
	w.Flush()
}

func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	v, _ := strconv.Atoi(sc.Text())
	return v
}



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

using namespace std;

typedef long long int li;
typedef long double ld;
typedef vector<li> vi;
typedef pair<li,li> pi;
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define B begin()
#define E end()
#define f(i,l,r) for(li i=l;i<=r;++i)
#define fr(i,l,r) for(li i=l;i>=r;--i)
#define u_map unordered_map
#define endl "\n"

li fastpow(li base,li exp,li M) 
{
    li res=1;
    while(exp>0) {
        if(exp&1)
            res=(res*base)%M;

        base=(base*base)%M;
        exp>>=1;
    }
    return res;
}

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

    li n,k;
    cin>>n>>k;

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

    vi dp(n,1e18);

    dp[0]=0;

    f(i,0,n-1)
    {
        f(j,i+1,min(i+k,n-1))
        {
            dp[j]=min(dp[j],dp[i]+abs(a[j]-a[i]));
        }
    }

    cout<<dp[n-1];

    return 0;
}

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

using namespace std;

int main(){
    int a[3];
    for(int i=0;i<3;i++)cin >> a[i];
    sort(a,a+3);
    if(a[0]==5&&a[1]==5&&a[2]==7)cout << "YES" <<endl;
    else cout << "NO" << endl;
}


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

using namespace std;

int main(){

    int N, A, B;
    cin>> N>> A>> B;
    int t[N];
    for(int i=0; i<N; i++){
        cin>> t[i];
    }

    sort(t, t+N);
    int ans=0;
    for(int T: t){
        if(!(A<=T&&T<B)) ans++;
    }

    cout<< ans<< endl;

    return 0;
}


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

using namespace std;

typedef long long ll;
typedef long double ld;

const int MX = 100 * 1000 + 7;

int a[MX];
int main()
{
#ifdef AZINO777
    freopen("in", "r", stdin);
#endif
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    ll l = 2, r = 2;
    for (int i = n - 1; i >= 0; i--) {
        ll lw = (l + a[i] - 1) / a[i] * a[i];
        if (lw > r) {
            cout << -1 << endl;
            return 0;
        }
        ll rw = r - r % a[i];
        rw += a[i] - 1;
        l = lw;
        r = rw;
    }
    cout << l << " " << r << endl;
}

Measured memory_bytes: 640
from collections import defaultdict
MOD = 10**9+7
n = int(input())
A = list(map(int, input().split()))


def factorization(n):
    retval = []
    tmp = n
    for i in range(2, int(-(-n**.5//1))+1):
        if tmp % i == 0:
            cnt = 0
            while tmp % i == 0:
                cnt += 1
                tmp //= i
            retval.append((i, cnt))
    if tmp != 1:
        retval.append((tmp, 1))
    return retval


x = defaultdict(int)
for a in A:
    for p, q in factorization(a):
        if x[p] < q:
            x[p] = q

mod_x = 1
for p, q in x.items():
    mod_x *= pow(p, q, MOD)
mod_x %= MOD

B = [mod_x*pow(a, MOD-2, MOD) % MOD for a in A]
print(sum(B) % MOD)


Measured memory_bytes: 4852
/*
*/
#include<iostream>
using namespace std;

int main()
{
  // 標準入力
  string S,T;
  cin >> S >> T;
  int A, B;
  cin >> A >> B;
  string U;
  cin >> U;

  if (U == S) {
    A--;
  }
  else {
    B--;
  }
  
  cout << A << " " << B;

  return 0;

}

Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 8)
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, M = map(int, readline().split())
dst = [[] for _ in range(N)]
src = [[] for _ in range(N)]
for i in range(M):
    x, y = [int(z) - 1 for z in readline().split()]
    dst[x].append(y)
    src[y].append(x)


def solve():
    nodes = []
    nindex = [-1] * N

    def topsort(i):
        res = []
        if nindex[i] != -1:
            return
        for j in src[i]:
            topsort(j)
        nindex[i] = len(nodes)
        nodes.append(i)

    for i in range(N):
        topsort(i)
    dp = [0] * N
    dpi = [None] * N
    for i in range(N):
        node = nodes[i]
        plen = 0
        mj = None
        for j in src[node]:
            k = nindex[j]
            # print(">>", node, "- > ", j, ":", k)
            if plen < dp[k] + 1:
                plen = dp[k] + 1
                mj = j
        # print(">", node, "- > ", mj)
        dp[i] = plen
        dpi[i] = mj
    return max(dp)


if __name__ == "__main__":
    print(solve())


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

int main(){
 int  A, B, C, D;
cin >> A >> B >> C >> D;

if((A+B) > (C+D)){
 cout << "Left" << endl;
 }
 else if((A+B) == (C+D)){
  cout << "Balanced" << endl;
 }
else{
 cout << "Right" << endl;
 }
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
    char x[4],y[4];scanf("%s%s",x,y);
    if(x[0]<y[0]){printf("<\n");}
    if(x[0]>y[0]){printf(">\n");}
    if(x[0]==y[0]){printf("=\n");}
    return 0;
}

Measured memory_bytes: 128
n=int(input())
D={}
for i in range(1,n+1):
    s=(str(i)[0],str(i)[-1])
    if s not in D:
        D[s]=1
    else:
        D[s]+=1
ans=0
for i in D:
    if (i[1],i[0]) in D:
        ans+=D[i]*D[i[1],i[0]]
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using pl = pair<ll, ll>;
const ll INF = ll(1e18);
const ll mod = ll(1e9+7);
const double pi = acos(-1);
#define rep0(i,n) for(ll (i) = 0; (i) < (n); ++(i))
#define rrep0(i,n) for(ll (i) = (n) - 1; (i) >= 0; --(i))
#define rep1(i,n) for(ll (i) = 1; (i) <= (n); ++(i))
#define rrep1(i,n) for(ll (i) = (n); (i) >= 1; --(i))
#define nfor(i,a,b) for(ll (i) = (a); (i) < (b); ++(i))
#define pf(x) cout << (x) << endl
#define all(x) (x).begin(),(x).end()
#define yes pf("Yes")
#define no pf("No")
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; }
const int dx[8]={1,0,-1,0,1,1,-1,-1};
const int dy[8]={0,1,0,-1,1,-1,1,-1};

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

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

ll factorial(ll n){
    ll ans = 1;
    rep1(i, n){
        ans *= i;
        ans %= mod;
    }
    return ans;
}

ll power(ll a, ll b){
    ll ans = 1;
    a %= mod;
    while(b) {
        if(b & 1LL) ans = ans * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return ans % mod;
}

//modの値の確認をすること
int main(){
    int a;
    rep1(i, 5){
        cin >> a;
        if(a == 0){
            pf(i);
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 3628
#include <cstdio>

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

	int p,max=0,sum=0;
	for(int i=0;i<n;i++){
		scanf("%d",&p);
		sum+=p;
		if(p>max) max=p;
	}

	sum-=max/2;

	printf("%d\n",sum);

	return 0;
}


Measured memory_bytes: 128
#include <stdio.h>

int a,b,ans ;

int main(void){
    
    scanf ("%d%d",&a,&b) ;
    
    ans = a+b ;
    
    if ( ans < a-b ) { ans = a-b ; }
    
    if ( ans < a*b ) { ans = a*b ; }
    
    printf ("%d",ans) ;
    
    return 0 ;
    
    
    
}


Measured memory_bytes: 128
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <string>
#include <unordered_map>
#include <vector>

//#define int long long

//#define ENABLE_TRACE
#ifdef ENABLE_TRACE
#define TRACE cout << __func__ << "()" << endl;
#define TRACE1(a) cout << __func__ << "(" << a << ")" << endl;
#define TRACE2(a, b) cout << __func__ << "(" << a << ", " << b << ")" << endl;
#else
#define TRACE
#define TRACE1(a)
#define TRACE2(a, b)
#endif  // #ifdef ENABLE_TRACE

using namespace std;

// Greatest Common Divisor
int Gcd(int a, int b) {
  TRACE2(a, b);
  if (a % b == 0)
    return b;
  return Gcd(b, a % b);
}

void Main() {
  int k, a, b;
  cin >> k >> a >> b;

  int kmax = (b / k) * k;
  if (kmax >= a) {
    cout << "OK" << endl;
  } else {
    cout << "NG" << endl;
  }
}

int32_t main() {
  Main();
  return 0;
}

Measured memory_bytes: 3540
#include <iostream>

using namespace std;

const int MAX = 2000002;
bool c[MAX+1];
 
int main(){
    int n,a,b;
 
    while(cin >> n >> a >> b , n+a+b){
	int cnt = 0;
	for(int i = 0 ; i <= n ; i++) c[i] = false;
	c[0] = true;
     
	for(int i = 0 ; i <= n ; i++){
	    if(c[i]&&(i+a <= n||i+b <= n)){
		c[i+a] = true; c[i+b] = true;
	    }
	}
	for(int i = 1 ; i  <= n ; i++) 
	    if(!c[i]) cnt++;
 
	cout << cnt << endl;
    }
    return 0;
}

Measured memory_bytes: 3980
n = gets.to_i
c = Array.new(n) { Array.new(3) }
(0..n-1).each do |i|
  x, y, h = gets.split.map(&:to_i)
  c[i][0] = x
  c[i][1] = y
  c[i][2] = h
end

tx = 0
ty = 0
th = 0
h = -1

for x in (0..100) do
  for y in (0..100) do
    h = -1
    (0..(c.length-1)).each do |i|
      if (c[i][2] > 0)
        if h == -1
          h = (x-c[i][0]).abs + (y-c[i][1]).abs + c[i][2]
        else
          if h != (x-c[i][0]).abs + (y-c[i][1]).abs + c[i][2]
            h = -1
            break
          end
        end
      end
    end
    if h > 0
      key = 1
      (0..(c.length-1)).each do |i|
        if c[i][2] == 0
          if h - (x-c[i][0]).abs - (y-c[i][1]).abs > 0
            key = 0
          end
        end
      end
      if key == 1
        tx = x
        ty = y
        th = h
        break
      end
    end
  end
end

puts tx.to_s + " " + ty.to_s + " " + th.to_s



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

const int maxn=85;
int n;
char s[maxn][maxn];
long long f[maxn][maxn][maxn][maxn],g[maxn][maxn][maxn];

int main(){
	scanf("%d",&n);
	n*=2;
	for(int i=0;i<n;i++){
		scanf("%s",s[i]);
		for(int j=0;j<n;j++)
			s[i+n][j]=s[i][j+n]=s[i+n][j+n]=s[i][j];
	}
	for(int len=1;len<=n;len++){
		for(int l=0;l<2*n;l++){
			int r=l+len-1;
			if(r>=2*n)break;
			for(int m=l;m<=r;m++){
				if(l==m&&m==r)g[l][r][m]++;
				for(int ll=l;ll<m;ll++)for(int rr=r;rr>m;rr--)
					g[l][r][m]+=g[ll+1][rr-1][m]*f[l][ll][rr][r];
				for(int ll=0;ll<l;ll++)for(int rr=ll;rr<l;rr++){
					if(rr-ll+1>len)break;
					for(int mm=ll;mm<=rr;mm++)if(s[mm][m]=='1')
						f[ll][rr][l][r]+=g[ll][rr][mm]*g[l][r][m];
				}
				for(int ll=r+1;ll<2*n;ll++)for(int rr=ll;rr<2*n;rr++){
					if(rr-ll+1>=len)break;
					for(int mm=ll;mm<=rr;mm++)if(s[mm][m]=='1')
						f[l][r][ll][rr]+=g[ll][rr][mm]*g[l][r][m];
				}
			}
		}
	}
	long long ans=0;
	for(int i=0;i<n;i++)for(int j=i+1;j<n;j++)if(s[i][j]=='1')
		ans+=g[i+1][i-1+n][j];
	printf("%lld\n",ans/(n/2));
	return 0;
}

Measured memory_bytes: 298240
import java.io.*;
import java.util.*;
class Main{
	static final long MOD = 1_000_000_007; // 10^9+7
    static final int MAX = 2_147_483_646; // intMax 
    static final int INF = 1_000_000_000; // 10^9  
    public static void main(String[] args) throws Exception {
		hayami saori = new hayami();
		int n = saori.saori_hayami();
		int[] a = new int[n];
		for(int i = 0;i < n;i++){
			a[i] = saori.saori_hayami();
		}
		Arrays.sort(a);
		System.out.println(Math.abs(a[0]-a[n-1]));

		saori.close();
    }
}

class hayami implements Closeable {
	private final InputStream in = System.in;
	private final byte[] hayami = new byte[1024];
	private int Hayami = 0;
	private int saori = 0;
	private boolean HayamiSaori() {
		if (Hayami < saori) {
			return true;
		}else{
			Hayami = 0;
			try {
				saori = in.read(hayami);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (saori <= 0) {
				return false;
			}
		}
		return true;
	}
	private int SaoriHayami() { 
		if (HayamiSaori()) {
            return hayami[Hayami++];
         }else{
             return -1;
         }
	}
	private static boolean hayami_saori(int hayami) { 
		return 33 <= hayami && hayami <= 126;
	}
	public boolean hayamisaori() { 
		while(HayamiSaori() && !hayami_saori(hayami[Hayami])) Hayami++; return HayamiSaori();
	}
	public String nextHayami() {
		if (!hayamisaori()) throw new NoSuchElementException();
		StringBuilder hayamin = new StringBuilder();
		int saori = SaoriHayami();
		while(hayami_saori(saori)) {
			hayamin.appendCodePoint(saori);
			saori = SaoriHayami();
		}
		return hayamin.toString();
	}
	public long saorihayami() {//nextLong
		if (!hayamisaori()) throw new NoSuchElementException();
		long hayami = 0;
		boolean misao = false;
		int saori = SaoriHayami();
		if (saori == '-') {
			misao = true;
			saori = SaoriHayami();
		}
		if (saori < '0' || '9' < saori) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= saori && saori <= '9') {
				hayami *= 10;
				hayami += saori - '0';
			}else if(saori == -1 || !hayami_saori(saori)){
				return misao ? -hayami : hayami;
			}else{
				throw new NumberFormatException();
			}
			saori = SaoriHayami();
		}
	}
	public int saori_hayami() {//nextInt
		long hayami = saorihayami();
		if (hayami < Integer.MIN_VALUE || hayami > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) hayami;
	}
	public double Hayamin() { //nextDouble
		return Double.parseDouble(nextHayami());
	}
	public void close() {
		try {
			in.close();
		} catch (IOException e) {
		}
    }
    
}

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

int main(){
	string str1, str2;
	while(cin >> str1 >> str2){

		// int count = 0;
		// for(int i = 0; i < str1.size(); i++){
		// 	for(int j = 0; j < str2.size(); j++){
		// 		int k = 0;
		// 		while(str1[i+k] == str2[j+k] && i+k < str1.size() && j+k < str2.size()){
		// 			//if(i + k > str1.size()-1 || j + k > str2.size()-1) break;
		// 			k++;
		// 			count = max(count, k);
		// 			//cout << str2.substr(i, k) << endl;
		// 		}
		// 	}
		// }
		// cout << count << endl;

		vector<vector<int> > dp(str1.size()+1, vector<int>(str2.size()+1));
		for(int i = 0; i < str1.size()+1; i++){
			for(int j = 0; j < str2.size()+1; j++){
				dp[i][j] = 0;
			}
		}
		int ans = 0;
		for(int i = 0; i < str1.size(); i++){
			for(int j = 0; j < str2.size(); j++){
				if(str1[i] == str2[j]){
					dp[i+1][j+1] = dp[i][j] + 1;
					ans = max(ans, dp[i+1][j+1]);
				}
			}
		}
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 63836
# AtCoder Beginner Contest 085
# C - Otoshidama 

N,Y = map(int,input().split())

for x in range (N+1):
    for y in range (N-x+1):
        if 10*x + 5*y + (N-x-y)==Y//1000:
            print (x,y,N-x-y)
            exit()

print(-1,-1,-1)

Measured memory_bytes: 9176
#include <iostream>
using namespace std;
int main(){
	int n[20],num,a[20],z,max=0;
	cin>>num;
	for(int i=0;i<num;i++){
		cin>>a[i]>>n[i];
		if(max<n[i]){
			max=n[i];
			z=i;
		}else if(max==n[i]){
			if(a[z]>a[i])z=i;
		}
	}
	cout<<a[z]<<" "<<n[z]<<endl;
	return 0;
}

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

int main(){
  	int ans(0);
 	string a;
  	cin >> a;
  	for(int i = 0 ; i < (a.length() / 2) ; i++ ){
     	 if(a[i] != a[a.length() - 1- i]) ans++;
    }
  	cout << ans << endl;
}

Measured memory_bytes: 256
use proconio::marker::*;
use proconio::*;

fn main() {
    input! {
        d: usize,
        c: [i64; 26],
        s: [[i64; 26]; d],
    };
    input! {
        mut t: [Usize1; d],
    };
    input! {
        m: usize,
        dq: [(Usize1, Usize1); m],
    };

    for &(p, q) in &dq {
        let mut lasts = [-1; 26];
        t[p] = q;
        let mut score = 0;
        for i in 0..d {
            score += calc_score(i, t[i], &c, &s, &mut lasts);
            lasts[t[i]] = i as i64;
        }
        println!("{}", score);
    }
}

fn calc_score(i: usize, j: usize, c: &Vec<i64>, s: &Vec<Vec<i64>>, lasts: &mut [i64; 26]) -> i64 {
    let mut res = s[i][j];
    let tmp = lasts[j];
    lasts[j] = i as i64;

    for j in 0..26 {
        let i = i as i64;
        let last = lasts[j];
        res -= c[j] * (i - last);
    }

    lasts[j] = tmp;
    res
}


Measured memory_bytes: 4400
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		String[] states = { "none", "a", "b" };
		Scanner sc = new Scanner(System.in);
		sc.nextLine();
		String in = sc.nextLine().toLowerCase();
		String state = "none";
		int count = 0;
		for (String s : in.split("")) {
			switch (state) {
			case "none":
				if ("a".equals(s)) {
					state = "a";
				}
				break;
			case "a":
				if ("b".equals(s)) {
					state = "b";
				} else {
					state = "none";
				}
				break;
			case "b":
				if ("c".equals(s)) {
					count++;
				}
				state = "none";
				break;
			}
			if(s.equals("a")) {
				state = "a";
			}
		}
		System.out.println(count);
	}
}


Measured memory_bytes: 21332
import bisect
import os
from collections import Counter, deque
from fractions import gcd
from functools import lru_cache
from functools import reduce
import functools
import heapq
import itertools
import math
import numpy as np
import re
import sys
import string


if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")

#
#
# N = int(sys.stdin.readline())
# print(int(math.sqrt(N)) ** 2)




N, K = [int(sys.stdin.readline()) for _ in range(2)]
ans = 1
for n in range(N):
    ans = min(ans *2, ans+K)
print(ans)


Measured memory_bytes: 17168
#include<bits/stdc++.h>
#define rep(i,a,...) for(int i = (a)*(strlen(#__VA_ARGS__)!=0);i<(int)(strlen(#__VA_ARGS__)?__VA_ARGS__:(a));++i)
#define per(i,a,...) for(int i = (strlen(#__VA_ARGS__)?__VA_ARGS__:(a))-1;i>=(int)(strlen(#__VA_ARGS__)?(a):0);--i)
#define foreach(i, n) for(auto &i:(n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define all(x) (x).begin(), (x).end()
#define bit(x) (1ll << (x))
using ll = long long;
//const ll MOD = (ll)1e9+7;
const ll MOD = 998244353;
const int INF = (ll)1e9+7;
const ll INFLL = (ll)1e18;
using namespace std;
template<class t>
using vvector = vector<vector<t>>;
template<class t>
using vvvector = vector<vector<vector<t>>>;
template<class t>
using priority_queuer = priority_queue<t, vector<t>, greater<t>>;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}
#ifdef DEBUG
#define debug(x) cout<<"LINE "<<__LINE__<<": "<<#x<<" = "<<x<<endl;
#else
#define debug(x) (void)0
#endif

ll modpow(ll x, ll b){
  ll res = 1;
  while(b){
    if(b&1)res = res * x % MOD;
    x = x * x % MOD;
    b>>=1;
  }
  return res;
}

ll modinv(ll x){
  return modpow(x, MOD-2);
}

bool was_output = false;
template<class t>
void output(t a){
  if(was_output)cout << " ";
  cout << a;
  was_output = true;
}
void outendl(){
  was_output = false;
  cout << endl;
}
ll in(){
  ll res;
  scanf("%lld", &res);
  return res;
}

template<class t>
istream& operator>>(istream&is, vector<t>&x){
  for(auto &i:x)is >> i;
  return is;
}

template<class t, class u>
istream& operator>>(istream&is, pair<t, u>&x){
  is >> x.first >> x.second;
  return is;
}

template<class t>
void in(t&x){
  cin >> x;
}

template<class t>
void out(t x){
  cout << x;
}

int need[]={0,2,5,5,4,5,6,3,7,6};

string func(){
  int n = in();
  int m = in();
  vector<int> can(m);
  foreach(i,can)i=in();
  vector<int> dp(n+1,-1);
  dp[0] = 0;
  rep(i,n){
    if(dp[i]==-1)continue;
    foreach(j,can){
      if(i+need[j]<=n){
        chmax(dp[i+need[j]],dp[i]+1);
      }
    }
  }
  string res = "";
  int it = n;
  while(it!=0){
    vector<int> kouho = [&](){
                          vector<int> res;
                          foreach(i,can){
                            if(it-need[i]<0)continue;
                            if(dp[it]-1!=dp[it-need[i]])continue;
                            res.push_back(i);
                          }
                          return res;
                        }();
    int add = *max_element(all(kouho));
    res += (char)('0'+add);
    it -= need[add];
  }
  return res;
}

int main(){
  cout << func() << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
void ABC130(void);
void ABC131(void);
void ABC132(void);
void ABC133(void);
void ABC134(void);
void ABC135(void);
void ABC136(void);
void ABC137(void);
void ABC138(void);
void ABC139(void);

int main(void){
    ABC131();
}

void ABC131(){
    int i,j,k=0;
    string s;
    cin>>s;
    for(i=0;i<=2;++i){
        if(s[i]==s[i+1])++k;
    }
    if(k==0)cout<<"Good"<<endl;
    else cout<<"Bad"<<endl;
}

Measured memory_bytes: 256
n = int(input())
x = list(reversed(list(map(int, input()))))
s = sum(x)
md = [s + 1, s - 1]
bs = [0, 0]
for i in range(2):
    if not md[i]:
        continue
    t = 1
    for j in range(n):
        if x[j]:
            bs[i] = (bs[i] + t) % md[i]
        t = t * 2 % md[i]
def solve(u):
    ans = 0
    while u:
        u = u % bin(u).count('1')
        ans += 1
    return ans
for i in range(n - 1, -1, -1):
    if not md[x[i]]:
        print(0)
        continue
    dt = pow(2, i, md[x[i]]) * (-1 if x[i] else 1)
    print(solve((bs[x[i]] + dt) % md[x[i]]) + 1)

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

int main(){
    int N,M;
	cin >> N >> M;
    vector<string>A(N);
    vector<string>B(M);
	for(int i = 0; i < N; i++) {
        cin >> A[i];
    }
	for(int i = 0; i < M; i++) {
        cin >> B[i];
    }
	for(int i = 0; i < N-M+1; i++){
		for(int j = 0; j < N-M+1; j++){
			bool ok = true;
			for(int k = 0; k < M; k++) {
                for(int l = 0; l < M; l++) {
                    if(A[i+k][j+l] != B[k][l]) {
                        ok = false;
                    }
                }
            }
			if(ok) {
                cout << "Yes" << endl;
                return 0;
            }
		}
	}
	cout << "No" << endl;
}

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

using namespace std;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
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 (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = 1e18;
const ll MOD = 1000000007;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0, -1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
//#define mp make_pair

    
int main() {
  ll n, x;
  cin >> n >> x;
  vl a(n);
  rep (i, n) {
    cin >> a[i];
  }
  int cnt = 0;
  sort(all(a));
  rep (i, n) {
    if (x >= a[i]) {
      x -= a[i];
      cnt++;
    }
  }
  if (x == 0) {
    cout << cnt << endl;
  }
  else {
    if (cnt == n) {
      cout << n - 1 << endl;
    }
    else {
      cout << cnt << endl;
    }
  }
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args)throws Exception {
        BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer tokenizer = new StringTokenizer(input.readLine());
        int a = Integer.parseInt(tokenizer.nextToken());
        int b = Integer.parseInt(tokenizer.nextToken());
        System.out.println(a + (b/2));
    }
}


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



int main() {
    
    int N;
    cin >> N;
    
    vector<string> W(N);
    for (int i=0; i<N; i++) {
        cin >> W[i];
    }
    
    vector<char> matsubi(N);
    
    for (int i=0; i<N; i++) {
        matsubi[i] = W[i][W[i].size()-1];
    }
    
    bool ans = false;
    
    for (int i=1; i<N; i++) {
        if (W[i][0] == matsubi[i-1]) {
            for (int j=0; j<i; j++) {
                if (W[i] == W[j]) {
                    ans = true;
                    break;
                }
            }
        }
        else {
            ans = true;
            continue;
        }
        
    }
    
    if (ans) cout << "No" << endl;
    else cout << "Yes" << endl;
    
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int ans = 0;
    vector<int> v(n), c(n);
    rep(i, 0, n) cin >> v[i];
    rep(i, 0, n) cin >> c[i];
    rep(i, 0, n){
        if(v[i] > c[i]) ans += v[i] - c[i];
    }
    cout << ans << endl;
}

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

using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

using Pi = pair<int, int>;
using Tapris = tuple<int, int, int>;
using vint = vector<int>;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int n;
  cin >> n;
  vint a(n);
  vint sum(n+1);
  rep(i, n) cin >> a[i], sum[i+1] += sum[i]+a[i];
  auto f = [&](int l, int r) {
    return sum[r]-sum[l];
  };
  auto g = [&](int l, int m, int r) {
    return abs(f(l, m)-f(m, r));
  };
  int ans = inf;
  reps(i, 2, n-1) {
    int mn = inf, mx = -inf;
    {
      int lb = 0, ub = i;
      while(lb+1 < ub) {
	int mb = (lb+ub)/2;
	if(g(0, mb, i)-g(0, mb-1, i) < 0) lb = mb;
	else ub = mb;
      }
      chmin(mn, min(f(0, lb), f(lb, i)));
      chmax(mx, max(f(0, lb), f(lb, i)));
    }
    {
      int lb = i, ub = n;
      while(lb+1 < ub) {
	int mb = (lb+ub)/2;
	if(g(i, mb, n)-g(i, mb-1, n) < 0) lb = mb;
	else ub = mb;
      }
      chmin(mn, min(f(i, lb), f(lb, n)));
      chmax(mx, max(f(i, lb), f(lb, n)));
    }
    chmin(ans, mx-mn);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3456
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <memory.h>
#include <cassert>

using namespace std;


#define all(c) ((c).begin()), ((c).end())
#define debug(c) cerr << "> " << #c << " = " << (c) << endl;
#define iter(c) __typeof((c).begin())
#define present(c, e) ((c).find((e)) != (c).end())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define tr(i, c) for (iter(c) i = (c).begin(); i != (c).end(); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, a, b) for (int i = (int)(a); i <= (int)(b); i++)

#define mp make_pair
#define fst first
#define snd second
#define pb push_back


const double EPS = 1e-10;


typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef complex<double> P;


int main() {
	for (int n; cin >> n, n != 0; ) {
		int t[20][20];
		rep (i, n) rep (j, n + 1) cin >> t[i][j];
		
		int dp[1 << 16];
		rep(i, 1 << 16) dp[i] = 10000000;
		dp[0] = 0;
		rep (mask, 1 << n) {
			rep (i, n) if (mask & 1 << i) {
				int eq = t[i][0];
				rep(j, n) if ((mask ^ 1 << i) & 1 << j) eq = min(eq, t[i][j + 1]);
				dp[mask] = min(dp[mask], dp[mask ^ 1 << i] + eq);
			}
		}
		cout << dp[(1 << n) - 1] << endl;
	}
	
	return 0;
}

Measured memory_bytes: 0
// J'aime
// Chemise Blanche

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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr << __LINE__ << " > " << #x << " = " << (x) << endl

void MAIN() {
  int n; cin >> n;
  double s = 0;
  for (int i = 0; i < n; i++) {
    double x; string u;
    cin >> x >> u;
    if (u == "JPY") s += x;
    else s += x * 380000.0;
  }
  cout << s << '\n';
}

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) MAIN();
}


Measured memory_bytes: 3784
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
typedef long long LL;

double sum_square(const std::vector<int>& y, const std::vector<int>& z) {
  double d = 0;
  for (int i = 0; i < y.size(); ++i) {
    d += (y[i] - z[i]) * (y[i] - z[i]);
  }
  return d;
}

int main() {
  int N, D; std::cin >> N >> D;
  std::vector<std::vector<int>> X;
  for (int i = 0; i < N; ++i) {
    std::vector<int> x(D);
    for (int j = 0; j < D; ++j) {
      std::cin >> x[j];
    }
    X.push_back(x);
  }

  int cnt = 0;
  for (int n = 0; n < N; ++n) {
    for (int i = n + 1; i < N; ++i) {
      int v = sum_square(X[n], X[i]);
      int v2 = (int)sqrt(v);
      if (v == (v2*v2)) ++cnt;
    }
  }

  std::cout << cnt << std::endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x)          (x).begin(), (x).end()
#define rep(i, n)       for (i64 i = 0, i##_limit = (n); i < i##_limit; ++i)
#define reps(i, s, t)   for (i64 i = (s), i##_limit = (t); i <= i##_limit; ++i)
#define repr(i, s, t)   for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#ifndef DBG
#define trace(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U> inline bool chmax(T &a, const U &b) { return b > a && (a = b, true); }
template <class T, class U> inline bool chmin(T &a, const U &b) { return b < a && (a = b, true); }
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> make_v(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto make_v(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(make_v<T>(initValue, args...))>(sz, make_v<T>(initValue, args...));
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail&... tail) { cin >> head; read(tail...); }

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream& operator<< (ostream &out, const vector<T> &vec) {
    static constexpr const char *delim[] = { " ", "" };
    for (const auto &e : vec) out << e << delim[&e == &vec.back()];
    return out;
}
// }}} End Header

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr);

    int N;
    read(N);
    vector<int > a(N);
    rep(i, N) read(a[i]);

    if (all_of(all(a), [](int a) { return (a & 1) || a % 3 == 0 || a % 5 == 0; } )) {
        print("APPROVED");
    } else
    {
        print("DENIED");
    }

    return 0;
}


Measured memory_bytes: 256