akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

class UnionFind {
public:
    int S;
    vector <int> par; // 各ノードの親を格納する配列
    vector <int> siz; // 素集合の大きさを格納する配列
 
    UnionFind(int n){
    	for (int i = 0; i < n; i++) {
    		par.push_back(i); // 最初、自分自身を親とする
    		siz.push_back(1);
    	}
        S = n;
    }
 
    int root(int x) { // 根を検索する
        while (par[x] != x) {
            x = par[x] = par[par[x]]; // 木の長さを短くする工夫
        }
        return x;
    }

    bool unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return false;

        if (siz[rx] < siz[ry]) swap(rx, ry); //縦に長いほうに短いほうをつなげる
        siz[rx] += siz[ry];
        par[ry] = rx;
        S--;
        return true;
    }
 
    bool is_same(int x, int y) { // a,bが同じグループに属するか調べる
        return root(x) == root(y);
    }
 
    int size(int x) { // 素集合のサイズ
        return siz[root(x)];
    }
	int allsize() {return S;} // 全てのグループ数
};

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> P(N);
    for(int i = 0; i < N; i++){
        cin >> P[i];
    }

    UnionFind tree(N);

    for(int i = 0; i < M; i++) {
        int x, y;
        cin >> x >> y;
        tree.unite(x-1, y-1); // x-1の木とy-1の木を併合する
    }

    int cnt = 0;
    for(int i = 0; i < N; i++) {
        if (tree.is_same(i, P[i]-1)) { //iとP[i]-1が同じ木に属するなら，カウンタに1追加
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 1660
# ABC063 D - Widespread
def check(x,hp):
    hp=[hh-(b*x) for hh in hp]
    explosion=0
    for hhh in hp:
        if hhh<=0:continue
        if hhh%(a-b)==0:
            explosion+=hhh//(a-b)
        else:
            explosion+=hhh//(a-b)+1
    return explosion<=x

n,a,b=map(int,input().split())
h=[int(input()) for i in range(n)]
lo=0
hi=10**9
while hi-lo>1:
    mid=(hi+lo)//2
    if check(mid,h):
        hi=mid
    else:
        lo=mid
print(lo+1)

Measured memory_bytes: 11040
// n/w * m/h 个特殊点
// 设特殊点权值为x，其他点为y,那么满足：
// x = y * (1 - w*h) - 1
// n/w * m/h * (x-y) + y * n * m > 0 

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=505;

int a[N][N],n,m,w,h,v;
ll sum=0;

int main(){
	scanf("%d%d%d%d",&n,&m,&w,&h),v=1000*(1-w*h)-1;
	for(int i=w;i<=n;i+=w)
		for(int j=h;j<=m;j+=h) a[i][j]=v;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
		    if(a[i][j]) sum+=(ll)a[i][j];
	        else sum+=(ll)1000,a[i][j]+=1000;

	if(sum<=0){ puts("No"); return 0;}

	puts("Yes");
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++) printf("%d ",a[i][j]);
		puts("");
	}
	
	return 0;
}

Measured memory_bytes: 2560
#include "bits/stdc++.h"
using namespace std;

long long n, a, b;

void solve() {
  if (n % (a + b) > a) {
    cout << n / (a + b) * a + a << endl;
  } else {
    cout << n / (a + b) * a + n % (a + b) << endl;
  }
}

