akhauriyash/Code-Regression huggingface dataset:
import scala.collection.mutable.ArrayBuffer
import scala.io.StdIn

object Main extends App {

  def pow5(x: Long) = x * x * x * x * x
  val x = StdIn.readInt()
  val d = -1000L to 1000L
  val set = d.map(pow5).toSet
  val map = d.map(a => pow5(a) -> a).toMap
  val good = d.filter(a => set.contains(x + pow5(a)))
  println(s"${map(x + pow5(good.head))} ${good.head}")

  def readIntPair: (Int, Int) = {
    val Array(x, y) = StdIn.readLine().split(" ").map(_.toInt)
    (x, y)
  }
}

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

int main() {
  int N, M, X, Y;
  cin >> N >> M >> X >> Y;
  int A[N], B[M];
  for(int i=0;i<N;i++){
    cin >> A[i];
  }
  for(int i=0;i<M;i++){
    cin >> B[i];
  }
  sort(A, A+N);
  sort(B, B+M);
  bool ans = true;
  if(A[N-1] >= B[0]) ans = false;
  if(B[0] > Y) ans = false;
  if(B[0] <= X) ans = false;
  cout << (ans ? "No War" : "War") << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(v) (v).begin(),(v).end();


string a[400];
int b[100];

signed main(){
    int n;cin>>n;
    string x;
    for(int i=1;i<=n;i++)cin>>a[i]>>b[i];
    cin>>x;
    int ans=0;
    int f=0;
    for(int i=1;i<=n;i++){
        ans += b[i]*f;
        f |= a[i]==x;
    }
    cout<<ans<<endl;

   
   // getchar();getchar();

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, start, n) for (int i = (int)(start); i < (int)(n); ++i)
static const int INFTY = (1 << 30);
int N, M;
void func()
{
    string T;
    cin >> T;
    int A[4];
    rep(i, 0, 4) A[i] = T[i] - '0';
    int ans = 7;
    for (int bit = 0; bit < (1 << 3); ++bit)
    {
        int tmp = A[0];
        string str;
        str.push_back(A[0] + '0');
        for (int i = 0; i < 3; ++i)
        {
            if (bit & (1 << i))
            {
                tmp += A[i + 1];
                str.push_back('+');
            }
            else
            {
                tmp -= A[i + 1];
                str.push_back('-');
            }
            str.push_back(A[i + 1] + '0');
        }

        if (tmp == 7)
        {
            cout << str + "=7" << endl;
            return;
        }
    }
}
int main()
{
    func();
}

Measured memory_bytes: 3612
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <vector>
#include <cstdlib>
#include <map>
#include <queue>
#include <algorithm>
#include <stack>
#include <functional>
#define rep(i,j,n) for(i=j;i<(n);i++)
#define rrep(i,j,n) for(i=j;i>(n);i--)
typedef long long int lli;
#define N 1000000007

using namespace std;

//lli gcd(lli a,lli b){
//    lli x,y;
//    x=max(a,b);
//    y=min(a,b);
//    if(x%y==0){
//        return y;
//    }
//    else{
//        return gcd(y,x%y);
//    }
//}
//
//lli lcm(lli a,lli b){
//    lli x,y;
//    x=max(a,b);
//    y=min(a,b);
//    return x*y/gcd(x,y);
//}

int main(){
    lli n,ans=1;
    string s;
    map<char,lli> map;
    lli i,j;
    cin>>n>>s;
    rep(i,0,n){
        map[s[i]]++;
    }
    for(auto itr=map.begin();itr!=map.end();itr++){
        ans*=itr->second+1;
        ans%=N;
    }
    ans--;
    cout<<ans<<endl;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define debug(x) cout << "debug " << x << endl;
const int INF = 100000000;
using namespace std;

static const int dy[8] = {0,-1,-1,-1,0,1,1,1};
static const int dx[8] = {1,1,0,-1,-1,-1,0,1};

const int n = 11;
char m[n][n];

int search(int y, int x, char b, char a){
    int cnt = 0;
    rep(i,8){
        int line = 0;
        range(j,1,9){
            if(m[y + dy[i] * j][x + dx[i] * j] == b) line++;
            else if(m[y + dy[i] * j][x + dx[i] * j] == a){
                cnt+=line;
                break;
            }else{
                break;
            }
        }
    }
    return cnt;
}

void putCookie(int y, int x, char b, char a){
    int ny, nx;
    m[y][x] = a;
    rep(i,8){
        ny = y + dy[i];
        nx = x + dx[i];
        range(j,1,9){
            if(m[y + dy[i] * j][x + dx[i] * j] == b) continue;
            else if(m[y + dy[i] * j][x + dx[i] * j] == a){
                range(k,1,n){
                    if(m[y + dy[i] * k][x + dx[i] * k] == b) m[y  + dy[i] * k][x + dx[i] * k] = a;
                    else break;
                }
            } else break;
        }
    }
}

int main(){
    rep(i,n) rep(j,n) m[i][j] = '.';
    rep(i,8) rep(j,8) cin >> m[i + 1][j + 1];

    bool a, b;
    int cnt, x, y;
    while(true){
        a = b = false;

        cnt = 1;
        for(int i = 8; i >= 1; i--){
            for(int j = 8; j >= 1; j--){
                if(m[i][j] != '.') continue;
                int temp = search(i, j, 'x', 'o');
                if(temp >= cnt){
                    cnt = temp;
                    x = j;
                    y = i;
                    a = true;
                }
            }
        }
        if(a) putCookie(y, x, 'x', 'o');
        /*
        cout << y <<' '<<x<< endl;
    rep(i,8){ rep(j,8){cout << m[i +1][j+1];} cout << endl;}
    cout << endl;
    */

        cnt = 1;
        range(i,1,9){
            range(j,1,9){
                if(m[i][j] != '.') continue;
                int temp = search(i, j, 'o', 'x');
                if(temp >= cnt){
                    cnt = temp;
                    x = j;
                    y = i;
                    b = true;
                }
            }
        }
        if(b) putCookie(y, x, 'o', 'x');

        /*
        cout << y <<' '<<x<< endl;
    rep(i,8){ rep(j,8){cout << m[i+1][j+1];} cout << endl;}
    cout << endl;
    */

        if(not a && not b) break;
    }
    rep(i,8){ rep(j,8){cout << m[i + 1][j + 1];} cout << endl;}
}

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

import sys


def main():
    station = ""
    for c in range(ord('a'), ord('z') + 1):
        station += chr(c)
    for c in range(ord('A'), ord('Z') + 1):
        station += chr(c)

    while True:
        n = int(sys.stdin.readline())
        if n == 0:
            return 0

        l = sys.stdin.readline()
        l = map(lambda x: int(x), l.split())

        s = sys.stdin.readline().rstrip()
        res = ""
        for i, x in enumerate(s):
            index = ord(x) - (ord('a') if x.islower() else ord('A') + 26) - l[i % len(l)]
            index %= len(station)
            res += station[index]
        print res

if __name__ == '__main__':
    main()

Measured memory_bytes: 4256
import numpy as np

n,a,b = map(int,input().split())
h = [int(input()) for _ in range(n)]
h = np.array(h)

hi = 10**10
low = -1

def calc(x):
    y = h-x*b
    y[y<0] = 0
    f = np.ceil(y/(a-b)).sum()
    return f

while hi-low > 1:
    ave = (hi+low)//2
    if calc(ave) <= ave:
        hi = ave
    else:
        low = ave
    
print(hi)

Measured memory_bytes: 17136
#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <algorithm>
#include <iostream>
#include <set>
using namespace std;
const int MOD = 1000000007;
const int INF = 1e9;
typedef long long ll;

int main(){
    int a,b,c;
    cin >> a >> b >> c;

    int count = 0;

    for(int i=0;i<c;i++){
        if(b - a < 0){
            cout << count << endl;
            return 0;
        }
        b -= a;
        count++;
        
    }

    cout << count << endl;
    
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <bits/stdc++.h>
using namespace std;
int main(){
    // Your code
    int K;

    vector<int> vec(3);

    for (int i=0;i<3;i++){
        cin >> vec[i];
    }
    cin>>K;

    sort(vec.begin(),vec.end());
    reverse(vec.begin(),vec.end());
    int a = vec[0];
    for (int i=0;i<K;i++){
        a = a*2;
    }
    
    int ans = a + vec[1] + vec[2];

    cout << ans <<endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define _USE_MATH_DEFINES
#include <math.h>
#define rep(i,n) for(int i = 0;i < n;i++)
#define NIL = -1;
#define all(x) x.begin(),x.end()
const ll INF = 1e9;
const ll mod = 1e9 + 7;
 
int digit(ll x) {
    if (x / 10 == 0) return 1;
    return digit(x / 10) + 1;
}
 
ll gcd(long long a,long long b) {
    if (a < b) swap(a,b);
    if (b == 0) return a;
    
    return gcd(b,a%b);
}

bool is_prime(long long N){
    if (N == 1) return false;
    for (long long i = 2;i * i <= N;i++){
        if (N % i == 0) return false;
    }
    return true;
}
 
ll lcm(ll a,ll b){
    return ((a * b == 0)) ? 0 : (a / gcd(a,b) * b);
}
 
double DegreeToRadian(double degree){
    return degree * M_PI / 180.0;
}
 
 
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};
 
 
///////////////////////////////////////////////////////////////////////////////////

int main(){
    int n,k;
    cin >> n >> k;
    int x = 200010;
    vector<int> a(x, 0);
    set<int> exist;
    for (int i = 0;i < n;i++){
        int A;
        cin >> A;
        a[A]++;
        exist.insert(A);
    }

    sort(a.begin(), a.end(), greater<int>());
    int sum = 0;
    for (int i = 0;i < k;i++){
        sum += a[i];
    }

    cout << n - sum << endl;
}

Measured memory_bytes: 13404
#include<bits/stdc++.h>
using namespace std;
int main(){
 int n;
  cin>>n;
  string s;
  cin>>s;
  int r=0,b=0;
  for(char i:s){
   	if(i=='R')r++;
    else b++;
  }
  if(r>b)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

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

static const int INF = 1 << 30;

template <class T> inline void chmax(T &a, const T &b) {
  if (a < b)
    a = b;
}

int main()
{
  // Input
  int numDay;
  std::cin >> numDay;
  assert(1 <= numDay and numDay <= 1.0e+5);
  std::vector<std::vector<int>> gain(3);
  for (int j = 0; j < 3; ++j)
    gain[j].assign(1 + numDay, 0);
  for (int i = 1; i <= numDay; ++i) {
    std::cin >> gain[0][i] >> gain[1][i] >> gain[2][i];
    assert(1 <= gain[0][i] and gain[0][i] <= 1.0e+4);
    assert(1 <= gain[1][i] and gain[1][i] <= 1.0e+4);
    assert(1 <= gain[2][i] and gain[2][i] <= 1.0e+4);
  }

  // Init
  std::vector<std::vector<int>> dp(3);
  for (int j = 0; j < 3; ++j) {
    dp[j].assign(1 + numDay, -INF);
    dp[j][1] = gain[j][1];
  }

  // DP main
  for (int i = 1; i < numDay; ++i) {
    for (int j = 0; j < 3; ++j) {
      for (int k = 0; k < 3; ++k) {
        if (k == j)
          continue;
        chmax<int>(dp[k][i + 1], dp[j][i] + gain[k][i + 1]);
      }
    }
  }

  // Output
  std::cout << std::max({dp[0][numDay], dp[1][numDay], dp[2][numDay]})
            << std::endl;

  return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define FAST_IO                     \
  ios_base::sync_with_stdio(false); \
  cin.tie(0);                       \
  cout.tie(0);
typedef long long ll;
/**
 * Uncomment the #define below if problem contains multiple test cases
 */
// #define MULTIPLE_TESTS 1
template <typename T>
inline void readArray(vector<T>& arr, int n) {
  arr.resize(n);
  for (auto& element : arr) {
    cin >> element;
  }
}
void solve() {
  int n, k;
  cin >> n >> k;
  vector<int> arr;
  readArray(arr, n);
  sort(arr.begin(), arr.end());
  int ans = 0;
  for (int i = 0; i < k; ++i) {
    ans += arr[i];
  }
  cout << ans << endl;
}

int main() {
  FAST_IO;
  int t = 1;
#ifdef MULTIPLE_TESTS
  cin >> t;
#endif

  while (t--) {
    solve();
  }

  return 0;
}

Measured memory_bytes: 3616
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	set<P> s;
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= n; j++){
			if(i >= j) continue;
			if(n%2 == 1){
				if(i+j != n) s.insert(P(i, j));
			}
			else{
				if(i+j != n+1) s.insert(P(i, j));
			}
		}
	}
	cout << s.size() << endl;
	for(auto p : s){
		cout << p.first << " " << p.second << endl;
	}
	return 0;
}

Measured memory_bytes: 512
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,c) for (int i = 0; i < (int)c; i++)
#define all(v) v.begin(), v.end()
const int inf = 1000000000; //10^9
using ll = long long;
using P = pair<int,int>;
//加算代入演算子は+=！！！！！
//int 2^31 10^9まで
int main() {
    string s;
    cin >> s;
    cout << s.substr(0, 5) << " " << s.substr(6, 7) << " " << s.substr(14) << endl;
}

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

using ll = long long;
using P = pair<int, int>;

const int INF = 1e9;
const int MOD = 1e9 + 7;

// 4近傍、8近傍
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

set<int> ans;

int main() {
  // 入力
  int a, b, k;
  cin >> a >> b >> k;

  for (int i = a; i < a + k; i++) if (i <= b) {
    ans.insert(i);
  }
  for (int i = b - k + 1; i <= b; i++) if (i >= a) {
    ans.insert(i);
  }

  // 解答
  set<int>::iterator it = ans.begin();
  for (; it != ans.end(); it++) {
    cout << *it << endl;
  }

  return 0;
}


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

int main(){
  const int INF = 100100100;
  long long n; cin >> n;
  int cnt = INF;
  int ans = INF;
  for(long long i = 1LL;i*i<=n; i++){
    if(n % i == 0){
      long long j = n/i;
      string s = to_string(i);
      string t = to_string(j);
      cnt = max((int)s.size(), (int)t.size());
      ans = min(ans, cnt);
    }
    else continue;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
using System;
using System.Linq;
class Program
{
    static void Main()
    {
        int[] input = Console.ReadLine().Split().Select(i => int.Parse(i)).ToArray(); 
        //int a=int.Parse(Console.ReadLine());
        //string a = Console.ReadLine();

        Console.WriteLine(input[1]%input[0]==0?input[0]+input[1]:input[1]-input[0]);
        Console.ReadLine();
    }
}

Measured memory_bytes: 13268
#include<stdio.h>
int cj(int b,int p)
{
	int i,t=1;
	for(i=0;i<p;i++)
	    t=t*b;
	return t;
}

int main()
{
    int x,b,p,i=2,j=2,t=1,max=1;
    scanf("%d",&x);
    while(i<=x)
    {
    	j=2;
    	t=cj(i,j);
    	while(t<=x)
    	{
    		if(t>max)
    		    max=t;
    		j++;
			t=cj(i,j);
	    }
		i++;
	}
	printf("%d",max);
}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
using namespace std;

struct line {
	long long int x, y;
};

bool cmp(line a, line b) {
	if (a.x < b.x)return true;
	else if (a.x > b.x)return false;
	
}

int main() {
	//cout << fixed << setprecision(10);
	line line[100005];
	long long int r, c, cou = 1, n, x1[100050], x2[100050], y1[100050], y2[100050], linex[100005] = {}, liney[100005] = {};
	cin >> r >> c >> n;
	for (int i = 1; i <= n; i++) {
		cin >> x1[i] >> y1[i] >> x2[i] >> y2[i];
		if ((x1[i] == 0 || x1[i] == r||y1[i] == 0 || y1[i] == c) && (x2[i] == 0 || x2[i] == r||y2[i] == 0 || y2[i] == c)) {
			if (x1[i] == 0) { linex[cou] = y1[i]; }
			else if (y1[i] == c) { linex[cou] = c + x1[i]; }
			else if (x1[i] == r) { linex[cou] = 2 * c + r - y1[i]; }
			else { linex[cou] = 2 * c + 2 * r - x1[i]; }

			if (x2[i] == 0) { liney[cou] = y2[i]; }
			else if (y2[i] == c) { liney[cou] = c + x2[i]; }
			else if (x2[i] == r) { liney[cou] = 2 * c + r - y2[i]; }
			else { liney[cou] = 2 * c + 2 * r - x2[i]; }
			long long int tmp = liney[cou];
			liney[cou] = max(liney[cou], linex[cou]);
			linex[cou] = min(linex[cou], tmp);
			
			line[cou].x = linex[cou];
			line[cou].y = liney[cou];
			cou++;
		}
	}
	cou--;
	sort(line + 1, line + cou + 1, cmp);
	long long int right, key,task[200005],memo;

	

	for (int i = 1; i <= cou; i++) {
		task[0] = i;
		i++;
		if (i > cou) {
			cout << "YES";
			return 0;
		}
		memo = 0;
	next:

		for (int j = memo; j >= 0; j--) {
			if(line[i].x<line[task[j]].y){
				if (line[i].y > line[task[j]].y) {
					cout << "NO";
					return 0;
				}
				else {
					memo = j + 1;
					task[j + 1] = i;
					i++;
				}
				
				if (i > cou) {
					cout << "YES";
					return 0;
				}
				goto next;
			}
		}
		i--;
	}
	cout << "YES";
}

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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf=1e9;
const int64_t inf64=1e18;
const double eps=1e-9;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

struct S{
    string date;
    int begin,end;
    
    S(){}
    
    S(string s,int b,int e)
    {
        date=s;
        begin=b;
        end=e;
    }
};

void solve(int n){
    vector<S> data[600];
    vector<int> ans(600,0);
    
    rep(i,0,n){
        string d;
        cin>>d;
        
        string temp;
        cin>>temp;
        
        int time=(temp[0]-'0')*600+(temp[1]-'0')*60+(temp[3]-'0')*10+(temp[4]-'0');
        
        string io;
        cin>>io;
        
        string sid;
        cin>>sid;
        
        int id=(sid[0]-'0')*100+(sid[1]-'0')*10+(sid[2]-'0');
        
        if(io=="I"){
            data[id].push_back(S(d,time,0));
        }else{
            data[id][data[id].size()-1].end=time;
        }
    }
    
    rep(i,1,500){
        rep(j,0,data[0].size()){
            rep(k,0,data[i].size()){
                if(data[0][j].date!=data[i][k].date){
                    continue;
                }
                
                int t_begin=max(data[0][j].begin,data[i][k].begin);
                int t_end=min(data[0][j].end,data[i][k].end);
                int t_ans=max(0,t_end-t_begin);
                
                ans[i]+=t_ans;
            }
        }
    }
    
    int answer=0;
    
    rep(i,0,500){
        answer=max(answer,ans[i]);
    }
    
    cout<<answer<<endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(10);
    
    while(true){
        int n;
        cin>>n;
        
        if(n==0) break;
        
        solve(n);
    }
    return 0;
}

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

bool b[50][50];
int N,M;
bool v[50];
bool func(int i,int j){
  bool ret=false;
  repeat(i,N) v[i]=i==0?true:false;
  queue<int> q;
  q.push(0);
  b[i][j]=b[j][i]=false;
  while(q.size()){
    int t=q.front();
    q.pop();
    repeat(i,N){
      if(b[t][i] and v[i]==false) {
        q.push(i);
        v[i]=true;
      }
    }
  }
  repeat(i,N){
    if(v[i]==false) ret=true;
  }
  b[i][j]=b[j][i]=true;
  return ret;
}

int main(){
  cin >> N >> M;
  repeat(i,M){
    int x,y;
    cin >> x >> y;
    b[x-1][y-1]=b[y-1][x-1]=true;
  }
  int ans=0;
  for(int i=0;i<N;i++){
    for (int j=i+1;j<N;j++){
      if (b[i][j]){
        if(func(i,j)) {
          ans++;
        }
      }
    }
  }
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 256
N, M, K = map(int, input().split())

MOD = 10**9+7
n = N*M-2
fac = [1]*(n+1)
rev = [1]*(n+1)
 
for i in range(1,n+1):
  fac[i] = i*fac[i-1]%MOD
  rev[i] = pow(fac[i], MOD-2, MOD)
 
comb = lambda a,b:(fac[a]*rev[a-b]*rev[b])%MOD

C = comb(N*M-2, K-2)
ans = 0
for d in range(N):
    ans += d*(N-d)*(M**2)*C
    ans %= MOD

for d in range(M):
    ans += d*(M-d)*(N**2)*C
    ans %= MOD

print(ans)

Measured memory_bytes: 43500
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pint;

int main(){
    int n;
    string s;
    cin>>n>>s;
    int cnt=0,cnt2=0;
    rep(i,n){
        if(s[i]=='(') ++cnt;
        else{
            if(cnt==0) ++cnt2;
            else --cnt;
        }
    }
    rep(i,cnt2) s="("+s;
    rep(i,cnt) s+=")";
    cout<<s<<endl;
    return 0;
}

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

struct item{
	ll val;
	ll wt;
};

vector<item> a;
ll n,w;

ll maxCost(){
	ll maxVal=n*1000;
	ll dp[n+1][maxVal+1];
	
	for(int va=0;va<=maxVal;va++){
		dp[1][va]=inf;
	}
	dp[1][0]=0;
	dp[1][a[1].val]=a[1].wt;
	
	for(int i=2;i<=n;i++){
	   for(int v=0;v<=maxVal;v++){
	   	 dp[i][v]=dp[i-1][v];
	   	 if(a[i].val > v)
	   	 continue;	
	    dp[i][v]=min(a[i].wt + dp[i-1][v-a[i].val],dp[i-1][v]);
    	}
   }
	
	ll ans=0;
	for(ll x=0;x<=maxVal;x++){
		if(dp[n][x]<=w)
		ans=x;
	}
	return ans;
}

int main(){
	cin>>n>>w;
	
	item it1;
	it1.wt=-1;
	it1.val=-1;
	a.push_back(it1);
	
	for(int i=0;i<n;i++){
		item it;
		cin>>it.wt>>it.val;
		a.push_back(it);
	}
	cout<<maxCost()<<endl;
}

Measured memory_bytes: 78336
import math
n, d = map(int, input().split())

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

count = 0
for r in lis:
    distance = r[0] ** 2 + r[1] ** 2
    distance = math.sqrt(distance)
    if distance <= d:
        count += 1
    
print(count)

Measured memory_bytes: 45460
//#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<cstdio>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<utility>
#include<algorithm>
#include<cstring>
#include<sstream>
#include <iomanip>

using namespace std;

typedef long long ll ;
typedef double db;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector< pair<int,int> > vii;
const double pi = 2*acos(0) ;

#define pf		  	printf
#define sf			  scanf
#define pb(a)         push_back(a)
#define mp			make_pair
#define fi			 first
#define se			 second
#define for0(i,n)        for(int i=0;i<n;i++)
#define for1(i,n)        for(int i=1;i<=n;i++)
#define forab(i,a,b)       for(int i=a;i<=b;i++)
#define lcm(a, b)     ((a)*((b)/gcd(a,b)))
#define sq(a)		   (a)*(a)
#define nw				"\n"
#define abs(x)		fabs(x)
#define pcase(z,x)    cout<<"Case "<<z<<": "<<x<<"\n"
int main()
{
	int k,s,x,y,z,c=0;
	cin>>k>>s;
	�forab(x,0,k){
		forab(y,0,k){
			z = s - x - y;
			if(z>=0 && z<=k) c++;
			}
		}
	cout<<c<<nw;
	return 0;
}

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

vector<int> a;
int n, k;

int check(int p)
{
	int i = 0;
	for(int j = 0; j < k; j++)
	{
		long long s = 0;
		while(s + a[i] <= p)
		{
			s += a[i];
			i++;
			if(i == n) return n;
		}
	}
	return i;
}

int getMinP()
{
	int low = 0, high = 100000 * 10000, mid;
	while(low <= high)
	{
		mid = (low + high) / 2;
		int t = check(mid);//当p=mid时候，看看怎么样
		if(t >= n)
			high = mid - 1;
		else
			low = mid + 1;
	}
	return low;
}

int main()
{
	int tmp;
	
	cin>>n>>k;
	for(int i = 0; i < n; i++)
	{
		cin>>tmp;
		a.push_back(tmp);
	}
	cout<<getMinP()<<endl;
}


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


typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
	stringstream ss;
	ss << f;
	ss >> t;
}


#define REP(i,n) for(int i=0;i<int(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define RALL(v) (v).rbegin(),(v).rend()
#define PB push


#define MOD 1000000007LL
#define EPS 1e-10

int main()
{
    int N, M;
    cin >> N >> M;
    int L[M];
    REP(i, M) L[i] = 0;
    int K, A;
    REP(i, N)
    {
        cin >> K;
        REP(j, K)
        {
            cin >> A;
            ++L[A - 1];
        }
    }
    int ans = 0;
    REP(i, M)
    {
        if(L[i] == N) ++ans;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
mod = pow(10,9)+7

r,c = list(map(int,input().split()))
arr = []
for i in range(r):
    string = input()
    lista = []
    for i in string:
        lista.append(i)
    arr.append(lista)

dp = [ [ 0 for i in range(c)] for j in range(r)]

for i in range(r):
    if(arr[i][0] == '#'):
        break
    
    dp[i][0] = 1

for i in range(c):
    if(arr[0][i] == '#'):
        break
    dp[0][i] = 1

for i in range(1,r):
    for j in range(1,c):
        if(arr[i-1][j] == '.'):
            dp[i][j] += dp[i-1][j]
        if(arr[i][j-1] == '.'):
            dp[i][j] += dp[i][j-1]

print(dp[r-1][c-1]%mod)


Measured memory_bytes: 166180
#include <algorithm>
#include <iostream>
#include <numeric>
#include <string>
#include <utility>
#include <vector>

int main() {
  int n;
  std::string s;
  std::cin >> n;
  std::vector<std::size_t> min_counter(26, 1e8);
  for (std::size_t i = 0; i < std::size_t(n); ++i) {
    std::vector<std::size_t> counter(26, 0);
    std::cin >> s;
    for (auto c : s) ++counter[c - 'a'];
    for (int i = 0; i < 26; ++i) min_counter[i] = std::min(min_counter[i], counter[i]);
  }
  for (int i = 0; i < 26; ++i) std::cout << std::string(min_counter[i], 'a' + i);
  std::cout << std::endl;
  return 0;
}

Measured memory_bytes: 888
from itertools import groupby, accumulate, product, permutations, combinations
def solve():
  N = int(input())
  A = list(map(int, input().split()))
  cum = [0]+list(accumulate(A))
  dp = [[float('inf')]*N for _ in range(N)]
  for i in range(N):
    dp[i][i] = 0
  for i in range(N-1):
    dp[i][i+1] = A[i]+A[i+1]
  for k in range(2,N):
    for i in range(N):
      j = i+k
      if j>N-1:
        break
      for l in range(i,j):
        dp[i][j] = min(dp[i][j],dp[i][l]+dp[l+1][j])
      dp[i][j] += cum[j+1]-cum[i]
  ans = dp[0][-1]
  return ans
print(solve())

Measured memory_bytes: 79468
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
typedef long long int ll;
using namespace std;
using Graph = vector<vector<int> >;

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int N;
cin>>N;
string ans="No";
if(N>0 && N<=81){
    reps(i,10,1){
        if(N%i==0){
            int b=N/i;
            if(b<10){
                ans="Yes";
            }
        }
    }
}
cout<<ans<<endl;
//system("pause");
return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

void readInt(int *x) {
	scanf("%d", x);
	return;
}
void readInts(int n, int arr[]) {
	int i;
	for (i=0;i<n;i++) {
		readInt(&arr[i]);
	}
}
void readChar(char *x) {
	scanf("%c", x);
	return;
}
void readChars(char x[]) {
	scanf("%s", x);
	return;
}
void printInts(int n, int *arr) {
	int i;
	for (i=0;i<n;i++) {
		printf("%d ", arr[i]);
	}
	printf("\n");
	return;
}

int main(int argc, char const *argv[])
{
	char s[11], t[11], u[11];
	int a, b;
	readChars(s);
	readChars(t);
	readInt(&a);
	readInt(&b);
	readChars(u);

	if (!strcmp(s,u)) {
		printf("%d %d\n", --a, b);
	}else{
		printf("%d %d\n", a, --b);
	}

	return 0;
}

Measured memory_bytes: 128
# coding: utf-8
# Your code here!
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline #文字列入力のときは注意

#n = int(input())
#s = input()
#a = [int(i) for i in readline().split()]
#m = [[int(i) for i in readline().split()] for _ in range(n)]

m1,d1 = [int(i) for i in readline().split()]
m2,d2 = [int(i) for i in readline().split()]


if m1 == m2: print(0)
else: print(1)

Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(i=0;i<n;i++)
#define pb push_back
#define all(a) a.begin(),a.end()
#define fi first
#define se second
int M=1e9+7;
int mm(int x,int y){x%=M,y%=M;return (x*y)%M;}//Modular Multiply
int po(int x,int y){ if(!y)return 1;int a=po(x,y/2)%M;if(y%2)return mm(a,mm(a,x));return mm(a,a);}//(x**y)%M

signed main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	//string s;
	int x,p,q;
	cin>>x;
	int a[2002];
	for(int i=0;i<=2001;i++) a[i]=pow(i-1000,5);
	for(int i=0;i<=2001;i++){
		for(int j=0;j<=2001;j++){
			if(a[i]-a[j]==x) p=i-1000,q=j-1000; 
		}
	}
	cout<<p<<" "<<q;
	return 0;
}




Measured memory_bytes: 4128
import sys
import itertools
if sys.platform =='ios':
    sys.stdin=open('input_file.txt')
    
n,x,y=map(int,input().split())


l1=n-y-x
l2=y-x

l=[0]*(n-1)
k=0
for i in range(1,n):
	for j in range(i+1,n+1):
		k=min(j-i,abs(i-x)+1+abs(j-y),abs(i-y)+1+abs(j-x))
		l[k-1]+=1
		k=0

for j in range(n-1):
	print(l[j])	

		
	

Measured memory_bytes: 48220
import sys
sys.setrecursionlimit(10**9)

def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))

INF=10**20
class Counting():
    def __init__(self,maxim,mod):
        maxim += 1

        self.mod = mod
        self.fact = [0]*maxim
        self.fact[0] = 1
        for i in range(1,maxim):
            self.fact[i] = self.fact[i-1] * i % mod

        self.invfact = [0]*maxim
        self.invfact[maxim-1] = pow(self.fact[maxim-1],mod-2,mod)
        for i in reversed(range(maxim-1)):
            self.invfact[i] = self.invfact[i+1] * (i+1) % mod


    def nCk(self,n,r):
        if n < 0 or n < r: return 0
        return self.fact[n] * self.invfact[r] * self.invfact[n-r] % self.mod

    def nPk(self,n,r):
        if n < 0 or n < r: return 0
        return self.fact[n] * self.invfact[n-r] % self.mod

        

def main():
    N,M=mi()
    MOD=10**9+7

    if N == 1:
        print(1)
        exit()
    
    def prime_factorize(n):
        P = []
        P_set = set()
        while n % 2 == 0:
            P.append(2)
            P_set.add(2)
            n //= 2
        f = 3
        while f * f <= n:
            if n % f == 0:
                P.append(f)
                P_set.add(f)
                n //= f
            else:
                f += 2
        if n != 1:
            P.append(n)
            P_set.add(n)

        P_count = {p:0 for p in P_set}
        for p in P: P_count[p] += 1

        return P_count


    
    ans = 1
    counting = Counting(3*10**5+10,MOD)
    for p,e in prime_factorize(M).items():
        ans *= counting.nCk(e+N-1,e)
        ans %= MOD

    
    print(ans % MOD)



if __name__ == "__main__":
    main()

Measured memory_bytes: 74528
import java.lang.*;
import java.io.*;
import java.util.*;


public class Main {

	public static void main(String[] args) throws java.lang.Exception {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskA solver = new TaskA();
		solver.solve(in, out);
		out.close();
	}
}

class TaskA {

	public void solve(InputReader in, PrintWriter out) {
		int k = in.nextInt(), s = in.nextInt();
		int x, y, z;
		int ans = 0;

		for (x=0; x<=k&&x<=s; ++x) {
			for (y=0; y<=k&&x+y<=s; ++y) {
				z = s - (x + y);
				if (z>=0 && z<=k)
					++ans;
			}
		}

		out.println(ans);
	}
}


class InputReader {
	public BufferedReader reader;
	public StringTokenizer tokenizer;


	public InputReader(InputStream stream) {
		reader = new BufferedReader(new InputStreamReader(stream), 32768);
		tokenizer = null;
	}

	public String next() {
		while (tokenizer==null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(reader.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}

	public int nextInt()  {
		return Integer.parseInt(next());
	}

	public long nextLong() {
		return Long.parseLong(next());
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}


Measured memory_bytes: 21460
n = int(input())
a = list(map(int, input().split()))

flag= True
ans=1
for i in range(n):
    ans*=a[i]
    if ans>10**18:
        flag=False
        break

if flag:
    print(ans)
else:
    if 0 in a:
        print(0)
    else:
        print(-1)

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

int main ()
{
	int A, B, C;
	scanf ("%d %d %d", &A, &B, &C);
	int x=0;
	int y=C-A+B;
	if (y>x) printf ("%d\n", y);
	else printf ("%d\n", x);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100100;
int n;
vector<int> vec[maxn];
int vis[maxn];
int dis;
int endpoint;
int score1;

bool dfs(int i, int count) {
	if(i == n) {
		dis = count;
		return true;
	}
	for(int j = 0; j < vec[i].size(); j++) {
		if(!vis[vec[i][j]]) {
			vis[vec[i][j]] = 1;
//			printf("%d\n", vec[i][j]);
			if(dfs(vec[i][j], count + 1)) {
				if(count + 1 == (dis + 1) / 2 + 1) {
					endpoint = vec[i][j];
				}
				return true;
			}
		}
	}
	return false;
} 

void Fennec(int i) {
	for(int j = 0; j < vec[i].size(); j++) {
		if(!vis[vec[i][j]]) {
			if(vec[i][j] == endpoint) continue;
			else {
				vis[vec[i][j]] = 1;
				score1++;
				Fennec(vec[i][j]);
			}
		}
	}
}

int main() {
	while(~scanf("%d", &n)) {
		for(int i = 1; i <= n; i++) vec[i].clear();
		memset(vis, 0, sizeof(vis));
		dis = -0x3f3f3f3f;
		endpoint = 0;
		for(int i = 1; i < n; i++) {
			int a, b;
			scanf("%d%d", &a, &b);
			vec[a].push_back(b);
			vec[b].push_back(a);
		}
		vis[1] = 1;
		dfs(1, 1);
		memset(vis, 0, sizeof(vis));
		vis[1] = 1;
		score1 = 1;
		Fennec(1);
//		printf("%d\n", endpoint);
		if(score1 > n - score1) puts("Fennec");
		else puts("Snuke");
	}
	return 0;
} 

Measured memory_bytes: 13952
#include<cstdio>
#include<iostream>
using namespace std;
int main(){
	int a,b;
	cin>>a>>b;
	if(a<0&&b<0){
		if((b-a+1)%2==0) printf("Positive");
		else printf("Negative");
	}else if(a==0||b==0) printf("Zero");
	else if(a<0&&b>0) printf("Zero");
	else printf("Positive");
}

Measured memory_bytes: 256
#include <math.h>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <iomanip>
#include <iterator>
#include <algorithm>
#include <functional>
#include <typeinfo>
#include <utility>
#include <tuple>
#include <queue>
#include <deque>

using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define reprrev(i, a, b) for (int i = (int)(b) - 1; i >= (int)(a); i--)
#define reprev(i, n) reprrev(i, 0, n)
#define mp(a, b) make_pair(a, b)
#define all(vec) (vec).begin(), (vec).end()
#define yn(formula) (formula) ? (cout << "Yes" << endl) : (cout << "No" << endl)
#define YN(formula) (formula) ? (cout << "YES" << endl) : (cout << "NO" << endl)
#define MIN(a, b) ((a) < (b)) ? (a) : (b)

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pii> vp;
typedef vector<pll> vpl;
typedef vector<vi> vvi;
typedef vector<vll> vvl;
typedef vector<vb> vvb;
typedef vector<vc> vvc;
typedef vector<vs> vvs;
typedef vector<vp> vvp;
typedef vector<vpl> vvpl;

constexpr double PI = 3.14159265358979323846;
constexpr ll INF = 1 << 29;
constexpr ll MOD = (ll)1e9 + 7;
constexpr double EPS = 1e-7;
constexpr int dy[4] = { 0, 1, 0, -1 };
constexpr int dx[4] = { 1, 0, -1, 0 };

struct edge { ll to; ll cost; };

/*<ここから>***********************************************************/


int main()
{
	int N, X;
	cin >> N >> X;
	vi m(N);
	int sum = 0;
	rep(i, N) {
		cin >> m[i];
		sum += m[i];
	}

	sort(all(m));

	X -= sum;

	int ans = N;
	ans += X / m[0];
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.util.stream.Collectors;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        List<Integer> H = new ArrayList<>(N);
        for(int i=0;i<N;i++){
            H.add(sc.nextInt());
        }
        Collections.sort(H, Comparator.comparingInt(a -> a));
        if(N < K){
            System.out.println(0);
        }else {
            long res = H.stream().limit(N - K).collect(Collectors.summingLong(Integer::longValue));
            System.out.println(res);
        }
    }
}


Measured memory_bytes: 96512
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int X = sc.nextInt(), A = sc.nextInt(), B = sc.nextInt();
		if(X > B) System.out.println("delicious");
		else if(X >= B-A) System.out.println("safe");
		else System.out.println("dangerous");
	}
}


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

int main(){
    int n;
    cin >> n;
    vector< vector<int> > G(n);
    vector<pii> vp;

    for(int i=1;i<n;i++){
        int a,b;
        cin>>a>>b;
        a--;b--;
        G[a].emplace_back(b);
        G[b].emplace_back(a);
        vp.emplace_back(a,b);
    }

    int K=0;

    vector<int> cs(n,0);
    vector<int> used(n,0);
    used[0]=1;

    map< pii ,int> I;
    queue<int> que;
    que.emplace(0);
    while(!que.empty()){
        int v=que.front();que.pop();
        if(K<(int)G[v].size()) K = G[v].size();
        
        int cur=1;
        for(int u:G[v]){
            if(used[u]) continue;
            if(cs[v]==cur) cur++;
            cs[u]=I[make_pair(u,v)]=I[make_pair(v,u)]=cur;
            cur++;
            used[u]=1;
            que.emplace(u);
        }
    }

    cout<<K<<endl;
    for(auto p:vp) cout << I[p] << endl;
    return 0;
}

Measured memory_bytes: 20084
using System;
using System.Collections.Generic;
using System.Numerics;
using System.Linq;
using static System.Math;

class MainClass
{

    public static void Main(string[] args)
    {
        var s = LnStr();
        if (s[0] == s[1]&&s[1] == s[2]&&s[2]==s[0])
        {
            print("No");
        }
        else
        {
            print("Yes");
        }
    }



    public static void print(object obj) { Console.WriteLine(obj); }
    public static long Gcd(long a, long b) { if (a > b) { var r = a % b; if (r == 0) return b; else return Gcd(b, r); } else { var r = b % a; if (r == 0) return a; else return Gcd(a, r); } }
    public static int Gcd(int a, int b) { if (a > b) { var r = a % b; if (r == 0) return b; else return Gcd(b, r); } else { var r = b % a; if (r == 0) return a; else return Gcd(a, r); } }
    public static int[] LnInts() { var vs = Console.ReadLine().Trim().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); var ins = new int[vs.Length]; for (int i = 0; i < vs.Length; i++) ins[i] = int.Parse(vs[i]); return ins; }
    public static int LnInt() { var vs = Console.ReadLine().Trim(); return int.Parse(vs); }
    public static long[] LnLngs() { var vs = Console.ReadLine().Trim().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); var ins = new long[vs.Length]; for (int i = 0; i < vs.Length; i++) ins[i] = long.Parse(vs[i]); return ins; }
    public static long LnLng() { var vs = Console.ReadLine().Trim(); return long.Parse(vs); }
    public static string[] LnStrs() { var vs = Console.ReadLine().Trim().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); return vs; }
    public static string LnStr() { var vs = Console.ReadLine().Trim(); return vs; }
}

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

