akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cctype>
#include<climits>
#include<bitset>
#define ld long double
#define ll long long int
#define ull unsigned long long int
#define rep(i,n) for(i=0;i<n;i++)
#define fin(ans) cout<<(ans)<<endl
#define INF INT_MAX
#define vi vector<int>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pair<int,int> >
#define vvi vector<vector<int> >
#define vvc vector<vector<char> >
#define vvs vector<vector<string> >
#define P 1000000007
using namespace std;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const long long LLINF=1LL<<60;
//set<int>::iterator it;
//|\_
//g++ -std=c++1z temp.cpp
//./a.out





int main(void){ios::sync_with_stdio(false);cin.tie(0);
//////////////////////////////////////////////////////
    int h,w,i,j,n;
    cin>>h>>w>>n;
    vector<int> a(n,0);
    vector<int> num;
    rep(i,n)cin>>a[i];
    rep(i,n)rep(j,a[i])num.push_back(i+1);
    
    vvi ans(h,vi(w,0));
    int p=0;
    rep(i,h){
        if(i%2==0){
            rep(j,w){
                ans[i][j]=num[p];
                p++;
            }
        }
        else{
            for(j=w-1;j>=0;j--){
                ans[i][j]=num[p];
                p++;
            }
        }
    }
    rep(i,h){
        rep(j,w){
            if(j!=w-1)cout<<ans[i][j]<<" ";
            else cout<<ans[i][j]<<endl;
        }
    }
//////////////////////////////////////////////////////
return 0;}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main() {
	pair<int,int> a[6];for(int i=0;i<6;i++){
		cin>>a[i].first>>a[i].second;
		if(a[i].first>a[i].second){
			int tmp=a[i].first;
			a[i].first=a[i].second;
			a[i].second=tmp;
		}
	}
	sort(a,a+6);
	set<int>s;
	if(a[0]==a[1]){
		s.insert(a[0].first);
		s.insert(a[1].second);
		if(a[2]==a[3]){
			s.insert(a[2].first);
			s.insert(a[3].second);
			if(a[4]==a[5]){
				s.insert(a[4].first);
				s.insert(a[5].second);
				if(s.size()==1)cout<<"yes\n";
				else if(s.size()==2){
					if(a[0]==a[2]&&a[2]==a[4])cout<<"no\n";
					else cout<<"yes\n";
				}
				else if(s.size()==3){
					for(int i=0;i<6;i++){
						if(a[i].first==a[i].second){
							cout<<"no\n";
							return 0;
						}
					}
					cout<<"yes\n";
				}
				else cout<<"no\n";
			}else cout<<"no\n";
		}else cout<<"no\n";
	}else cout<<"no\n";
	return 0;
}

Measured memory_bytes: 3092
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int n, m, x, y;
int Rank[100001];
int parent[100001];

int find(int x);
bool isSame(int x, int y);
void unite(int x, int y);


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

    vector<int> p(n+1, 0);
    for (int i = 1; i <= n; i++) {
        cin >> p[i];
    }
    
    for (int i = 1; i <= n; i++ ) {
        Rank[i] = 0;
        parent[i] = i;
    }

    for (int i = 0; i < m; i++) {
        cin >> x >> y;
        
        if (!isSame(x, y)) 
            unite(x, y);
    }

    int ans = 0;
    for (int i = 1; i <= n; i++) {
        if (isSame(i, p[i]))
                ans++;
    }

    cout << ans << '\n';


}


int find(int x) {
    if (x == parent[x]) return x;
    else {
        return parent[x] = find(parent[x]);
    }
}

bool isSame(int x, int y) {
    return find(x) == find(y);
}

void unite(int x, int y) {
    x = find(x);
    y = find(y);

    if (x == y) return;

    if (Rank[x] < Rank[y]) {
        parent[x] = y;
    } 
    else {
        parent[y] = x;
        if (Rank[x] == Rank[y]) 
            Rank[x]++;
    }
}


Measured memory_bytes: 1408
import java.util.*;
public class Main {
	static Scanner sc = new Scanner(System.in);
	static int n;
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO ツ篠ゥツ督ョツ青カツ青ャツつウツづェツつスツδソツッツドツ・ツスツタツブ
		while(read()){
			slove();
		}
	}
	static boolean read(){
		if(!sc.hasNext())
			return false;
		n = sc.nextInt();
		return true;
	}
	static void slove(){
		int ans = n*(n+1)/2 + 1;
		System.out.println(ans);
	}
}

Measured memory_bytes: 12000
#include <algorithm>
#include <functional>
#include <iostream>
#include <vector>

template <class T>
int binary_search(const std::vector<T> &values, const std::function<bool(T)> &func)
{
	int N = values.size();
	int a = 0;
	int b = values.size() - 1;
	if ( func(values[0])) { return 0; }
	if (!func(values[b])) { return N; }
	while (b - a > 1)
	{
		int m = (a + b) / 2;
		if (func(values[m])) { b = m; }
		else                 { a = m; }
	}
	return b;
}

int count(int N, const std::vector<int> &A, const std::vector<int> &B, int mask)
{
	std::vector<int> X(N);
	std::vector<int> Y(N);
	auto mod = [&](int b) { return b & (mask * 2 - 1); };
	std::transform(A.begin(), A.end(), X.begin(), mod);
	std::transform(B.begin(), B.end(), Y.begin(), mod);
	std::sort(Y.begin(), Y.end());
	int cnt = 0;
	for (int x : X)
	{
		int n1 = binary_search<int>(Y, [&](int y) { return y >= 1 * mask - x; });
		int n2 = binary_search<int>(Y, [&](int y) { return y >= 2 * mask - x; });
		int n3 = binary_search<int>(Y, [&](int y) { return y >= 3 * mask - x; });
		int n4 = binary_search<int>(Y, [&](int y) { return y >= 4 * mask - x; });
		cnt += std::max(n2 - n1, 0);
		cnt += std::max(n4 - n3, 0);
	}
	return cnt;
}

int solve(int N, const std::vector<int> &A, const std::vector<int> &B)
{
	int res = 0;
	for (int mask = 1; mask < 1 << 29; mask <<= 1)
	{
		if ((count(N, A, B, mask) & 1) != 0) { res |= mask; }
	}
	return res;
}