int main() {
  cin >> n >> a >> b;
  solve();
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll MOD=1e9+7;
ll mod_pow(ll a,ll b) {
    if(b==0){return 1;}
    ll res=mod_pow(a*a%MOD,b/2);
    if(b&1)res=res*a%MOD;
    return res;
}
int main(){
  ll N,ans=0;
  cin>>N;
  vector<ll> vec(61);
  for(ll i=0;i<N;i++){
    ll a,j=0;
    cin>>a;
    while(a>0){
      if(a&1){vec.at(j)++;}
      a/=2;
      j++;
    }
  }
  for(ll i=0;i<61;i++){
    ans+=((((N-vec.at(i))*vec.at(i))%MOD)*mod_pow(2,i))%MOD;
    ans%=MOD;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main( )
{
	char s[11];
	char t[12];
	cin>>s>>t;
	int x=0;
	int p=strlen(s);
	int l=strlen(t);
	for(int i=0;i<=l-1;i++){
		if(s[i] == t[i])
		x++;
	}
	if(p == x && l==p+1) cout<<"Yes"<<'\n';
	else cout<<"No"<<"\n";
}

Measured memory_bytes: 3592
#include <iostream>
#include <algorithm>
#include <cstdio>

using namespace std;

int main() {
  int n, a, b;
  scanf("%d%d%d", &n, &a, &b);
  if ((b-a)%2) printf("Borys\n");
  else printf("Alice\n");
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <stdio.h>
#include<math.h>
#include<string>
#include<vector>
#define ll long long
using namespace std;
int main(void){
  int N,D;
  cin >> N>>D;
  int marge=2*D+1;
  if(N%marge==0){
    cout << N/marge;
  }else{
    cout << N/marge+1;
  }
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define debug(...)
#include <complex.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
vvi g;
int n;
map<pair<int , int>, int> BFS(int s){
    vi clr(n + 1, -1);
    queue<int>q;
    q.push(s);
    vi used(n + 1);
    used[s] = 1;
    map<pair<int,int>, int>hhh;
    while(!q.empty()){
        int from = q.front();
        q.pop();
        int id = 1;
        for(int to : g[from]) if(!used[to]){
            if(id == clr[from])id++;
            used[to] = 1;
            hhh[make_pair(from, to)] = clr[to] = id;
            id++;
            q.push(to);
        }
    }
    return hhh;
}
int32_t main() {
    ios::sync_with_stdio(false); cin.tie(0);
    #ifdef LOCAL
        freopen("f.txt", "r", stdin);
      // freopen("g.txt", "w", stdout);
    #endif

    cin >> n;
    g =vvi(n + 1);

    size_t mx = 0;
    vector<pair<int , int>>edges;
    for(int i = 1; i < n; i++){
        int from , to;
        cin >> from >> to;
        g[from].push_back(to);
        g[to].push_back(from);
        mx = max({mx , g[from].size() , g[to].size()});
        if(from > to)swap(from , to);
        edges.emplace_back(from , to);
    }

    map<pair<int , int>, int> clr = BFS(1);
    cout << mx << '\n';
    for(pair<int , int> p : edges){
        cout << clr[p] << '\n';
    }
    return 0;
}













Measured memory_bytes: 13816
N = input()
M = input()

sorted_asc = sorted(list(N))
sorted_desc = sorted(list(M), reverse=True)
res = ""

for (x, y) in zip(sorted_asc, sorted_desc):
    if x < y:
        res = "Yes"
        break
    elif x > y:
        res = "No"
        break

if res == "":
    if len(N) >= len(M):
        res = "No"
    else:
        res = "Yes"

print(res)


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

int N;
int A[100001], B[100000];

signed main() {
  cin >> N;
  for(int i=0; i<N+1; i++) cin >> A[i];
  for(int i=0; i<N; i++) cin >> B[i];

  long long ans =0;
  for(int i=N-1; i>=0; i--) {
    int b = B[i];
    ans += min(b, A[i+1]);
    b = max(0, b-A[i+1]);
    ans += min(b, A[i]);
    A[i] = max(0, A[i] - b);
  }
  cout << ans << endl;
}


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

using namespace std;

int k, x;

int main(){
  cin >> k >> x;
  int flag=0;
  for(int i=x-k+1; i<x+k; i++){
    if(flag==0){
      cout << i;
      flag++;
    } else {
      cout << " " << i;
    }
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <string>
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <array>

using namespace std;

int main() {
	
	// 変数宣言
	int N;
	vector<int> A;
	int l;
	int ans;
	int tmp;
	int max = 0;

	// 入力
	scanf("%d", &N);
	for(int i = 0; i<N; i++){
		scanf("%d", &l);
		A.push_back(l);
	}

	for (int i = 0; i < N; i++){
		for(int j = 0; j < N; j++){
			if(i == j) continue;
			tmp = abs(A[i] - A[j]);
			if(tmp > max) max = tmp;
		}
	}

	// 出力
	ans = max;
	printf("%d\n", ans);
	
	return 0;
	
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int[][] ary = new int[n][2];
        List<Integer> list = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            ary[i][0] = Integer.parseInt(sc.next());
            ary[i][1] = Integer.parseInt(sc.next());
            list.add(i);
        }
        List<List<Integer>> makeList = makePermutation(list);
        double sum = 0;
        for (int i = 0; i < makeList.size(); i++) {
            List<Integer> list2 = makeList.get(i);
            for (int j = 0; j < n - 1; j++) {
                sum += Math.sqrt(Math.pow(ary[list2.get(j)][0] - ary[list2.get(j + 1)][0], 2) + Math.pow(ary[list2.get(j)][1] - ary[list2.get(j + 1)][1], 2));
            }
        }
        System.out.println(sum / factorial(n));
    }

    public static List<List<Integer>> makePermutation(List<Integer> list) {
        if (list.size() == 0) {
            List<List<Integer>> empty = new ArrayList<>();
            empty.add(new ArrayList<>());
            return empty;
        }

        return list.stream().flatMap(i -> {
            List<Integer> rest = new ArrayList<>(list);
            rest.remove(i);
            return makePermutation(rest).stream().map(lst -> {
                lst.add(0, i);
                return lst;
            });
        }).collect(Collectors.toList());
    }

    private static long factorial(long n) {
        if (n == 1) {
            return 1;
        }
        return n * factorial(n - 1);
    }
}

Measured memory_bytes: 72968
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <stack>
#include <climits>
#include <map>
#include <set>

using namespace std;

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

const ll mod = 1000000007;
const int inf = 1e9;
const long long INF = 1LL << 60;


int main()
{
    int n; cin >> n;
    ll c[n-1],s[n-1],f[n-1];
    for(int i = 0; i < n-1; i++){
        cin >> c[i] >> s[i] >> f[i];
    }
    ll arrive[n];
    for(int i = 0; i < n; i++){
        arrive[i] = 0;
    }

    for(int i = 0; i < n-1; i++){
        for(int j = 0; j <= i; j++){
            if(arrive[j] < s[i]) arrive[j] = s[i];
            if(arrive[j] % f[i] != 0){
                arrive[j] += (f[i] - arrive[j] % f[i]);
            }
            arrive[j] += c[i];
        }
    }
    for(int i = 0; i < n; i++){
        cout << arrive[i] << endl;
    }
}


Measured memory_bytes: 256
import java.util.*;


public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a1 = sc.nextInt();
        int a2 = sc.nextInt();
        int a3 = sc.nextInt();

        if(a1 + a2 + a3 >= 22){
            System.out.println("bust");
        }

        else System.out.println("win");

        // write your code here
    }
}

Measured memory_bytes: 22356
#include<iostream>
using namespace std;
int main(){
	int n,temp,j;
	while(cin >> n){
		int k=0;
		int a[n];

		while(k!=n){
			cin >> a[k];
			k++;
		}

		for(int i=0;i<n;i++){
			temp = a[i];
			j = i-1;

			while(j>= 0 && a[j]>temp){
				a[j+1]=a[j];
				j--;
				a[j+1]=temp;
			}

			int l=0;

			while(l!=n-1){
				cout << a[l] << " ";
			l++;
			}
			cout << a[n-1]<< endl;

		}
	}
	return 0;
}

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

int main() {
    int N; cin >> N;
    vector<ll> A(N);
    for (int i = 0; i < N; i++){
        cin >> A[i];
    }
    sort(A.begin(), A.end());
    int i = N - 1;
    ll p = 0;
    while (i > 0) {
        if (A[i] == A[i - 1]){
            if (p > 0) {
                cout << p * A[i] << endl;
                return 0;
            }
            else {
                p = A[i];
                i--;
                i--;
            }
        }
        else {
            i--;
        }
    }
    cout << 0 << endl;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define fi first
#define se second
#define pb push_back
#define mk make_pair
using namespace std;
typedef long long ll;
typedef long double lld;
const ll INF = 1e18;
const ll MOD = 1e9+7;
 
ll fastpowMOD(ll a, ll p,ll MOD);
ll fastpowMOD(ll a, ll p,ll MOD){ if(p==0) return 1; a %= MOD; ll z = fastpowMOD(a,p/2,MOD); z = (z*z)%MOD; if(p%2) z = (z*a)%MOD; return z; }
 
ll lcm(ll a,ll b){
	return (a*b)/__gcd(a,b);
}

int main(){
    fastio;
    int n;
  	cin>>n;
  	map<string,int> mp;
  	for(int i=0;i<n;i++){
      string s;
      cin>>s;
      mp[s]++;
    }
  cout<<mp.size()<<"\n";
      
}




Measured memory_bytes: 19148
#include<bits/stdc++.h>
using namespace std;
#define ll         long long int
#define co         cout
#define ci         cin
#define sf1(n)     scanf("%lld",&n)
#define sf2(n,m)   scanf("%lld %lld",&n,&m);
#define sf3(n,m,p) scanf("%lld %lld %lld",&n,&m,&p);
#define pf1(n)     printf("%lld\n",n);
#define mem(a,b)   memset(a,b,sizeof(a))
#define en         cout<<endl;
#define pb         push_back
#define gcd(n,m)   __gcd(n,m)
#define lcm(n,m)   ((n)/__gcd(n,m))*(m)
#define fi         first
#define se         second
#define coy        cout<< "YES"<<endl;
#define con        cout<< "NO"<<endl;
#define f(i,a,b)     for(ll i=a;i<b;i++)
#define all(x)     (x).begin(),(x).end()
#define allr(x)    (x).rbegin(),(x).rend()
#define pi         pair<ll,ll>
#define br         break;
#define i64        long long
#define PI         2*acos(0.0)
#define MAXN       3*100000

 ll findProductSum(vector<ll>A, ll n) 
{ 
    ll sum=0,m=1000000007,ans=0;
    for(auto x:A) sum=(sum+x)%m,sum%=m;
    for(auto x:A)
    {
        sum-=x;
        if(sum<0) sum+=m;
        ans+=(x*sum)%m;
        ans%=m;
    }
    return ans;
} 
int main()
{
    ll n,m,k,g,mx,mn,res,c,x,y,z,w,p,q,r,l,s,t;
    ci>>n;
    vector<ll>a(n);
    for(auto &x:a) ci>>x;
    res=findProductSum(a,n);
    co<<res;
    return 0;
}

Measured memory_bytes: 6432
n,k = gets.split.map &:to_i
h = gets.split.map &:to_i
 
INF = 10**12
dp = Array.new(n,INF)
dp[0] = 0
 
1.upto(n-1) do |i|
  min = 10000000001
  t = i - k
  t = 0 if t < 0
  t.upto(i-1) do |j|
    cost = (h[i] - h[j]).abs + dp[j]
    min = cost if min > cost
  end
  dp[i] = min
end
 
puts dp[-1]

Measured memory_bytes: 8836
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 1e9;
const ll LINF = ll(1e18);
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
//-std=gnu++17
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,x,t;
    cin>>n>>x>>t;
    cout<<((n+x-1)/x)*t<<"\n";
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
using vll=vector<ll>;
using vi=vector<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;}

//pow(llpow,modpow)
template<class T> ll llpow(ll x,T n){ll ans=1;if(x==0)ans=0;while(n){if(n&1)ans*=x;x*=x;n>>=1;}return ans;}
long long modpow(long long a, long long n, long long mod) {long long res = 1;while (n > 0) {if (n & 1) res = res * a % mod;a = a * a % mod;n >>= 1;}return res;}
//最大公約数
template<class T> inline T gcd(T x,T y){if(y==0)return x; else {return gcd(y,x%y);}}
//最小公倍数
template<class T> inline T lcm(T x,T y){return x/gcd(x,y)*y;}
//逆元
long long modinv(long long a, long long m) {long long b = m, u = 1, v = 0;while (b) {long long t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}

#define rep(i,n) for(ll i=0;i<(ll)n;i++)
#define rep2(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)

long long INF = 1LL<<60;
int main( ){
    long double a,b,c;
    cin>>a>>b>>c;
    if(c-b-a-2*sqrtl(a*b)>0)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}




Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int n[5];
  int i;
  while(1){
    int c=0,t[4]={0};
    scanf("%d",&n[0]);
    if(n[0]==0)break;
    t[n[0]]=1;
    c=1;
    for(i=0;i<4;i++){
      scanf("%d",&n[i+1]);
      if(t[n[i+1]]==0)c++;
      t[n[i+1]]=1;
    }
    if(c==1||c==3)for(i=0;i<5;i++)printf("3\n");
    else{
      for(i=0;i<5;i++){
	if(t[1]==0){
	  if(n[i]==2)printf("1\n");
	  if(n[i]==3)printf("2\n");
	}
	if(t[2]==0){
	  if(n[i]==3)printf("1\n");
	  if(n[i]==1)printf("2\n");
	}
	if(t[3]==0){
	  if(n[i]==1)printf("1\n");
	  if(n[i]==2)printf("2\n");
	}
      }
    }
  }
  return 0;
}

Measured memory_bytes: 584
#include <cmath>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <list>
#include <time.h>
#include <math.h>
#include <random>
#include <deque>
#include <queue>
#include <cassert>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>
#include <sstream>

using namespace std;

typedef long long ll;

mt19937 rnd(228);

map <int, int> mp[2];

int main()
{
#ifdef ONPC
    freopen("a.in", "r", stdin);
#endif
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        int x;
        cin >> x;
        mp[i % 2][x]++;
    }
    int ans = 0;
    vector <vector <pair <int, int> > > f;
    for (int t = 0; t < 2; t++)
    {
        vector <pair <int, int> > e;
        for (auto c : mp[t]) e.push_back({c.second, c.first});
        for (int i = 1; i <= 3; i++) e.push_back({mp[t][i], i});
        sort(e.rbegin(), e.rend());
        e.resize(unique(e.begin(), e.end()) - e.begin());
        e.resize(2);
        f.push_back(e);
    }
    for (auto c : f[0])
    {
        for (auto d : f[1])
        {
            if (c.second != d.second)
            {
                ans = max(ans, c.first + d.first);
            }
        }
    }
    cout << n - ans << '\n';
}


Measured memory_bytes: 5876
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<set>
#include<tuple>
#include<ctime>
#include<functional>
#include<cmath>
#include<cassert>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> p; 
#define rep(i,n) for(ll i=0;i<(n);i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))

const ll mod = 1e9 + 7;
const ll inf = 1e18;
int main(){
ll N,D;
cin>>N>>D;
if(N%(2*D+1)==0) p(N/(2*D+1));
else p(N/(2*D+1)+1);
}

Measured memory_bytes: 256
from heapq import *
n, m = map(int, input().split())
jobs = [tuple(map(int, input().split())) for _ in range(n)]
jobs.sort(reverse=True)
ans = 0
q = []
for i in range(1, m+1):
    while jobs and jobs[-1][0] <= i:
        heappush(q, -jobs.pop(-1)[1])
    if q:
        ans -= heappop(q)
print(ans)

Measured memory_bytes: 17156
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        List<Long> list = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            list.add(sc.nextLong());
        }
        System.out.println(list.stream().sorted(Comparator.reverseOrder()).skip(k).reduce(0L, (a, b) -> a + b));
    }
}