int main() {
	int a, b;
	cin >> a >> b;
	rep(i, 10000) {
		int ta = i * 8 / 100;
		int tb = i * 10 / 100;
		if (a == ta && b == tb) {
			cout << i << endl;
			return 0;
		}
	}

	cout << -1 << endl;
	return 0;
}

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

int w[110],v[110];
long long int dp[110000];
int INF = 1000000009;

int N,W;
int main () {
    for(int i=0; i<100001; i++) dp[i] = INF;
    cin >> N >> W;
    for(int i=0; i<N; i++) {
        cin >> w[i] >> v[i];
    }
    dp[0] = 0;
    for(int i=0; i<N; i++) {
        for(int j=100000; j >= v[i]; j--) {
            dp[j] = min( dp[j], dp[j - v[i] ] + w[i]);
        }
    }
    int ans = 0;
    for(int i=0; i<100001; i++) {
        if(  dp[i] <= W ) {
        ans = max( ans, i);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iomanip>
#include <iostream>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main(void) {
  ios::sync_with_stdio(false);
  int N;
  cin >> N;

  int A[20];
  rep(i, N) {
    cin >> A[i];
    A[i]--;
  }
  int B[20];
  rep(i, N) { cin >> B[i]; }
  int C[20];
  rep(i, N - 1) { cin >> C[i]; }

  int Ans = 0;
  int Prev;
  rep(i, N) {
    Ans += B[A[i]];
    if (i >= 1) {
      if ((A[i] - Prev) == 1) Ans += C[A[i] - 1];
    }
    Prev = A[i];
  }
  cout << Ans << endl;
  return 0;
}


Measured memory_bytes: 256
import sys
 
def shuffle( cards ):
    h = int( sys.stdin.readline() )
    cards = cards[ h : ] + cards[ 0 : h ]
    return cards
 
while True:
    cards = sys.stdin.readline().rstrip()
    if '-' == cards:
        break
    m = int( sys.stdin.readline() )
    for i in range( m ):
        cards = shuffle( cards )
    print( cards )

Measured memory_bytes: 7676
N=int(input())
a=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']

name=[]

for i in range (20):
    N=N-1
    name.insert(0,a[N%26])
    N=N//26
    if N==0:
        break

print(''.join(name))

Measured memory_bytes: 9136
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <math.h>
#include <string>
#include <math.h>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> Q;

const ll mod = 1000000007;
const ll INF = 1000000000000;




int main()
{
	ll n;
	double a[110];
	ll sek = 1;

	cin >> n;

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

	double ans = (double)sek;
	
	double sum = 0;

	for (int i = 0; i < n; i++)
	{
		sum += sek / a[i];
	}

	ans /= sum;

	cout << setprecision(10) << ans << endl;

	int www;
	cin >> www;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
int main() {
  int n;
  scanf("%d", &n);
  
  int *h = (int *)malloc(sizeof(int) * n);
  
  for (int i = 0; i < n; i++) {
    scanf("%d", &h[i]);
  }
  
  int max;
  int num = 0;
  for (int i = 0; i < n-1; i++) {
    if (h[i] >= h[i+1]) {
      num++;
    }
    else {
      num = 0;
    }
    if (max < num) {
      max = num;
    }
  }
  printf("%d", max);
  
  return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define pb push_back
#define f first
#define s second
#define PI 3.14159265358979
signed main()
{
      double a,b,h,m;
      cin>>a>>b>>h>>m;
      double t1=(360*h+m*6);
      double t2=(30*h+.5*m);
      double t= abs(t1-t2);
      if(t>180)
        t=360-t;
        double k=7;

      printf("%0.11f",sqrt(pow(a,2)+pow(b,2)-2*a*b*cos(t*PI/180.0)));
}


Measured memory_bytes: 4228
#include<stdio.h>
int a, b, c;
int main(void){
  scanf("%d%d%d", &a, &b, &c);
  if(a<c && c<b){
    puts("Yes");
  }else if(b<c && c<a){
    puts("Yes");
  }else{
    puts("No");
  }
}


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

using ll = long long;

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

    string S;
    cin >> S;


    string T;
    for (int i = 0; i < S.size(); ++i) {
        char s = S[i];
        if (s == 'A') {
            T += s;
        } else if (s == 'B' && i < S.size() - 1 && S[i + 1] == 'C') {
            T += 'D';
            ++i;
        } else {
            T += s;
        }
    }

    ll total = 0;
    ll A = 0;
    ll D = 0;
    for (char t : T) {
        if (t == 'A') {
            if (D > 0) {
                total += A * D;
                D = 0;
            }
            A++;
        } else if (t == 'D' && A > 0) {
            D++;
        } else {
            total += A * D;
            A = 0;
            D = 0;
        }

    }
    total += A * D;

    cout << total << '\n';

    return 0;
}


Measured memory_bytes: 916
def main():
    n = int(input())
    A = list(map(int, input().split()))
    n = max(A)
    tmp = float("inf")
    r = 0
    for x in A:
        if abs(n-x*2) < tmp and x != n:
            tmp = abs(n-x*2)
            r = x
    print(n, r)


if __name__ == "__main__":
    main()


Measured memory_bytes: 62704
#include <stdio.h>
#define MAX 100005
#define NIL -1

typedef struct Node {
  int p;
  int l;
  int r;
}Node;

Node T[MAX];

int n,D[MAX],H[MAX];


int setHeight(int u){

  int h1=0,h2=0;

  if(T[u].l!=NIL) h1=setHeight(T[u].l)+1;
  if(T[u].r!=NIL) h2=setHeight(T[u].r)+1;

  return H[u]=(h1>h2?h1:h2);
}


void setDepth(int u,int p){
  if(u==NIL) return;

  D[u]=p;
  setDepth(T[u].r,p+1);
  setDepth(T[u].l,p+1);
}

int getSibling(int u){

  if(T[u].p==NIL) return NIL;

  if(T[T[u].p].l!=u && T[T[u].p].l!=NIL){
    return T[T[u].p].l;
  }

  if(T[T[u].p].r!=u && T[T[u].p].r!=NIL){
    return T[T[u].p].r;
  }

  return NIL;
}

int main(){
  int v,l,r,i,root=0,deg=0;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    T[i].p=NIL;
  }

  for(i=0;i<n;i++){

    scanf("%d %d %d", &v, &l, &r);

    T[v].l=l;
    T[v].r=r;

    if(l!=NIL)T[l].p=v;
    if(r!=NIL)T[r].p=v;

}
  for(i=0;i<n;i++){
    if(T[i].p==NIL) root=i;
  }

  setDepth(root,0);
  setHeight(root);

  for(i=0;i<n;i++){

    printf("node %d: parent = %d, sibling = %d, ",i,T[i].p,getSibling(i));

    if(T[i].l!=NIL)deg++;
    if(T[i].r!=NIL)deg++;

    printf("degree = %d, depth = %d, height = %d, ",deg,D[i],H[i]);

    if(T[i].p==NIL)printf("root");
else if(T[i].l==NIL&&T[i].r==NIL)printf("leaf");
    else printf("internal node");

    printf("\n");
    deg=0;
  }

  return 0;
}


Measured memory_bytes: 2108
//
// Created by Hideaki Imamura on 2020-03-21.
//
# include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair <ll, ll> l_l;
typedef pair<int, int> i_i;

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

# define EPS (1e-7)
# define INF (1e9)
# define PI (acos(-1))
const ll mod = 1000000007;
ll fact[200000];
ll invfact[200000];

inline ll take_mod(ll a) {
    return (a % mod + mod) % mod;
}

inline ll add(ll a, ll b) {
    return take_mod(a + b);
}

inline ll sub(ll a, ll b) {
    return take_mod(a - b);
}

inline ll mul(ll a, ll b) {
    return take_mod(a * b);
}

inline ll mod_pow(ll x, ll n) {
    ll res = 1LL;
    while (n > 0) {
        if (n & 1) res = mul(res, x);
        x = mul(x, x);
        n >>= 1;
    }
    return res;
}

ll mod_inv(ll x) {
    return mod_pow(x, mod - 2);
}

// nは上限
void make_fact(ll n){
    fact[0] = 1;
    ll res = 1;
    for(int i = 1; i <= n; i++){
        fact[i] = res;
        res = mul(res, i+1);
    }
}

// nは上限
void make_invfact(ll n){
    invfact[0] = 1;
    invfact[n] = mod_inv(fact[n]);
    for(int i = n-1; i >= 1; i--){
        invfact[i] = mul(invfact[i + 1], i + 1);
    }
}

ll perm(ll n, ll k){
    return mul(fact[n], invfact[n-k]);
}

ll comb(ll n, ll k){
    return mul(mul(fact[n], invfact[n-k]), invfact[k]);
}

ll N, K;
vector<ll> A;

int main() {
    cin >> N >> K;
    A.resize(N);
    make_fact(N * 2);
    make_invfact(N * 2);
    for (int i = 0; i < N; ++i) cin >> A[i];
    sort(A.begin(), A.end(), greater<ll>());

    ll ans = 0;
    for (int i = 1; i <= N - K + 1; ++i) ans = add(ans, mul(A[i-1], comb(N - i, K - 1)));
    for (int i = K; i <= N; ++i) ans = sub(ans, mul(A[i-1], comb(i - 1, K - 1)));
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4096