int main()
{
	int N;
	std::cin >> N;
	std::vector<int> A(N);
	std::vector<int> B(N);
	for (int i = 0; i < N; ++i) { std::cin >> A[i]; }
	for (int i = 0; i < N; ++i) { std::cin >> B[i]; }
	std::cout << solve(N, A, B);
}


Measured memory_bytes: 3432
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e5+10;
int gcd(int a,int b){
	if(!b) return a; else return gcd(b,a%b);
}
int a[maxn];	
int main() {
	int n, x;
	scanf("%d%d",&n,&a[0]);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	sort(a,a+1+n);
	int ans=a[1]-a[0]; 
	for(int i=1;i<=n;i++) 
		 ans=gcd(ans,a[i]-a[i-1]);
	printf("%d\n",ans);
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rrep(i, a, b) for (int i = a; i >= (b); i--)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <class T>
inline bool chmin(T& a, T b) {
   if (a > b) {
      a = b;
      return true;
   }
   return false;
}
template <class T>
inline bool chmax(T& a, T b) {
   if (a < b) {
      a = b;
      return true;
   }
   return false;
}
void hr() {
   cerr << "--------------" << endl;
}
const int INF = 1001001001;
const int MOD = 1000000007;
// const int MOD = 998244353;

int sqr[100][100];
int ans;
void dfs(int x, int y, int d = 1) {
   sqr[x][y] = 0;
   if (sqr[x][y - 1]) dfs(x, y - 1, d + 1);
   if (sqr[x][y + 1]) dfs(x, y + 1, d + 1);
   if (sqr[x - 1][y]) dfs(x - 1, y, d + 1);
   if (sqr[x + 1][y]) dfs(x + 1, y, d + 1);
   if ((sqr[x][y - 1] || sqr[x][y + 1] || sqr[x + 1][y] || sqr[x - 1][y]) ==
       0) {
      chmax(ans, d);
   }
   sqr[x][y] = 1;
}
int main() {
   cin.tie(0);
   ios_base::sync_with_stdio(0);

   while (true) {
      ans = 0;
      int m, n;
      cin >> m >> n;
      if (m == 0 && n == 0) break;
      rep(i, 0, m + 2) {
         rep(j, 0, n + 2) {
            if (i == 0 || i == m + 1 || j == 0 || j == n + 1)
               sqr[i][j] = 0;
            else {
               int c;
               cin >> c;
               sqr[i][j] = c;
            }
         }
      }

      rep(i, 1, n + 1) {
         rep(j, 1, m + 1) {
            if (sqr[i][j]) dfs(i, j);
         }
      }
      cout << ans << endl;
   }
   return 0;
}


Measured memory_bytes: 3128
/*
    Created by Rahul Goel.
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
/*******************************************************************************/
using namespace std;
using namespace __gnu_pbds;
template < typename T >
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
/*******************************************************************************/
using ll = long long;
using ld = long double;
const ll MOD = 1000000007;
// const ll MOD = 998244353;
const int INF = 1e9;
const ll LINF = 1e18;
/*******************************************************************************/
ll mod_sum() { return 0LL; }
template < typename T, typename... Args >
T mod_sum(T a, Args... args) { return ((a + MOD_sum(args...))%MOD + MOD)%MOD; }
/*******************************************************************************/
ll mod_prod() { return 1LL; }
template< typename T, typename... Args >
T mod_prod(T a, Args... args) { return (a*MOD_prod(args...))%MOD; }
/*******************************************************************************/
#ifdef ONLINE_JUDGE
#define endl '\n'
#endif
#define fastio          ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define all(c)          (c).begin(), (c).end()
#define present(c,x)    ((c).find(x) != (c).end())
#define cpresent(c,x)   (find(all(c),x) != (c).end())
#define uniq(c)         (c).resize(distance((c).begin(), unique(all(c))))
#define min_pq(t)       priority_queue < t, vector < t >, greater < t > >
#define max_pq(t)       priority_queue < t >
#define pb              push_back
#define ff              first
#define ss              second
/*******************************************************************************/
using pii = pair < ll, ll >;
using vi = vector < ll >;
using vb = vector < bool >;
using vvi = vector < vector < ll > >;
using vvb = vector < vector < bool > >;
using vpii = vector < pii >;
using vvpii = vector < vector < pii > >;
/*******************************************************************************/
//.-.. . -. -.- .- .. ... .-.. --- ...- .
/*
    Code begins after this.
*/

ll solve() {
    ll n, k;
    cin >> n >> k;

    vi vec(n);
    for (ll &x : vec) {
        cin >> x;
    }

    if (k == 0) {
        cout << *max_element(all(vec)) << endl;
        return 0;
    }

    ll start = 1, end = INF, mid, ans = -1;
    while (start <= end) {
        mid = (start + end) >> 1;

        ll op = 0;
        for (ll &x : vec) {
            if (x > mid) {
                op += x / mid;
            }
        }

        if (op <= k) {
            ans = mid;
            end = mid - 1;
        } else {
            start = mid + 1;
        }
    }

    cout << ans << endl;

    return 0;
}

signed main() {
    fastio;

    ll t = 1;
    while (t--) {
        solve();
    }
    return 0;
}


Measured memory_bytes: 4764
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);

		String a = in.next();
		String b = in.next();

		if (a.equals(b)) {
			System.out.println("H");
		} else {
			System.out.println("D");
		}

	}
}

Measured memory_bytes: 21076
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <cmath>
 
using namespace std;
 
const int N = 2e5 + 10;
typedef long long LL;
int a[N];
 
 
int main()
{
	int n;
	LL sum = 0;
	scanf("%d",&n);
	for(int i = 1 ; i <= n ; i++){
		scanf("%d",&a[i]);
		sum += a[i];
	}
	if(n == 2){
		printf("%d\n",abs(a[1] - a[2]));
		return 0;
	}
	LL ans = 0;
	LL Min = (LL)1e18;
	for(int i = 1 ; i < n ; i++){
		ans += a[i];
		Min = min(Min , abs(ans - (sum - ans)));
	}
	printf("%lld\n",Min);
}

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