Measured memory_bytes: 67492
#include <iostream>
#include <string.h>
using namespace std;

int main(){
	char  s[200001]={};
	int st=-1,go=0;
	cin >> s;
	for(int i=0;i<sizeof(s);i++)
	{
		if(s[i]=='A'&&st==-1)
		{
			st=i;
		}
		if(st!=-1&&s[i]=='Z')
		{
			go=i;
		}
	}
	cout<<go-st+1;
	return 0;
	}


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
using namespace std;
int main() {
    int N;
    cin >> N;
    //N以下の素数を格納するライブラリ
    vector<int> prime;
    prime.push_back(2);
    bool flag = true;
    for (int i = 3;i<N+1;i++){
        flag = true;
        for (int j = 0;j<prime.size();j++){
            if(i % prime[j] == 0){
                flag = false;
                break;
            }
        }
        if(flag == true){
            prime.push_back(i);
        }
    }
    //N!を素因数分解する
    int b;
    int p = 0;
    int a[prime.size()];
    int k;
    for (int i = 0;i<prime.size();i++){
        for (int j = 1;j < N+1;j++){
            k = j;
            b = j % prime[i];
            k = k / prime[i];
            while(b == 0){
                b = k % prime[i];
                p = p + 1;
                k = k / prime[i];
            }
        }
        a[i] = p;
        p = 0;
    }
    int psize = prime.size();
    bool fl2 = true,fl4 = true,fl14 = true,fl24 = true,fl74 = true;
    int t2 = 0,t4 = 0,t14 = 0,t24 = 0,t74 = 0;
    for (int i = 0;i< psize;i++){
        if(a[psize-i-1] >= 2){
            if(fl2 == true){
                t2 = psize - i;
            }
            fl2 = false;
        }
        if(a[psize-i-1] >= 4){
            if(fl4 == true){
                t4 = psize - i;
            }
            fl4 = false;
        }
        if(a[psize-i-1] >= 14){
            if(fl14 == true){
                t14 = psize - i;
            }
            fl14 = false;
        }
        if(a[psize-i-1] >= 24){
            if(fl24 == true){
                t24 = psize - i;
            }
            fl24 = false;
        }
        if(a[psize-i-1] >= 74){
            if(fl74 == true){
                t74 = psize - i;
            }
            fl74 = false;
        }
    }
    int ans = t74 + (t2 - 1)*(t24) + (t4 - 1)*(t14) + (t2 - 2)*(t4 - 1)*(t4)/2;
    cout << ans << endl;
}

Measured memory_bytes: 256
# frozen_string_literal: true

n, m, q = gets.split.map(&:to_i)
abcd = q.times.map { gets.split.map(&:to_i) }
max = 0
(1..m).to_a.repeated_combination(n).each do |f|
  sum = 0
  abcd.each do |e|
    a = e[0] - 1
    b = e[1] - 1
    c = e[2]
    d = e[3]
    sum += d if f[b] - f[a] == c
  end
  max = sum if max < sum
end
puts max


Measured memory_bytes: 14716
#include <bits/stdc++.h>
using namespace std;
//Author: Ezio Sam
/* Shorthands */
#define ll long long
#define pb push_back
#define em emplace_back
#define mp make_pair
#define sp " "
#define cs "Case "
#define fi first
#define sn second

/* STL */
#define mem(a,n) memset(a, n, sizeof(a));
#define all(x) x.begin(),x.end()
#define alr(x) x.rbegin(),x.rend()
#define sz(x)  (int)x.size()
#define mx(v)  *max_element(v.begin(),v.end())
#define mxi(v) distance(v.begin(),max_element(v.begin(),v.end()))
#define mxa(a) *max_element(a, a.size())
#define r(a)   reverse(a.begin(),a.end())
/* loops */
#define fr(i,n)   for(__typeof(n) i=0;i<(n);i++)
#define fn(i,n)   for(__typeof(n) i=1;i<=(n);i++)
/*Special*/
#define Ezio ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define db(something)  cerr<<#something<<" - "<<something<<"\n";

int main()
{

   Ezio
   ll t,m,n,x,a,b;
   string s;

   cin>>n;
   cout<<(n*n)<<endl;
   return 0;
}


Measured memory_bytes: 3620
X = int(input())
cnt_0 = 0
cnt_1 = 0
while True:
  cnt_1 = 0
  ref_x = X + cnt_0
  ref_list = [i for i in range(2, ref_x)]
  for i in ref_list:
    if ref_x % i == 0:
      break
    else:
      cnt_1 += 1
  if cnt_1 == len(ref_list):
    print(ref_x)
    break
  cnt_0  += 1

Measured memory_bytes: 11032
import java.util.*;

public class Main {
    public static void main(String args[]) throws Exception {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        long k = sc.nextLong();
        if(k == 1) {
            System.out.println(s.charAt(0));
            return;
        }
            
        int idx = 0;
        while(idx < s.length() && idx < k-1) {
            if(s.charAt(idx) != '1')
                break;
            idx++;
        }
        System.out.println(idx == s.length() ? 1 : s.charAt(idx));
    }
}


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