int main()
{
    int n,i,x;
    cin>>n;
    vector<int> a,b,c;
    int dp[3][n];
    for(i=0;i<n;i++)
    {
        cin>>x;
        a.push_back(x);
        cin>>x;
        b.push_back(x);
        cin>>x;
        c.push_back(x);
    }
    dp[0][0]=a[0];
    dp[1][0]=b[0];
    dp[2][0]=c[0];
    for(i=1;i<n;i++)
    {
        dp[0][i]=max(dp[1][i-1],dp[2][i-1])+a[i];
        dp[1][i]=max(dp[0][i-1],dp[2][i-1])+b[i];
        dp[2][i]=max(dp[1][i-1],dp[0][i-1])+c[i];
    }
    int res=dp[0][n-1]>dp[1][n-1]?(dp[0][n-1]>dp[2][n-1]?dp[0][n-1]:dp[2][n-1]):(dp[1][n-1]>dp[2][n-1]?dp[1][n-1]:dp[2][n-1]);
    cout<<res<<endl;
    return 0;
}


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

#define x first
#define y second
#define pb push_back
#define mp make_pair

#define all(a) (a).begin(), (a).end()

vector<pair<int, int>> a[15];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        while (x--) {
            int y, z;
            cin >> y >> z;
            a[i].pb({z, y-1});
        }
    }
    int ans = 0;
    for (int mask = 0; mask < (1 << n); mask++) {
        bool ok = 1;
        for (int i = 0; i < n; i++) {
            if ((mask >> i) & 1) {
                for (auto e : a[i]) {
                    int x = (mask >> e.y) & 1;
                    if (x != e.x) ok = 0;
                }
            }
        }
        if (ok) ans = max(ans, __builtin_popcount(mask));
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("unroll-loops")
#include <stdio.h>
#include <bits/stdc++.h>
using namespace std;
char s[21][(1<<20)+5];
int Arr[41943040+5],*tl=Arr;
int *sm[25][25],w0[1<<20][20],w1[1<<20][20];
int main()
{
	int n,kk;
	scanf("%d%d",&n,&kk);
	for(int i=0;i<=n;i++)
		scanf("%s",s[i]);
	for(int i=0;i<(1<<n);i++){
		if(i&1)w1[i][0]=0,w0[i][0]=-1;
		else w1[i][0]=-1,w0[i][0]=0;
		for(int j=1;j<n;j++)
			if(i>>j&1)w1[i][j]=j,w0[i][j]=w0[i][j-1];
			else w1[i][j]=w1[i][j-1],w0[i][j]=j;
	}
	for(int i=1;i<=n;i++)
		for(int j=i;j>=0;--j)
			sm[j][i]=tl,tl+=1<<i;
	cerr<<tl-Arr<<" >>\n";
	int len=0,as=0,all=(1<<20)-1;
	for(int p=n;p;--p){
		for(int i=0;i<(1<<p);i++)
			if(s[p][i]=='1')
				++sm[p][p][i];for(int i=0;i<(1<<p);i++)
		for(int j=p;j;--j)
			{
				if(j<p)sm[0][p-j][i>>j]+=sm[j][p][i];
				if(w1[i][j-1]!=-1){
					int c=w1[i][j-1];
					sm[c][p-(j-1-c)]
					[((i&(all^((1<<j)-1)))>>(j-1-c))|(i&((1<<(c+1))-1))]
					+=sm[j][p][i];
				}
				if(w0[i][j-1]!=-1){
					int c=w0[i][j-1];
					sm[c][p-(j-1-c)]
					[((i&(all^((1<<j)-1)))>>(j-1-c))|(i&((1<<(c+1))-1))]
					+=sm[j][p][i];
				}
			}
		for(int i=0;i<(1<<p);i++)
			if(sm[0][p][i]>=kk){
				len=p;
				as=i;
				break;
			}
		if(len)break;
	}
	if(!len)return 0&puts("");
	for(int i=len-1;i>=0;--i)
		printf("%d",as>>i&1);
	return 0;
}

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

#define CEIL(a,b) ((a) / (b) + ((a) % (b) == 0 ? 0 : 1))

using namespace std;
using ll = long long;
using pii = pair<int, int>;

constexpr int MOD = 1'000'000'007;
constexpr int INF = 1'000'000'001;
constexpr ll LLINF = 4'000'000'000'000'000'001;
// constexpr int INF = 2147483647; // 2 * 1e9
// constexpr ll LLINF = 9223372036854775807; // 9 * 1e18

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    int x, y;
    while(true){
        cin >> x >> y;
        if(x + y == 0) break;
        cout << min(x, y) << " " << max(x, y) << "\n";
    }
    return 0;
}


Measured memory_bytes: 3116
#include<stdio.h>
#include<math.h>
int main(void){
  
  int N;
  int s[4];
  int ct=0;
  int i;
  
  scanf("%d",&N);
  
  for(i=1;i<=3;i++){
    s[i]=(N/((int)pow(10,i-1)))%10;
    }
  
  for(i=1;i<=3;i++){
    if(s[i]==1)ct++;
  }
  
  printf("%d\n",ct);
  
  return 0;
  
}

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

using namespace std;
using boost::adaptors::reversed;
using boost::irange;
using uint = unsigned int;
using ll = long long int;
using ull = unsigned long long int;

int main() {
    ll N, K;
    cin >> N >> K;
    ll ret = 0;
    for (ll a = 1; a <= N; a++){
        ll a_con = a % K;
        ll b_con = a_con == 0 ? 0 : K - a % K;
        ll c_con = b_con;
        if ((b_con + c_con) % K != 0){
            continue;
        }
        ret += ((N + a_con) / K) * ((N + a_con) / K);
    }
    cout << ret;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int m;
    while(cin >> m, m){
        vector<int> dp(1001);
        dp[0] = 1;
        for (int i = 0; i < m; ++i) {
            int a, b;
            cin >> a >> b;
            for (int j = 1000-a*(b+1); j >= 0; --j) {
                dp[j+a*(b+1)] -= dp[j];
            }
            for (int j = 0; j+a <= 1000; ++j) {
                dp[j+a] += dp[j];
            }
        }
        int g;
        cin >> g;
        for (int i = 0; i < g; ++i) {
            int a;
            cin >> a;
            cout << dp[a] << "\n";
        }
    }
    return 0;
}


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

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define BIL ((ll)1e9)
#define MOD ((ll)1e9+7)
#define INF (1LL<<60)           //1LL<<63でオーバーフロー
#define inf (1<<29)             //1<<29でオーバーフロー