int main() {
    double r;
    cin >> r;
    
    double area = r * r * ((double) M_PI);
    double circ = 2.0 * r * ((double) M_PI);
    cout << fixed << setprecision(5) << area << " " << circ << endl;
    return 0;
}


Measured memory_bytes: 3284
#include<iostream>
using namespace std;
int main(){

  long long n,sum=0,a,max,min;
    cin >>n;
    for(int i=1; i<=n; i++)
    {
        cin >>a;
        if(i==1){
            max=min=a;
        }
            
        if(max<a){  
            max=a;
        }
          
        else if(min>a){
            min=a;
        }
            
        sum=sum+a;
    }
   cout<< min<<" "<<max<<" "<<sum<<endl;
   
   return 0;
}




Measured memory_bytes: 3108
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

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 ll INF=1e9+1;

int main()
{
    string s;
    cin >> s;
    ll k;
    cin >> k;
    ll n=s.length();
    ll ans=1;
    rep(i,min(n,k)){
        ll num=(ll)(s[i]-'0');
        if(num!=1){
            ans=num;
            break;
        }
    }
    cout << ans << endl;
    return 0;
} 


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



int main(void){
    int N;
    cin >> N;
    map<long long int, int> m;
    for(int i=0; i<N; i++) {
        long long int x;
        cin >> x;
        m[x]++;
    }
    int sum = 0;
    for(auto it = m.begin(); it != m.end(); it++) {
        long long int key = it->first;
        int value = it->second;
        if(key < value) sum += value - key;
        else if(key > value) sum += value;
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 6272
N = int(input())
fn = [list(map(int,input().split())) for _ in range(N)]
pn = [list(map(int,input().split())) for _ in range(N)]
bitf = []
for i in range(N):
    temp = 0
    for j in range(10):
        temp += ((2 ** j) * fn[i][j])
    bitf.append(temp)
#print(bitf)
def func(x , y):
    return bin(x & y).count('1')
ans = (-1) * 10 ** 10
for i in range(1,2**10):
    temp = 0
    for j in range(N):
        temp += pn[j][func(i,bitf[j])]
    ans = max(ans , temp)
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
 
using namespace std;
 
int main(){
	
	ios :: sync_with_stdio(false);
	
	int n;
	
	cin>>n;
	
	long long int total = 0;
	
	vector <int> arr(n+1);
	
	for(int i=1; i<=n; i+=1){
		
		cin>>arr[i];
		
		total += arr[i];
	}
	
	long long int dp[n+1][n+1];
	
	for(int i=1; i<=n; i+=1){
		
		dp[i][i] = arr[i];
	}
	
	for(int i=1; i+1<=n; i+=1){
		
		dp[i][i+1] = max(arr[i],arr[i+1]);
	}
	
	for(int i=2; i<n; i+=1){
		
		for(int j=1; j+i<=n; j+=1){
			
			long long int x = arr[j] + min(dp[j+2][j+i],dp[j+1][j+i-1]);
			
			long long int y = arr[j+i] + min(dp[j+1][j+i-1],dp[j][i+j-2]);
			
			dp[j][j+i] = max(x,y);
		}
	}
	
	long long int X = dp[1][n];
	
	long long int Y = total - X;
	
	cout<<X-Y<<endl;
}

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

int main() {
    long n, a, ans = 0, b;
    cin >> n;
    vector<long> num(n);
    rep(i, n) {
        cin >> a;
       num.at(i) = a - (i + 1);
    }
    sort(num.begin(), num.end());
    b = num.at(n / 2);
    rep(i, n) ans += abs(num.at(i) - b);
    cout << ans << endl;
}

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

int main(){
  int N,a,b,c,d,e,f,g,h,i;
  cin >> N;
  a=N/100000000;
  b=N%100000000/10000000;
  c=N%10000000/1000000;
  d=N%1000000/100000;
  e=N%100000/10000;
  f=N%10000/1000;
  g=N%1000/100;
  h=N%100/10;
  i=N%10;

  if(N%(a+b+c+d+e+f+g+h+i)==0)
    cout << "Yes";
  else cout << "No";
  
} 

Measured memory_bytes: 256
# B 
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))
a,b=nm()

if a<=0<=b:
    print('Zero')
elif b<0:
    if (b-a+1)%2==1:
        print('Negative')
    elif (b-a+1)%2==0:
        print('Positive')
elif 0<a:
    print('Positive')
    


Measured memory_bytes: 3060
N,M=map(int,input().split())
X=list(map(int,input().split()))
X.sort()
Y=[]
for i in range(M-1):
  Y.append(X[i+1]-X[i])
Y.sort()
if M<=N:
  print(0)
else:
  print(sum(Y[:M-N]))

Measured memory_bytes: 13968
#include <cstdio>
#include <string>
#include <iostream>
#include <vector>
#include <list>
#include <cmath>
#include <iomanip>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <numeric>

typedef unsigned long long ULONG;
typedef long long LONG;
using namespace std;

#define PI 3.1415926535897932384626433
#define _DBG_

#define BIG 10000000000 //10

#define LAST 10000000 //10^7

#define MOD (LONG)(10e8 + 7)