int main(int argc,char* argv[]){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);

    int h,w;
    cin >> h >> w;
    vector<string> plane(h);
    for(auto &x:plane)cin >> x;

    string sample(w,'.');
    for(int i=0;i<h;i++){
        if(sample==plane[i]){
            plane.erase(plane.begin()+i);
            i--;
            h--;
        }
    }

    set<int> jump;
    for(int i=0;i<w;i++){
        bool check=true;
        for(int j=0;j<h;j++){
            if(plane[j][i]=='#'){
                check=false;
                break;
            }
        }
        if(check)jump.insert(i);
    }

    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(jump.count(j))continue;
            cout << plane[i][j];
        }
        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 3672
#include <iostream>

int main(){
	int W,H,x,y,r;
	std::cin >> W >> H >> x >> y >> r;
	
	if((r <= x && x <= W - r) && (r <= y && y <= H - r)){
		std::cout << "Yes" << std::endl;
	}
	else{
		std::cout << "No" << std::endl;
	}
}




Measured memory_bytes: 3092
#include<bits/stdc++.h>
using namespace std;
int moder = 2019;
map<int,int>m;
map<int,int>::iterator it;
long long tenth[200005];

int main(){
	tenth[0] = 1;
	for(int i=1; i<=200000; i++){
		tenth[i] = tenth[i-1]*10;
		tenth[i]%=moder;
	}
	string s;
	cin>>s;
	vector<int>arr((int)s.length());
	for(int i=0; s[i]; i++) arr[i] = (int)(s[i]-'0');
	m.insert(make_pair(0,1));
	long long curr = 0;
	int ret = 0;
	for(int i=0; i<arr.size(); i++){
		curr*=10;
		curr+=arr[i];
		curr%=moder;
		long long temp = curr*tenth[s.length()-1-i];
		temp%=moder;
		it = m.find((int)temp);
		if(it!=m.end()){
			ret+=it->second;
			it->second+=1;
		}
		else m.insert(make_pair((int)temp,1));
	}
	cout<<ret;
}


Measured memory_bytes: 5948
L = sorted(list(map(int, input().split())))
cnt = 0
while L[0]<L[2]-2:
    cnt+=1
    L[0]+=2
while L[1]<L[2]-2:
    cnt+=1
    L[1]+=2
if L[0]%2 == L[1]%2 and L[1]%2 == L[2]%2:
    if(L[0]<L[2]):
        cnt += 1
    if(L[1]<L[2]):
        cnt += 1
else:
    if L[0]==L[1]:
        cnt+=1
    elif L[1]==L[2]: 
        cnt+=2
    else:
        cnt+=3


print(cnt)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i, n) for(int i = n; i >= 0; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define SORT(v) sort((v).begin(), (v).end())
#define REV(v) sort((v).begin(), (v).end(), greater<int>())
typedef long long ll;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a * b / gcd(a, b);};

int main() {
  int w[10], k[10];
  rep(i, 10) cin >> w[i];
  rep(i, 10) cin >> k[i];
  sort(w, w + 10, greater<int>());
  sort(k, k + 10, greater<int>());
  cout << w[0] + w[1] + w[2] << " " <<  k[0] + k[1] + k[2] << endl;
  return 0;
}



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

using namespace std;

long long knapsack(std::vector<long long>& weight , std::vector<long long>& val , long long n , long long cap,vector<vector<long long >>& v){
	long long ans;
	if(v[n][cap] != -1){
		//cout<<"Tes";
		return v[n][cap];
	}
	else{
		if(n==0 || cap == 0){
			//cout<<" T"<<endl;
			ans = 0;
		}
		else if(weight[n] > cap){
			//cout<<"E"<<endl;
			ans = knapsack(weight,val,n-1,cap,v);
		}
		else{
			//cout<<"S"<<endl;
			
			long long ans2 = val[n] + knapsack(weight,val,n-1,cap - weight[n],v);
			long long ans1 = knapsack(weight,val,n-1,cap,v);
			ans = max(ans1,ans2);
		}
		//cout<<n<<" "<<cap<<" "<<ans<<" ";
		v[n][cap] = ans;
		//cout<<ans<<" ";
		return ans;
	}
}
signed main()
{
	long long n,capacity;
	cin>>n>>capacity;

	std::vector<long long> weight(n+1);
	std::vector<long long> val(n+1);

	for (long long i = 1; i <= n; ++i)
	{
		cin>>weight[i]>>val[i];
	}
	vector<vector<long long >> v(n+1,vector<long long > (capacity+1,-1));
	long long ans = knapsack(weight,val,n,capacity,v);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 80256
N = int(input())
A = [int(a) for a in input().split()]
B = [int(b) for b in input().split()]

total_monster = sum(A)
for n in range(N):
  A1 = A[n]
  A2 = A[n+1]
  B1 = B[n]
  if B1 < A1:
    A[n] = A1 - B1
    A[n+1] = A2
  elif A1 <= B1 < A1+A2:
    A[n] = 0
    A[n+1] = A1 + A2 - B1
  else:
    A[n] = 0
    A[n+1] = 0

remaining_monster = sum(A)
ans = total_monster - remaining_monster
print(ans)

Measured memory_bytes: 19648
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    //今から文字入力
   int a,b,c;
   int i;
   cin>>a>>b>>c;
   i=0;
   //AからBまでの整数の中でCの約数の個数を求める
   while(1)
   {
       if(c%a==0)
       {
           i++;
           a++;
       }
       else
       {
           a++;
       }
       if(a>b) break;
   }
   cout<<i<<endl;
    return 0;
}



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