int main(void) {
	int N;
	cin >> N;
	vector<int> a(N);
	int count = 0;
	for (int i = 0; i < N; i++) {
		cin >> a[i];
	}
	for (int i = 0; i < N; i++) {
		if ((i+1) % 2 == 1 && a[i] % 2 == 1) {
			count++;
		}
	}



	cout << count << endl;
	return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define REP(i, n) for(long long i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;

int main(){
  int m;
  cin >> m;
  cout << 24 + (24 - m);
}

Measured memory_bytes: 256
use std::io;

fn main() {
    let mut input = String::new();
    io::stdin().read_line(&mut input).unwrap();
    let (n, k) = {
        let parameters: Vec<usize> = input.trim().split_whitespace().map(|e| e.parse().unwrap()).collect();
        (parameters[0], parameters[1])
    };
    input.clear();
    io::stdin().read_line(&mut input).unwrap();
    let hs: Vec<isize> = input.trim().split_whitespace().map(|h| h.parse().unwrap()).collect();

    let mut costs = vec![0; n];
    costs[1] = (hs[1] - hs[0]).abs();
    for i in 2..n {
        costs[i] = (1..(k + 1)).filter(|j| i >= *j).map(|j| (hs[i] - hs[i - j]).abs() + costs[i - j]).min().unwrap();
    }

    println!("{}", costs[n - 1]);
}

Measured memory_bytes: 8444
#include <stdio.h>

int main(){
    int A,B,C,D;
    scanf("%d%d%d%d",&A,&B,&C,&D);
    while(1){
        C -= B;
        if(C<=0){
            printf("Yes\n");
            return 0;
        }
        A -= D;
        if(A<=0){
            printf("No\n");
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 1660
#include<stdio.h>
#include<ctype.h>
int main(){
	int a=0,c,d;
	char b[1200];
	while(1){
		scanf("%c",&b[a]);
		if(b[a]=='\n')
		break;
		if(islower(b[a])!=0){//?°????????????????
			printf("%c",b[a]=toupper(b[a]));
		}
		else if(isupper(b[a])!=0){//??§???????????????
			printf("%c",tolower(b[a]));
		}
else{
printf("%c",b[a]);
}
			
		a++;
	}
	printf("\n");
return 0;
}

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

int main(){
    int r[]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int k;
    cin>>k;
    cout << r[k-1];
    return 0;
}

Measured memory_bytes: 256
cards = {}
cards['a'] = gets.chomp.split('')
cards['b'] = gets.chomp.split('')
cards['c'] = gets.chomp.split('')

teban = 'a'
while true do
  if (cards[teban] == [])
    puts teban.upcase
    exit
  end
  teban = cards[teban].shift
end

Measured memory_bytes: 1788
int main(){
  long int a,b;
  scanf("%ld%ld",&a,&b);
  if(a>b){
    a%=b;
    if((int)a==0){
      printf("%d",0);
    }else{
      b%=a;
      if(a<b) printf("%ld",a);
      else printf("%ld",b);
    }
  }else{
    b-=a;
    if(b<a) printf("%ld",b);
    else printf("%ld",a);
  }
  return 0;
}

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

int main()
{
	int a, b, c, d;

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

	if (abs(a-b) <= d and abs(b - c) <= d)
	{

		cout << "Yes" << endl;
	}
	else if (abs(a - c) <= d)
	{
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
public class Main{
    public static void main(String[] args)throws IOException{
    InputStreamReader is = new InputStreamReader(System.in);       
    BufferedReader br = new BufferedReader(is);
    
        Integer sum = 0; //?????°???????´????????????°
        Integer ave = 0; //????????????????´????????????°
        Integer num = 0; //??\?????????????????°????????????????????°
        Integer loop = 0; //????????????????????°????????????????????°
        Integer divide = 0; //?????????????±???????????????????????±????????????°
        Integer Referee = 0; //????????°???????´????????????°
        
        //????????°?????\???
        //System.out.println("????????°?????\?????????????????????.");
        
        //??\????????????????????°???int???????????????Referee?????£??\???0??\??????????¶???????
        while((Referee = Integer.parseInt(br.readLine() ) )!= 0){
        
        //????´???°?????\????????????????????°??§??????
        ArrayList<Integer> element = new ArrayList<Integer>(Referee);
        
            //????????°?????????????????????
            for (int y = 0; y < Referee; y++){
                //?????°?????\???
                //System.out.println("?????°?????\?????????????????????.");
                String Points = br.readLine();
            
                //??\?????????????????°???int???????????????num?????£??\
                num = Integer.parseInt(Points);
                //ArrayList?????????
                element.add(num);
            }
            
            //????´????????????????
            Collections.sort(element);
            
            //????´???°??????1???????????§?????§????????????
            loop = element.size() - 1;
            
            //1?????????????????§????°?????????????
            sum = 0;
            for (int i = 1; i < loop; i++){
                sum += element.get(i);
            }
            
            //????°??????¨?????§??????????????????????????°??????2??????????????°????±???????
            divide = element.size() - 2;
            
            
            ave = sum / divide;
            
        
        System.out.println(ave);
        }
        //System.out.println(sum);   
        
        //System.out.println(loop);
        
        
    }
}

Measured memory_bytes: 24620
#include <stdio.h>
#include <complex>
#include <vector>
#include <algorithm>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef complex<double> P;
#define EPS (1e-6)

P readP() {
    double x, y;
    scanf("%lf%lf", &x, &y);
    return P(x, y);
}

double radius(const vector<P>& ps) {
    P p = P(0, 0);
    double cur = 1.0;
    rep (dep, 30) {
        rep (_, 100) {
            double mx = norm(ps[0]-p);
            int ix = 0;
            rep (i, ps.size()) {
                const double d = norm(ps[i]-p);
                if (mx < d) mx = d, ix = i;
            }
            p += cur*(ps[ix]-p);
        }
        cur *= 0.5;
    }
    double ans = 0;
    rep (i, ps.size()) ans = max(ans, abs(ps[i]-p));
    return ans;
}

int n, m;
double rs[128], ts[128];
bool used[128];

bool can(int k) {
    vector<double> a, b;
    rep (i, n) if (!used[i]) a.push_back(rs[i]);
    rep (i, m) if (i >= k) b.push_back(ts[i]);
    sort(a.begin(), a.end());
    reverse(a.begin(), a.end());
    sort(b.begin(), b.end());
    reverse(b.begin(), b.end());
    rep (i, b.size()) if (b[i] > a[i]+EPS) return false;
    return true;
}

int main() {
    scanf("%d%d", &n, &m);
    rep (i, n) scanf("%lf", rs+i);
    rep (i, m) {
        int K;
        scanf("%d", &K);
        vector<P> ps;
        rep (_, K) ps.push_back(readP());
        ts[i] = radius(ps);
    }
    if (!can(0)) puts("NG");
    else {
        rep (k, m) rep (i, n) if (!used[i] && ts[k] <= rs[i]+EPS) {
            used[i] = 1;
            if (can(k+1)) { printf("%d\n", i+1); break; }
            used[i] = 0;
        }
    }
    return 0;
}

Measured memory_bytes: 1116
#include <iostream>

using namespace std;

int main() {
    long long ans = 3, prev = 1, prevprev = 2;
    int n;
    cin >> n;
    if (n == 0) {
        cout << prevprev << endl;
        return 0;
    }
    if (n == 1) {
        cout << prev << endl;
        return 0;
    }
    for (int i = 2; i < n; i++) {
        prevprev = prev;
        prev = ans;
        ans += prevprev;
    }
    cout << ans << endl;
    return 0;
}

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

#ifdef LOCAL
#include "../lib/dump.hpp"
#else
#define dump(...)
#define dumpv(...)
#endif

typedef long long ll;
typedef pair<int, int> P;
const int MOD = 1e9 + 7;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;

ll gcd(ll a, ll b) { return (a == 0) ? b : gcd(b % a, a); }

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  // freopen("temp.1", "r", stdin);

  int N;
  cin >> N;
  vector<ll> a(N);
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }
  vector<ll> al(N);
  vector<ll> ar(N);
  al[0] = a[0];
  for (int i = 1; i < N; i++) {
    al[i] = gcd(a[i], al[i - 1]);
  }
  ar[N - 1] = a[N - 1];
  for (int i = N - 2; 0 <= i; i--) {
    ar[i] = gcd(a[i], ar[i + 1]);
  }
  dump(al, ar);
  ll ans = 0;
  for (int i = 0; i < N; i++) {
    ll g;
    if (i == 0)
      g = ar[i + 1];
    else if (i == N - 1)
      g = al[i - 1];
    else
      g = gcd(al[i - 1], ar[i + 1]);
    ans = max(ans, g);
    dump(g, ans);
  }
  cout << ans << endl;
  return 0;
}

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

int main(){
	char *state;
	state = (char*)malloc(sizeof(char)*100001);
	scanf("%s", state);
	int i = 0, count = 0;
	char current = state[0];
	while(state[i] !='\0'){
		if(state[i] != current){
			count++;
			current = state[i];
		}
		i++;
	}
	printf("%d", count);
	free(state);
	return 0;
}

Measured memory_bytes: 256
n = int(input())
s = list(input())
ans = 0

R = [0] * n
G = [0] * n
B = [0] * n

r = 0
g = 0
b = 0

for i in range(n):
    if s[i] == "R":
        r += 1
        R[i] = r
    elif s[i] == "G":
        g += 1
        G[i] = g
    else:
        b += 1
        B[i] = b

for i in range(n-2):
    for j in range(i+1,n-1):
        x = s[i]
        y = s[j]
        
        if x != y:
            if "R" not in [x,y]:
                ans += R[n-1] - R[j]
                
                if 2*j-i < n:
                    if s[2*j-i] == "R":
                        ans -= 1
                    
            if "G" not in [x,y]:
                ans += G[n-1] - G[j]
                
                if 2*j-i < n:
                    if s[2*j-i] == "G":
                        ans -= 1
                    
            if "B" not in [x,y]:
                ans += B[n-1] - B[j]
                
                if 2*j-i < n:
                    if s[2*j-i] == "B":
                        ans -= 1
    
print(ans)

Measured memory_bytes: 74612
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll inf = 1e18;
ll w[110], v[110];
ll dp[110][100010];

int main() {
    int N,W;
    cin >> N >> W;
    for (int i = 1; i <= N; i++) {
        cin >> w[i] >> v[i];
    }
    for (int i = 1; i <= N; i++) {
        for (int j = W; j >= 0; j--) {
            dp[i][j] = max(dp[i][j], dp[i-1][j]);
            if (j - w[i] >= 0) {
                dp[i][j - w[i]] = max(dp[i][j - w[i]], dp[i-1][j] + v[i]);
            }
        }
    }
    ll mx = 0;
    for (int i = 0; i <= W; i++) {
        mx = max(mx, dp[N][i]);
    }
    cout << mx << endl;
    return 0;
}

Measured memory_bytes: 79360
#include <stdio.h>

int main(void)
{
  int a, b;
  scanf("%d %d", &a, &b);

  if (a < b) {
    printf("a < b\n");
  }
  else if (a == b) {
    printf("a == b\n");
  }
  else {
    printf("a > b\n");
  }

  return 0;
}

Measured memory_bytes: 580
#include<bits/stdc++.h>
#include<iostream>
using namespace std;
int main(){
  int n,W;
  cin>>n>>W;
  std::vector<int> weight(n) ;
  vector<int> value(n);
  for(int i=0;i<n;i++){
      cin>>weight[i]>>value[i];
  }
  int max_val = 0;
  for(int i =0;i<n;i++){
      max_val+=value[i];
  }
  vector<vector<long long int> > op(n+1,vector<long long int>(max_val+1,INT_MAX));
  for(int i =0;i<op.size();i++){
      op[i][0] = 0;
  }
  for(int i =1;i<n+1;i++){
      for(int j = 1;j<max_val+1;j++){
          op[i][j] = op[i-1][j];
          if(value[i-1]<=j){
              op[i][j] = min(op[i][j],op[i-1][j-value[i-1]] + weight[i-1]);
          }
      }
  }
  int res =0;
  for(int j = 0;j<max_val+1;j++){
      if(op[n][j]<=W){
          res = j;
      }
  }
  std::cout << res << std::endl;
  return 0;
}

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

using namespace std;

const int mod = 1e9 + 7;

int main() {
	int h, w, sol[1005][1005];
	char ch;
	cin >> h >> w;
	for (int i = 1; i <= h; ++i)
		for (int j = 1; j <= w; ++j){
			cin >> ch;
			if (ch == '.')
				sol[i][j] = 0;
			else
				sol[i][j] = -1;
		}
	if (sol[1][1] == -1) sol[1][1] = 0;
	else sol[1][1] = 1;
	
	for (int i = 2; i <= h; ++i){
		if (sol[i][1] == -1) {sol[i][1] = 0; break;}
		sol[i][1] = (1LL * sol[i][1] + sol[i - 1][1]) % mod;
	}
	for (int j = 2; j <= w; ++j){
		if (sol[1][j] == -1) {sol[1][j] = 0; break;}
		sol[1][j] = (1LL * sol[1][j] + sol[1][j - 1]) % mod;
	}
	
	for (int i = 2; i <= h; ++i)
		for (int j = 2; j <= w; ++j)
			if (sol[i][j] == -1) sol[i][j] = 0;
			else if (sol[i - 1][j] == -1 && sol[i][j - 1] == -1) sol[i][j] = 0;
			else if (sol[i - 1][j] == -1) sol[i][j] = sol[i][j - 1];
			else if (sol[i][j - 1] == -1) sol[i][j] = sol[i - 1][j];
			else sol[i][j] = (1LL * sol[i - 1][j]  + sol[i][j - 1]) % mod;
	cout << sol[h][w];
	return 0;
}

Measured memory_bytes: 4224
S = list(input())
for i in range(len(S)):
    S[i] = int(S[i])

K = int(input())

start = 1
loc = 101
for i in range(len(S)):
    if S[i] != 1:
        start = S[i]
        loc = i
        break

if K > 100:
    print(start)
elif K-1 >= loc:
    print(start)
else:
    print(1)

Measured memory_bytes: 38384
#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)
using LL = long long;
using ULL = unsigned long long;

int main()
{
	int n, a;
	cin >> n;
	map<int, int> mp;
	LL ans = 0;
	Rep(i, n) {
		scanf("%d", &a);
		++mp[a+i];
		ans += mp[i-a];
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 20644
#include <stdio.h>

int main(){
  int i,j,k,flag = 0;
  int a[10];
  for(i=0;i<5;i++)scanf("%d\n",&a[i]);
  scanf("%d",&k);
  
  for(i=0;i<5;i++){
    for(j=0;j<5;j++){
      if(a[j]-a[i] >k)flag = 1;
    }
  }
  if(flag == 0) printf("Yay!");
  else printf(":(");
  return 0;
}

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

int main(){
  int n,cnt,cnt1;
  cnt=cnt1=0;
  scanf("%d",&n);
  for(int i=1;i<=n;i+=2){
    cnt1=0;
    for(int j=1;j<=i;j++)
      if(i%j==0)
        cnt1++;
    if(cnt1==8)
      cnt++;
  }
  printf("%d\n",cnt);
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define pi acos(-1)
#define mod 1000000009
using namespace std;

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

    int n;
    cin >> n;
    int mx  = 0;
    map<string, int> mp;
    for(int i = 0; i < n; i++){
        string s;
        cin >> s;
        mp[s]++;
        mx = max(mx, mp[s]);
    }
    for(auto it : mp){
        string s = it.first;
        int cnt = it.second;
        if(cnt == mx){
            cout << s << endl;
        }
    }
}


Measured memory_bytes: 23808
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,x,sum=0;
	cin>>n;
	while(n--){
		cin>>x;
		for(int i=1;i*i<=x;i++)
			if((x-i)%(2*i+1)==0)goto L;
		sum++;L:;
	}
	cout<<sum<<endl;
}

Measured memory_bytes: 3064
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define P pair<int, int>
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
const int MAX_Y = 11;
const int MAX_X = 11;
const int INF = 1e9 + 7;

int Y, X, ans;
int my[] = {0, 1, 0, -1};
int mx[] = {1, 0, -1, 0};

void change_color(int y, int x, int color, int bef_color, int v[MAX_Y][MAX_X]){
  //cout <<y <<", " <<x <<endl;
  v[y][x] = color;
  REP(i, 4){
    int ny = y + my[i], nx = x + mx[i];
    if(ny >= 0 && nx >= 0 && ny < Y && nx < X && v[ny][nx] == bef_color) change_color(ny, nx, color, bef_color, v);
  }
}

bool isOK(int v[MAX_Y][MAX_X]){
  REP(i, Y) REP(j, X) if(v[i][j] != v[0][0]) return false;
  return true;
}

int cntColor(int y, int x, int v[MAX_Y][MAX_X], int visited[MAX_Y][MAX_X]){
  int ret = 1;
  visited[y][x] = true;
  REP(i, 2){
    int ny = y + my[i], nx = x + mx[i];
    if(ny >= 0 && nx >= 0 && ny < Y && nx < X && v[ny][nx] == v[0][0] && !visited[ny][nx]) ret += cntColor(ny, nx, v, visited);
  }
  return ret;
}

void dfs(int cnt, int all_cnt, int v[MAX_Y][MAX_X]){
  //cout <<"--------" <<endl;
  //cout <<cnt <<", " <<isOK(v) <<endl;
  //REP(i, Y){
  //  REP(j, X) cout <<v[i][j] <<" ";
  //  cout <<endl;
  //}
  if(isOK(v)) ans = cnt;
  if(cnt >= ans) return ;
  REP(i, 3){
    if(v[0][0] == i) continue;
    //cout <<i <<"->" <<endl;
    int tmp[MAX_Y][MAX_X];
    REP(i, Y) memcpy(tmp[i], v[i], sizeof(v[i]));
    change_color(0, 0, i, v[0][0], tmp);
    int tmptmp[MAX_X][MAX_Y] = {0};
    int c = cntColor(0, 0, tmp, tmptmp);
    //REP(i, Y){
    //  REP(j, X) cout <<tmp[i][j] <<" ";
    //  cout <<endl;
    //}
    if(c > all_cnt) dfs(cnt + 1, c, tmp);
  }
}

int main(){
  int v[MAX_Y][MAX_X];
  while(cin >>X >>Y && Y){
    ans = INF;
    REP(i, Y){
      REP(j, X){
        char tmp; cin >>tmp;
        if(tmp == 'R') v[i][j] = 0;
        if(tmp == 'G') v[i][j] = 1;
        if(tmp == 'B') v[i][j] = 2;
      }
    }
    int tmp[MAX_X][MAX_Y] = {0};
    REP(i, 3) dfs(0, cntColor(0, 0, v, tmp), v);
    cout <<ans <<endl;
  }
  return 0;
}

Measured memory_bytes: 1184
n = int(input())
a = list(input().split())

b = ['' for _ in range(n)]
m = n // 2

b[m] = a[0]

p = 1

for i in range(1, n):
    if i % 2 == 1:
        b[m - p] = a[i]
    else:
        b[m + p] = a[i]
        p += 1

if n % 2 == 1:
    b = list(reversed(b))

print(' '.join(b))

Measured memory_bytes: 26180