int main(){
	ios::sync_with_stdio(false);
	int n,i;
	cin >> n;
	
	string command, str;
	set<string> S;
	for (i=0;i<n;i++){
		cin >> command >> str;
		if (command=="insert"){
			S.insert(str);
		}else{
			if (S.find(str)==S.end()){
				cout << "no" <<endl;
			}else{
				cout <<"yes" << endl;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 27812
#include <bits/stdc++.h>
#define x first
#define y second
using namespace std;
const int sz=5005;
long long d[sz];
int n,m,p;
int f[sz],t[sz],w[sz];
long long inf=1e18,ans;

int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    scanf("%d %d %d",&n,&m,&p);
   for(int i=0;i<m;i++){
        scanf("%d %d %d",&f[i],&t[i],&w[i]);
        w[i]=p-w[i];
    }
    for(int i=1;i<=n;i++) d[i]=inf;
    bool flag=0;
    d[1]=0;
    for(int i=0;i<10*n;i++){
        for(int j=0;j<m;j++){
            int u=f[j];
            int v=t[j];
            int k=w[j];
            if(d[u]>=inf) continue;
            if(d[v]>d[u]+k){
                if(v==n&&i>=n) flag=1;
                d[v]=max(d[u]+k,-inf);
            }
        }
        if(flag){
            cout<<-1;
            return 0;
        }
    }
    if(d[n]==inf) cout<<-1;
    else{
        d[n]=-d[n];
        ans=max(ans,d[n]);
        cout<<ans;
    }
    return 0;
}


Measured memory_bytes: 384
n, m, k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
a, b = [0], [0]

for i in range(n):
    a.append(A[i]+a[i])
for i in range(m):
    b.append(B[i]+b[i])

ans, j = 0, m
for i in range(n+1):
    if a[i] > k:
        break
    while b[j] > k - a[i]:
        j -= 1
    ans = max(ans, i+j)
print(ans)

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

int main(){
	

	int t = 1;
	//cin >> t;
	while(t--){
		ll n, d;
		cin >> n >> d;
		ll x, y;
		int count = 0;
		double dist;
		for(int i = 0; i < n; ++i){
			cin >> x >> y;
			dist = x*x + y*y;
			dist = sqrt(dist*1.0);
			if(dist <= d){
				count++;
			}
		}
		cout << count << '\n';
	}
	return 0;
}

Measured memory_bytes: 3676
#include <iostream>
#include <vector>
#include <algorithm>
#include <random>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;

ll N = 0;

int main(){

    cin >> N;

    vector<ll > A;
    vector<ll > t_A;

    ll t = 0;

    for(int i = 0; i < N; i++){
        cin >> t;
        A.push_back(t);
        t = t - (i + 1);
        t_A.push_back(t);
        

    }

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

    //中央値
    ll center = 0;
    if(t_A.size() % 2 == 1){
        //cout << A[A.size() / 2  ] << endl;
        center = t_A[t_A.size() / 2];
    }else{
        //cout << (A[A.size() / 2 - 1] + A[A.size() / 2]) / 2 << endl;
        center = (t_A[t_A.size() / 2 - 1] + t_A[t_A.size() / 2]) / 2;
    }
    //cout << center << endl;
    ll ans = 0;

    for(int i = 1; i <= N; i++){
        //cout << A[i - 1] << endl;
        ans += abs(A[i - 1] - (center + i));
    }    

    cout << ans << endl;

}

Measured memory_bytes: 3564
n = input()

R = []
for i in range(n):
    R.append(input())

min_v = R[0]
max_v = -1000000000
for i in range(1, n):
    temp = R[i] - min_v
    if (temp >= max_v):
        max_v = temp
    temp = R[i]
    if (min_v >= temp):
        min_v = temp
print max_v

Measured memory_bytes: 18996
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  for(int i = 0; i < s.length(); i++){
    if(s[i] == '1') s[i] = '9';
    else if(s[i] == '9') s[i] = '1';
  }
  cout << s << endl;
  return 0;
}

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

int main() {
  int n, m, a, b;
  cin >> n >> m;
  vector<int> vec(n);

  for (int i=0; i<m; i++) {
    cin >> a >> b;
    vec.at(a-1)++;
    vec.at(b-1)++;
  }
  
  for (int i=0; i<n; i++) {
    cout << vec.at(i) << endl;
  }
}


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

const int MAXN = 2e5+4;
int a[MAXN];//保存输入数据
const int MAXM = 1e6;
bool flag[MAXM+4];//倍数标志

int main()
{
    int n;
    scanf("%d", &n);
    for (int i=1; i<=n; i++)
    {
        scanf("%d", &a[i]);
    }
    sort(a+1, a+n+1);
    int ans = 0;
    for (int i=1; i<=n; i++)
    {
        if (false==flag[a[i]])
        {
            if (a[i]!=a[i+1])
            {
                //参考样例2
                ans++;
            }

            for (int j=1; a[i]*j<=MAXM; j++)
            {
                flag[a[i]*j] = true;
            }
        }
    }

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

    return 0;
}


Measured memory_bytes: 5556
#include<bits/stdc++.h>
#define LL long long 
using namespace std;
const int MAXN = 1e5 + 10, MAXM = 53, mod = 1e9 + 7;
inline int read() {
    char c = getchar(); int x = 0, f = 1;
    while(c < '0' || c > '9') {if(c == '0') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * f;
}

int main() {
	int N = read();
	if(N == 7 || N == 5 || N == 3 ) puts("YES");
	else puts("NO");
    return 0;
}
/*
2
4 2
1
2
10 1
5
*/

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

namespace A
{
    class Frog1
    {
        const long INF = long.MaxValue;

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

            var h = new long[100001];
            var dp = new long[100001];

            int N = int.Parse(Console.ReadLine());
            h = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();

            for (var i = 0; i < 100001; i++) dp[i] = INF;

            dp[0] = 0;
            for (var i = 1; i < N; i++)
            {
                dp[i] = Math.Min(dp[i], dp[i - 1] + Math.Abs(h[i] - h[i - 1]));

                if (i >= 2)
                {
                    dp[i] = Math.Min(dp[i], dp[i - 2] + Math.Abs(h[i] - h[i - 2]));
                }
            }

            Console.WriteLine(dp[N - 1]);

            Console.Out.Flush();
        }
    }
}


Measured memory_bytes: 22496
#include<bits/stdc++.h>
#define rep(i, x, y) for(int i = (x); i <= (y); i++)
#define ll long long
#define N 105
using namespace std;
int n, m, sx, sy, h[N][N], s[N][N], f[N][N][N];
char str[N];
inline void upd(int &x, int y) { if(y > x) x = y; }
int main() {
	scanf("%d%d", &n, &m);
	rep(i, 1, n) {
		scanf("%s", str+1);
		rep(j, 1, m) {
			h[i][j] = h[i][j-1]; s[i][j] = s[i-1][j];//横竖前缀和
			if(str[j] == 'E') sx = i, sy = j;
			if(str[j] == 'o') h[i][j]++, s[i][j]++;
		}
	}
	//rep(i, 1, n) rep(j, 1, m) printf("%d %d: %d %d\n", i, j, h[i][j], s[i][j]);
	memset(f, -1, sizeof f); f[0][0][0] = 0; int ans = 0;
	rep(t, 0, m-sy) rep(i, 0, sx-1) rep(j, 0, n-sx) rep(k, 0, sy-1)
		if(f[i][j][k] != -1) {
			int u = max(j+1, sx-i), d = min(n-i, sx+j), l = max(t+1, sy-k), r = min(m-k, sy+t), cost;
			if(j+1 <= sx-i-1) {
				cost = h[sx-i-1][r]-h[sx-i-1][l-1];
				//if(n-i <= d) cost -= h[n-i-1][r]-h[n-i-1][l-1];
				upd(f[i+1][j][k], f[i][j][k]+cost);
			}
			if(sx+j+1 <= n-i) {
				cost = h[sx+j+1][r]-h[sx+j+1][l-1];
				//if(j+1 >= u) cost -= h[j+1][r]-h[j+1][l-1];
				upd(f[i][j+1][k], f[i][j][k]+cost);
			}
			if(t+1 <= sy-k-1) {
				cost = s[d][sy-k-1]-s[u-1][sy-k-1];
				//if(m-k <= r) cost -= s[d][m-k]-s[u-1][m-k];
				upd(f[i][j][k+1], f[i][j][k]+cost);
			}
			if(sy+t+1 <= m-k) {
				cost = s[d][sy+t+1]-s[u-1][sy+t+1];
				//if(t+1 >= l) cost -= s[d][t+1]-s[u-1][t+1];
				upd(f[i][j][k], f[i][j][k]+cost);
			}
			upd(ans, f[i][j][k]);
		}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 4992
def B_Bounding():
    N, X = map(int, input().split())
    L = list(map(int, input().split()))
    D = 0
    count = 1
    for bound in range(N):
        D = D + L[bound]
        if X >= D:
            count += 1
        else:
            break
    print(count)

if __name__ == "__main__":
    B_Bounding()

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int n,k;
int main(){
    cin>>n>>k;
    vector<int> v(n);
    rep(i,n) cin>>v[i];
    int sum=0;
    rep(i,n){
        sum+=min(abs(v[i]),abs(v[i]-k))*2;
    }
    cout<<sum<<endl;
    return 0;
}


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

int main()
{
	string s;
	
	cin>>s;
	
	int y=(s[5]-'0')*10+s[6]-'0';
	
	if(y<=4)
	{
		cout<<"Heisei"<<endl;
	}
	else
	{
		cout<<"TBD"<<endl;
	}
	return 0;
}

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

using namespace std;
long long ans;
const int MAXN =1e5+5;
int a[MAXN];
int b[MAXN];
int c[MAXN];
int main(){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    for(int i=1;i<=n;i++){
        cin>>b[i];
    }
    for(int i=1;i<=n;i++){
        cin>>c[i];
    }
    sort(a+1,a+n+1);
    sort(b+1,b+n+1);
    sort(c+1,c+n+1);
    int l =1;
    int r =1 ;
    for(int i=1;i<=n;i++){
        while(l<=n && a[l]<b[i]){
            l++;
        }
        while(r<=n && c[r]<=b[i]){
            r++;
        }
        //cout<<l<<" "<<r<<endl;
        ans+=1LL*(l-1)*((n-r+1));
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1536
def resolve():
    n = int(input())
    s = list(input() for _ in range(n))
    ans = ""
    for i in range(26):
        c = chr(ord('a') + i)
        num = min([si.count(c) for si in s])
        ans += c * num
    print(ans)    


if __name__ == "__main__":
    resolve()


Measured memory_bytes: 2940
//ITP 1_7_A
#include <iostream>
using namespace std;

int main(){
  int m,f,r;
  
  while(cin >> m >> f >> r and (m!=-1 or f!=-1 or r!=-1)){
    if(m==-1 or f==-1) cout << "F" << endl;
    else if(m + f >=80) cout << "A" << endl;
    else if(m + f >=65) cout<<"B"<<endl;
    else if(m + f >=50 or (m + f >= 30 and r>=50)) cout << "C" << endl;
    else if(m + f >=30) cout << "D" << endl;
    else cout<< "F" << endl;
  }
  
  return 0;
}



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

int main() {
    long int n,a,b;
    cin >> n >> a >> b;

    long int sumAB = a + b;
    long int divAB = n / sumAB;
    long int modAB = n % sumAB;

    long int totalA = 0;
    if(a != 0){
        totalA += divAB * a;
        totalA += min(modAB,a);
    }

    cout << totalA << endl;

}

Measured memory_bytes: 256
n = int(input())
s = input()
l = s.count("(")
r = s.count(")")
lmax = 0
if n == 1:
    print("()")
elif l == 0:
    print("("* r + s)
elif r == 0:
    print(s + ")"*l)
else:
    l = 0
    r = 0
    for c in s:
        if c == "(":
            l += 1
        else:
            r += 1
        lmax = max(r-l, lmax,0)
    
    res = "(" * lmax + s 

    l = res.count("(")
    r = res.count(")")

    if l > r:
        res = res + ")" * (l-r)

    elif r > l:
        res = "(" * (r-l) + res

    print(res)

Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace past10.Abc
{
    public class Question6
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            long N = long.Parse(Console.ReadLine());

            var a = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();

            Array.Sort(a);
            Array.Reverse(a);

            long res=0;
            for(long i=0;i<N;++i){
                if(i%2==0) res+=a[i];
                else res-=a[i];
            }

            Console.WriteLine(res);

            Console.Out.Flush();
        }
    }
}

Measured memory_bytes: 27880
#include <bits/stdc++.h>
    using namespace std;
     
    const int M = 50;
     
    int n, m,g[M+10][M+10];
    pair<int, int> a[M+10];
    bool bo[M + 10];
     
    void dfs(int x)
    {
        if (bo[x]) return;
        bo[x] = true;
        for (int i = 1;i <= n;i++)
            if (i!=x && g[x][i])
                dfs(i);
    }
     
    int main()
    {
        //freopen("F:\\rush.txt", "r", stdin);
        scanf("%d%d", &n, &m);
        for (int i = 1; i <= m; i++)
        {
            int x, y;
            scanf("%d%d", &x, &y);
            g[x][y] = g[y][x] = 1;
            a[i] = make_pair(x, y);
        }
     
        int ans = 0;
        for (int i = 1; i <= m; i++)
        {
            g[a[i].first][a[i].second] = 0;
            g[a[i].second][a[i].first] = 0;
            for (int j = 1; j <= n; j++) bo[j] = 0;
            dfs(1);
            int ok = false;
            for (int j = 1; j <= n; j++)
                if (bo[j] == 0)
                    ok = 1;
            ans += ok;
            g[a[i].first][a[i].second] = 1;
            g[a[i].second][a[i].first] = 1;
        }
        printf("%d\n", ans);
        return 0;
    }

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

public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) throws IOException {
		// TODO 自動生成されたメソッド・スタブ
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = new String();
		while ((line = br.readLine()) != null) {
			String[] s = line.split(" ");
			System.out.println(Integer.toString(Integer.parseInt(s[0])
					+ Integer.parseInt(s[1])).length());
		}
	}

}

Measured memory_bytes: 10000
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.traits;

alias X = Tuple!(int, "g", long, "a");

void main()
{
    auto nm = readln.split.to!(int[]);
    auto N = nm[0];
    auto M = nm[1];
    auto as = readln.split.to!(long[]);
    auto G = new int[][N];
    foreach (_; 0..M) {
        auto xy = readln.split.to!(int[]);
        auto x = xy[0];
        auto y = xy[1];
        G[x] ~= y;
        G[y] ~= x;
    }
    auto F = new bool[](N);
    X[] xs;
    int len;
    foreach (i; 0..N) {
        if (F[i]) continue;
        F[i] = true;
        xs ~= X(len, as[i]);
        void walk(int i) {
            foreach (j; G[i]) if (!F[j]) {
                xs ~= X(len, as[j]);
                F[j] = true;
                walk(j);
            }
        }
        walk(i);
        ++len;
    }
    if (len == 1) {
        writeln(0);
        return;
    }
    sort!"a.a < b.a"(xs);
    auto cs = new long[][len];
    int filled, cnt;
    X[] ys;
    foreach (x; xs) {
        if (cs[x.g].empty) filled += 1;
        cs[x.g] ~= x.a;
        ys ~= x;
        if (++cnt >= (len-1)*2 && filled == len) break;
    }
    if (cnt < (len-1)*2) {
        writeln("Impossible");
        return;
    }
    foreach_reverse (x; ys) {
        if (cnt == (len-1)*2) break;
        if (cs[x.g].length == 1) continue;
        cs[x.g] = cs[x.g][0..$-1];
        --cnt;
    }
    long r;
    foreach (ref c; cs) foreach (ref a; c) r += a;
    writeln(r);
}

Measured memory_bytes: 24472
from operator import mul
from functools import reduce

def cmb(n, r):
	if n < r: return 0
	if r == 0 or n - r == 0: return 1
	r = min(n - r, r)
	u = reduce(mul, range(n, n - r, -1))
	d = reduce(mul, range(1, r + 1))
	return u // d

n,a,b,*v=map(int,open(0).read().split())
v.sort(reverse=True)
print(sum(v[:a])/a)
c=v[a-1]
cnt=v.count(c)
d=sum(x>c for x in v)
if d:
	print(cmb(cnt,a-d))
else:
	print(sum(cmb(cnt,i) for i in range(a,min(cnt,b)+1)))

Measured memory_bytes: 3572
n,m = (int(x) for x in input().split())
edge = [[] for x in range(n)]
hight = [int(x) for x in input().split()]
highest = [True]*n
ans = 0

for i in range(m):
    a,b = (int(x) for x in input().split())
    edge[a-1].append(b)
    edge[b-1].append(a)

for i in range(n):
    if(highest[i] == False):
        continue
    high = hight[i]
    flag =True
    for v in edge[i]:
        if hight[v-1] >= high:
            flag=False
            break
        else:
            highest[v-1] = False
    if(flag):
        ans +=1


print(ans)

Measured memory_bytes: 30876
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;

namespace Pyramid
{
    class Program
    {
        public static void Main(string[] args)
        {
            using (var sc = new SetConsole())
            {
                int n = GetIntInput();
                var xyh = new int[3];
                var list = new List<int[]>();
                for (int i = 0; i < n; i++)
                {
                    var tmp = Console.ReadLine().Split().Select(int.Parse).ToArray();
                    if (tmp[2] != 0)
                    {
                        xyh = tmp;
                    }
                    list.Add(tmp);
                }
                
                bool result = false;
                for (int i = 0; i <= 100; i++)
                {
                    for (int j = 0; j <= 100; j++)
                    {
                        int expH = Math.Abs(xyh[0] - i) + Math.Abs(xyh[1] - j) + xyh[2];
                        var flg = true;
                        for (int k = 0; k < list.Count; k++)
                        {
                            if (list[k][2] != Math.Max(expH - Math.Abs(list[k][0] - i) - Math.Abs(list[k][1] - j), 0))
                            {
                                flg = false;
                                break;
                            }
                        }
                        if (flg && expH >= 1) { Console.WriteLine($"{i} {j} {expH}"); result = true; break; }

                    }
                    if (result) { break; }
                }
            }
        }

        static string[] GetArrayCharInput() => Console.ReadLine().Split();
        static int[] GetArrayIntInput() => Console.ReadLine().StringToIntArray();
        static int GetIntInput() => Console.ReadLine().ToInt();
        static void CWrite(string str) => Console.WriteLine(str);

    }

    class SetConsole : IDisposable
    {
        public SetConsole()
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = true };
            Console.SetOut(sw);
        }
        public void Dispose()
        {
            Console.Out.Flush();
        }
    }

    static class ExtentionsLibrary
    {
        public static int[] StringToIntArray(this string str) =>
            str.Split().Select(int.Parse).ToArray();
        public static int ToInt(this string str) => int.Parse(str);
    }
}


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

def solve():
    n, hp = map(int, input().split())
    swing_damage_list = []
    throw_damege_list = []
    
    for _ in range(n):
        swing_damage, throw_damage = map(int, input().split())
        swing_damage_list.append(swing_damage)
        throw_damege_list.append(throw_damage)

    swing_damage_list.sort()
    throw_damege_list.sort()
    max_swing_damage = swing_damage_list[-1]

    will_throw_list = [damage for damage in throw_damege_list if damage > max_swing_damage]
   
    all_damage = sum(will_throw_list) 
    answer = len(will_throw_list)
    if all_damage > hp:
       for damage in will_throw_list:
            if all_damage - damage < hp:
                print(answer)
                return
            all_damage -= damage
            answer -= 1
    else:
        print(answer + ((hp - all_damage) + (max_swing_damage - 1)) // max_swing_damage)

if __name__=="__main__":
    solve()


Measured memory_bytes: 12104
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int main(void)
{
	int n,l,num[100],i,j,k;
	char s[100][101];
	scanf("%d %d",&n,&l);
	for(i=0;i<n;i++){
		scanf("%s",s[i]);
		num[i]=i;
	}
	for(j=0;j<n-1;j++){
			for(k=j+1;k<n;k++){
				if(strcmp(s[num[j]],s[num[k]])>0){
					swap(num[j],num[k]);
				}
			}
	}
	for(i=0;i<n;i++){
		printf("%s",s[num[i]]);
	}
	printf("\n");
	return 0;
}

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

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<")"<< endl
#define BINARY(x) static_cast<bitset<16> >(x)

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)

#define in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;
const int INF   = 1e9;
const ll  INFLL = 1e18;
typedef pair<int, int> PII;
typedef vector<vector<int>> Graph;
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};

int main()
{
    ios::sync_with_stdio(false);
    int N; cin >> N;
    string S; cin >> S;
    int all_e=0, all_w=0;
    for (auto c : S) {
        if (c == 'W') all_w++;
        else          all_e++;
    }

    int e = 0, w = 0;
    int ans = INF;
    rep(i, N) {
        int tmp = 0;
        tmp += w;
        tmp += all_e - e - (S[i] == 'E');
        ans = min(ans, tmp);

        if (S[i] == 'W') w++;
        else          e++;
    }

    cout << ans << endl;
}

Measured memory_bytes: 720
n,k = gets.split.map(&:to_i)
p_k = gets.split.map(&:to_i)
p_k = p_k.map{|n| (n+1.0)/2.0}
plus = []
plus[0] = p_k[0]
for i in 1..(n-1)
    plus[i] = p_k[i]+plus[i-1]
end
if n == k 
    puts plus[-1]
    exit
end
max = 0
sum = 0
for i in k..(n-1)
    sum = plus[i]-plus[i-k]
    if max < sum
        max = sum
    end
end
puts max

Measured memory_bytes: 18260
// https://atcoder.jp/contests/abc107/tasks/arc101_a

#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;

typedef long long ll;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOREACH(x, a) for (auto &(x) : (a))
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()

// int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

int main() {
    int n, k;
    vector<int> x, y;
    cin >> n >> k;
    x.resize(n);

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

    // k本のロウソクに火をつける時間を計算
    for (int i = 0; i <= n - k; i++) {
        // 比較対象の符号が逆の場合
        int a = x[i], b = x[i + k - 1];
        if (signbit(a) != 0 && signbit(b) == 0 ||
            signbit(a) == 0 && signbit(b) != 0) {
            if (abs(x[i]) < abs(x[i + k - 1])) {
                y.push_back(2 * abs(x[i]) + abs(x[i + k - 1]));
            } else {
                y.push_back(abs(x[i]) + 2 * abs(x[i + k - 1]));
            }
        } else {
            y.push_back(max(abs(x[i]), abs(x[i + k - 1])));
        }
    }
    sort(ALL(y));
    cout << y[0] << endl;

    return 0;
}


Measured memory_bytes: 1024
#include <stdlib.h>
#include <stack>
#include <cctype>
#include <iostream>
#include <string>

using namespace std;

int main()
{
	long long ans = 0;
	const char* i;
	const char* pEnd;
	stack<int> c;

	string s;
	getline(cin, s);
	pEnd = s.c_str() + s.length();
	i = s.c_str();
	while (i < pEnd) {
		int n;
		char* idx;
		if (isspace(*i)) ++i;
		if (isdigit(*i)) {
			n = strtol(i, &idx, 10);
			c.push(n);
			i = idx;
		} else {
			int t, b;
			switch (*i) {
				case '+':
					t = c.top();
					c.pop();
					t += c.top();
					c.pop();
					c.push(t);
					break;
				case '-':
					t = c.top();
					c.pop();
					b = c.top();
					c.pop();
					b -= t;
					c.push(b);
					break;
				default:
					t = c.top();
					c.pop();
					t *= c.top();
					c.pop();
					c.push(t);
			}
			i += 2;
		}
	}

	cout << c.top() << endl;

	return 0;
}



Measured memory_bytes: 3228
def calc(N, adj, dp, ignore):
    s, t = ignore
    for i in range(N-1, -1, -1):
        dp[i] = 0.0
        n = len(adj[i])
        if i == s:
            n -= 1
        for nxt in adj[i]:
            if i == s and nxt == t:
                continue
            dp[i] += (dp[nxt] + 1) / n
    return dp[0]


def main():
    N, M = map(int, input().split())
    adj = [set() for _ in range(N)]
    for _ in range(M):
        s, t = map(int, input().split())
        adj[s-1].add(t-1)
    dp1 = [0.0] * N
    ans = calc(N, adj, dp1, (-1, -1))
    dp2 = [0.0] * N
    for i in range(N-1, -1, -1):
        if len(adj[i]) <= 1:
            continue
        j = i
        mx = -1
        for nxt in adj[i]:
            if dp1[nxt] > mx:
                j = nxt
                mx = dp1[nxt]
        tmp = calc(N, adj, dp2, (i, j))
        ans = min(ans, tmp)
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 62424