akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
#define countof(a) (sizeof(a)/sizeof((a)[0]))
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i < (n); i++)
#define all(a) begin(a),end(a)
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
template<class T> void cout_v(const vector<T>& c)
{ for (int i = 0; i < c.size(); i++) cout << c[i] << endl; }
template<class T> void cout_h(const vector<T>& c)
{ for (int i = 0; i < c.size(); i++) cout << c[i] << (i==c.size()-1?"\n":" "); }
template<class T> inline bool chmin(T& a, T b) {return a>b?a=b,true:false;}
template<class T> inline bool chmax(T& a, T b) {return a<b?a=b,true:false;}
template<class T> void sort3a(T& a,T& b,T& c) {if (a>b) swap(a,b); if (b>c) swap(b,c); if (a>b) swap(a,b);}
#define SP << " " <<
#define FMT(a) #a<<":"<<a 
#define FMT2(a,b) #a<<":"<<a<<", "<<#b<<":"<<b 
#define FMT3(a,b,c) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c 
#define FMT4(a,b,c,d) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c<<", "<<#d<<":"<<d 

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

    string S; cin >>S;

    cout << count(S.begin(), S.end(), '2') <<endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <iostream>
using namespace std;
typedef long long ll;
const int NN = 110000;
int n;
int t, sum, m, a[NN], b[NN], c, a1, b1, x, y, ans;

char s[NN];

int main(){
	//freopen("a.in", "r", stdin);
	//freopen("a.out", "w", stdout);
	
	scanf("%d%d%d", &a1, &b1, &m);
	for (int i=1; i<=a1; i++) scanf("%d", &a[i]);
	for (int i=1; i<=b1; i++) scanf("%d", &b[i]); 
	ans = 0x7fffffff;
	for (int i=1; i<=m; i++){
		scanf("%d%d%d", &x, &y, &c);
		ans = min(ans, a[x] + b[y] - c);
	}
	sort(a+1, a+a1+1);
	sort(b+1, b+b1+1);
	ans = min(ans, a[1] + b[1]);
	
	printf("%lld", ans);
	

	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define INF 1 << 30
#define EPS 1e-10
#define MAX_P 1*1000+5*1000+10*1000+50*1000+100*1000+500*1000

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

int P, N[6], p[6] = {1, 5, 10, 50, 100, 500};

int change(int m){
  int c = m-P, res = 0;
  for(int i = 5; i >= 0; i--){
    if(c/p[i]){
      int use = c/p[i];
      res += use;
      c -= use*p[i];
    }
  }
  /*  //  printf("%d %d\n", c, res);
  if(c/500){
    int use = c/500;
    res += use;
    c -= use*500;
  }
  //  printf("%d\n", res);
  if(c/100){
    int use = c/100;
    res += use;
    c -= use*100;
  }
  //  printf("%d\n", res);
  if(c/50){
    int use = c/50;
    res += use;
    c -= use*50;
  }
  //  printf("%d\n", res);
  if(c/10){
    int use = c/10;
    res += use;
    c -= use*10;
  }
  //  printf("%d\n", res);
  if(c/5){
    int use = c/5;
    res += use;
    c -= use*5;
  }
  //  printf("%d\n", res);
  res += c;*/

  return res;
}

int pay(int m){
  int res = 0, use;
  if(m/500){ use = min(m/500, N[5]); res += use; m -= use*500;}
  //  printf("%d\n", res);
  if(m/100){ use = min(m/100, N[4]); res += use; m -= use*100;}
  //  printf("%d\n", res);
  if(m/50){ use = min(m/50, N[3]); res += use; m -= use*50;}
  //  printf("%d\n", res);
  if(m/10){ use = min(m/10, N[2]); res += use; m -= use*10;}
  //  printf("%d\n", res);
  if(m/5){ use = min(m/5, N[1]); res += use; m -= use*5;}
  //  printf("%d\n", res);
  if(m){ use = min(m, N[0]); res += use; m -= use;}
  if(m) return INF;
  else return res;
}

int main(){
  while(scanf("%d%d%d%d%d%d%d", &P, &N[0], &N[1], &N[2], &N[3], &N[4], &N[5]) && P){
    int res = INF, sum = N[0]*p[0]+N[1]*p[1]+N[2]*p[2]+N[3]*p[3]+N[4]*p[4]+N[5]*p[5];
    //    printf("%d %d\n", P, sum);
    REP(i, P, sum+1){
      //            printf("%d %d %d\n", i, change(i), pay(i));
      res = min(res, change(i)+pay(i));
    }

    printf("%d\n", res);
  }
  return 0;
}

Measured memory_bytes: 1188
#include<bits/stdc++.h>
#define ll long long
#define inf(x) (ll)(1e##x)
using namespace std;
int H,W,s1[110][110],s2[110][110],MX1,MX2,MX3,MX4;
char mp[110][110];
struct DP{
	int f[10001000];
	int& operator () (int a,int b,int c,int d){
		return f[a*MX2*MX3*MX4+b*MX3*MX4+c*MX4+d];
	}
}f;
void chmax(int &a,int b){if(b>a) a=b;}
int main(){
	cin>>H>>W;
	int x=0,y=0;
	for(int i=1;i<=H;i++){
		cin>>mp[i]+1;
		for(int j=1;j<=W;j++){
			if(mp[i][j]=='E') x=i,y=j;
			s1[i][j]=s1[i][j-1]+(mp[i][j]=='o');
			s2[j][i]=s2[j][i-1]+(mp[i][j]=='o');
		}
	}
	MX1=x;MX2=H-x+1;MX3=y;MX4=W-y+1;
	int ans=0;
	for(int a=0;a<MX1;a++)
		for(int b=0;b<MX2;b++)
			for(int c=0;c<MX3;c++)
				for(int d=0;d<MX4;d++){
					int U=min(a,MX1-b-1),D=min(b,MX2-a-1),L=min(c,MX3-d-1),R=min(d,MX4-c-1);
					if(MX1-b>a+1) chmax(f(a+1,b,c,d),f(a,b,c,d)+s1[x-a-1][y+R]-s1[x-a-1][y-L-1]);
					if(MX2-a>b+1) chmax(f(a,b+1,c,d),f(a,b,c,d)+s1[x+b+1][y+R]-s1[x+b+1][y-L-1]);
					if(MX3-d>c+1) chmax(f(a,b,c+1,d),f(a,b,c,d)+s2[y-c-1][x+D]-s2[y-c-1][x-U-1]);
					if(MX4-c>d+1) chmax(f(a,b,c,d+1),f(a,b,c,d)+s2[y+d+1][x+D]-s2[y+d+1][x-U-1]);
					chmax(ans,f(a,b,c,d));
				}
	cout<<ans<<'\n';
	return 0;
}

Measured memory_bytes: 27008
S = input()
flag = True
for i in range(2 ** 4):
    C = ''
    for j in range(4):
        if ((i >> j) & 1):
            C = C + 'A'
        if j == 0:
            C = C + 'KIH'
        elif j == 1:
            C = C + 'B'
        elif j == 2:
            C = C + 'R'
    if C == S:
        break
else:
    print('NO')
    flag = False
if flag:
    print('YES')
    

    

Measured memory_bytes: 3060
import java.util.LinkedList;
import java.util.Scanner;

public class Main{
    
 
    public static void main(String[] args)  {
        new Main().solve();
    }

    void solve(){
        Scanner sc = new Scanner(System.in);        
        String S = sc.next();

        LinkedList<String> string = new LinkedList<String>();

        for(int i=0; i<S.length(); i++){
            String s1 = "";
            s1 = String.valueOf(S.charAt(i));
            string.push(s1);
        }
        
        int N = S.length();
        StringBuilder sb1 = new StringBuilder();
        for (int i=0; i<(N-1)/2; i++){
            sb1.append(string.get(i));
        }

        StringBuilder sb2 = new StringBuilder();
        for (int i=(N+3)/2-1; i<N; i++){
            sb2.append(string.get(i));
        }

        String s1 = sb1.toString();
        String s2 = sb2.toString();

        if(s1.equals(s2)){
            System.out.println("Yes");
        }
        else{
            System.out.println("No");
        }

    }
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
using t_map = vector<vector<char>>;

bool check_mine(t_map & A, int x, int y) {
    if (x < 0 || y < 0 || x > A.at(0).size() - 1 || y > A.size() - 1) {
        return false;
    } else {
       if (A.at(y).at(x) == '#') return true;
       else return false;
    }
}

int sum_mine(t_map & A, int x, int y) {
    int count = 0;
    for (int i = -1; i < 2; i++) {
        for (int j = -1; j < 2; j++) {
            if (check_mine(A, x + j, y + i) && !(i == 0 && j == 0))
                ++count;
        }
    }
    return count;
}


int main() {
    int H, W;
    cin >> H >> W;

    t_map map(H, vector<char>(W));
    vector<pair<int, int>> mine_place;
    for(int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            cin >> map.at(i).at(j);
            if (map.at(i).at(j) == '#') {
                mine_place.push_back(make_pair(i, j));
            }
            //cout << map.at(i).at(j);
        }
        //cout << endl;
    }

    using t_ans = vector<vector<int>>;
    t_ans ans(H, vector<int>(W));
    for(int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            if (!check_mine(map, j, i)) {
                ans.at(i).at(j) = sum_mine(map, j, i);
                cout << ans.at(i).at(j);
            } else {
                cout << '#';
            }
        }
        cout << endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>

using namespace std;

int main()
{
	int n;
	cin >> n;
	int side = n / 3;
	int remain = n % 3;

	double d = remain / 3.0;

	double total = d + side;

	cout << fixed << setprecision(7) << total * total * total;

    return 0;
}


Measured memory_bytes: 256
# -*- coding:utf-8 -*-

data = input()
n = [0]*5
n[0],n[1],n[2],n[3],n[4] = map(int,data.split(' '))

count = 0
while True:
    for i in range(len(n)-1):
        if n[i] < n[i+1]:
            tmp = n[i]
            n[i] = n[i+1]
            n[i+1] = tmp
    count += 1
    if count == 5:
        break

for i in range(len(n)-1):
    print(n[i],end=' ')

print(n[len(n)-1])

Measured memory_bytes: 7696
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<pint> vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=n-1;i>=(0);i--)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define all(v) (v).begin(),(v).end()
#define eall(v) unique(all(v), v.end())
#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 int MOD = 1e9 + 7;
const int INF = 1e9;
const ll INFF = 1e18;

string s;
int cnt[30];
int main(void){
	cin >> s;
	for(auto u : s){
		cnt[u - 'a']++;
	}
	int n = (int)s.size();
	int d = 0;
	rep(i, 30) if(cnt[i] % 2) d++;
	int ans = INF;
	chmin(ans, d / 2);
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 3248
#include <math.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

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

ull absol(ll number)
{
  if (number < 0)
    return((-1) * number);
  else
    return(number);
}

int main(void) {
  int scan; // scanf result
  ull n; // to input 
  ull k; // to input 

  scan = scanf("%llu", &n);
  scan = scanf("%llu", &k);

  if (k == 1)
    printf("0");
  else if (n == k)
    printf("0");
  else if (n < k)
  {
    if (absol(n - k) > n)
      printf("%llu", n);
    else
      printf("%llu", absol(n - k));
  }
  else if (n % k < k)
  {
    if (n % k - k < n % k)
      printf("%llu", n % k);
    else
      printf("%llu", absol(n % k - k));
  }
  else
    printf("%llu", absol(n % (n - k)));

  return (0);
}


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

int main(){
  int N,K;
  cin >> N >> K;
  
  int count = 0;
  int totyu = N;
  
  while(totyu > 0){
    totyu = totyu / K;
    count++;
  }
  
  cout << count << endl;
}

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

 using namespace std;
 typedef long long ll;
 #define rep(i, n) for(int i = 0; i < (int)(n); i++)

 int main() {
   ll N, M, ans = 1;
   cin >> N >> M;
   if (abs(N - M) > 1) ans = 0;
   else {
      rep(i, N) {
        ans *= i + 1;
        ans %= 1000000007;
      }
      rep(i, M) {
        ans *= i + 1;
        ans %= 1000000007;
      }
      if (N == M) {
        ans *= 2;
        ans %= 1000000007;
      }
   }

   cout << ans << endl;
 }


Measured memory_bytes: 256
class UFT < Array
  def root x
    if self[x] == x
      x
    else
      self[x] = root(self[x])
    end
  end

  def same(x, y)
    return root(x) == root(y)
  end

  def unite(x, y)
    rootx = root(x)
    rooty = root(y)

    if (rootx == rooty)
      return
    else
      self[rootx] = rooty
    end
  end
end

N, M = gets.split.map(&:to_i)
uft = UFT.new(N.times.map(&:itself))
p = gets.split.map(&:to_i)

M.times do
  x, y = gets.split.map(&:to_i)
  uft.unite(x-1, y-1)
end

cnt = 0
p.each.with_index do |d, i|
  cnt += 1 if uft.same(i, d-1)
end

puts cnt


Measured memory_bytes: 12428
#include <iostream>
#include <cstring>
using namespace std;
char c[10];
int main(void)
{
  cin>>c;
  int l=strlen(c);
  if(c[l-1]=='2'||c[l-1]=='4'||c[l-1]=='7'||c[l-1]=='5'||c[l-1]=='9')cout<<"hon"<<endl;
  else if(c[l-1]=='3')cout<<"bon"<<endl;
  else cout<<"pon"<<endl;
  return 0;
}

Measured memory_bytes: 3068
N,x = (list(map(int,input().split())))
a = (list(map(int,input().split())))
a.sort()
out = 0
for i in a:
    if x>=i:
        x-=i
        out +=1
    else:
        break
else:
    if x != 0:
        out -=1
print(out)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define eachdo(e,array) for(const auto& e : array)
#define upper_index(v,a) (int)distance(v.begin(), upper_bound((v).begin(),(v).end(),a))
template<class T> bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
typedef long long ll;
const ll INF=1e18;
const ll MOD=1e9+7;


const ll monoidUnit=2147483647;
ll monoidOperator(ll a,ll b){return min(a,b);} 

ll fixedArraySize;
vector<ll> segmentTree;

void initialize(int arraySize){
    fixedArraySize=1;
    while(fixedArraySize<arraySize) fixedArraySize*=2;
    segmentTree.resize(fixedArraySize*2-1);
    rep(i,fixedArraySize*2-1) segmentTree[i]=monoidUnit;
}

void update(int index,ll value){
    index+=fixedArraySize-1;
    segmentTree[index]=value;
    while(0<index){
        index=(index-1)/2;
        segmentTree[index]=monoidOperator(segmentTree[index*2+1],segmentTree[index*2+2]);
    }
}

ll recursiveQuery(int a,int b,int k,int l,int r){
    if(r<=a || b<=l) return monoidUnit;
    if(a<=l && r<=b) return segmentTree[k];
    else{
        ll vl=recursiveQuery(a,b,k*2+1,l,(l+r)/2);
        ll vr=recursiveQuery(a,b,k*2+2,(l+r)/2,r);
        return monoidOperator(vl,vr);
    }
}

ll query(int a,int b){return recursiveQuery(a,b,0,0,fixedArraySize);}


int main(){
    int N,Q;cin>>N>>Q;
    initialize(N);
    rep(i,Q){
        int com,x,y;cin>>com>>x>>y;
        if(com==1) cout<<query(x,y+1)<<endl;
        else update(x,y);
    }

}


Measured memory_bytes: 4912
n,k=[int(i) for i in input().split()]
a=[int(i) for i in input().split()]
count=1
a.sort()
#print(a)
num=[]
count_kakikae=0

for i in range(1,n):
    if a[i]==a[i-1]:
        count=count+1
    else:
        num.append(count)
        count=1
    if i==n-1:
        num.append(count)

#print(num)

num.sort()

if len(num)-k>0:
    for i in range(len(num)-k):
        count_kakikae=count_kakikae+num[i]

print(count_kakikae)

Measured memory_bytes: 25768
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
#define P pair<int,ll>
const int MOD=1e9+7;
const ll INF=2e18;



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

    int n;
    cin >> n;
    vector<vector<P>> r(n); 
    rep(i,n-1) {
        ll a,b,c;
        cin >> a >> b >> c;
        r[a-1].push_back({b-1,c});
        r[b-1].push_back({a-1,c});
    } 
    int q,k;
    cin >> q >> k;
    priority_queue<P,vector<P>,greater<P>> pq;
    pq.push({k-1,0});
    vector<ll> cost(n,INF);
    cost[k-1]=0;
    while (!pq.empty()) {
        P p=pq.top();
        pq.pop();
        int now=p.first;
        rep(i,r[now].size()) {
            int next=r[now][i].first;
            ll nc=cost[now]+r[now][i].second;
            if (cost[next]>nc) {
                cost[next]=nc;
                pq.push({next,nc});
            }
        }
    }
    rep(i,q) {
        int x,y;
        cin >> x >> y;
        cout << cost[x-1]+cost[y-1] << endl;
    }
    return 0;   
}


Measured memory_bytes: 11120
using System;
using System.Collections.Generic;

namespace AtCoder_B
{
    class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            var s = cin.Read();

            var a1 = int.Parse(s.Substring(0, 2));
            var a2 = int.Parse(s.Substring(2, 2));

            bool b1 = (a1 > 0 && a1 <= 12);
            bool b2 = (a2 > 0 && a2 <= 12);

            if (b1 && b2) Console.WriteLine("AMBIGUOUS");
            else if (b1 && !b2) Console.WriteLine("MMYY");
            else if (!b1 && b2) Console.WriteLine("YYMM");
            else Console.WriteLine("NA");
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read()
        {
            if (inputStream.Count != 0) return inputStream.Dequeue();
            string[] tmp = _stream.ReadLine().Split(_separator);
            for (int i = 0; i < tmp.Length; ++i)
            {
                inputStream.Enqueue(tmp[i]);
            }
            return inputStream.Dequeue();
        }
        public string ReadLine() { return _stream.ReadLine(); }
        public int ReadInt() { return int.Parse(Read()); }
        public long ReadLong() { return long.Parse(Read()); }
        public double ReadDouble() { return double.Parse(Read()); }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read(); return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt(); return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong(); return ret; }
    }
}


Measured memory_bytes: 11220
#include <stdio.h>
#include <algorithm>

using namespace std;

int main() {
	int n, d[100010], mid;
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
		scanf("%d", &d[i]);
	sort(d, d + n);
	mid = n / 2;
	printf("%d\n", d[mid] - d[mid - 1]);
	return 0;
}

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

int main(int argc, char const *argv[])
{
	int n;
	cin>>n;
	char s[n][n];
	for (int i = 0; i < n; ++i)
	{
		for (int j = 0; j < n; ++j)
		{
			cin>>s[i][j];
		}
	}
	int ans=0;
	for (int i = 0; i < n; ++i)
	{
		int f=1;
		for (int j = 0; j < n; ++j)
		{
			for (int k = 0; k < n; ++k)
			{
				if (s[(k+j)%n][(j+i)%n]!=s[(j)%n][(k+j+i)%n])
				{
					f=0;
				}
			}
		}
		if (f)
		{
			ans+=n;
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 384
def d_11(MOD=10**9 + 7):
    class Combination(object):
        """参考: https://harigami.net/contents?id=5f169f85-5707-4137-87a5-f0068749d9bb"""
        __slots__ = ["mod", "factorial", "inverse"]

        def __init__(self, max_n: int = 10**6, mod: int = 10**9 + 7):
            fac, inv = [1], []
            fac_append, inv_append = fac.append, inv.append

            for i in range(1, max_n + 1):
                fac_append(fac[-1] * i % mod)

            inv_append(pow(fac[-1], mod - 2, mod))

            for i in range(max_n, 0, -1):
                inv_append(inv[-1] * i % mod)

            self.mod, self.factorial, self.inverse = mod, fac, inv[::-1]

        def combination(self, n, r):
            if n < 0 or r < 0 or n < r:
                return 0
            return self.factorial[n] * self.inverse[r] * self.inverse[n - r] % self.mod

    N = int(input())
    A = [int(i) for i in input().split()]
    # 重複した数のインデックスを求める
    appeared = set()
    for k, a in enumerate(A):
        if a in appeared:
            left, right = A.index(a), k
            break
        appeared.add(a)

    c = Combination(N + 1).combination
    ans = [(c(N + 1, k) - c(N - (right - left), k - 1)) % MOD for k in range(1, N + 2)]
    return '\n'.join(map(str, ans))

print(d_11())

Measured memory_bytes: 31568
def main():
    n = int(input())
    cnt = [1] * (n + 1)

    for i in range(2, n + 1):
        cnt[i] += 1
        for j in range(i * 2, n + 1, i):
            cnt[j] += 1
    #print(cnt)

    res = 0
    for i in range(1, n + 1):
        res += i * cnt[i]
    print(res)
if __name__ == '__main__':
    main()

Measured memory_bytes: 146012
K = int(input())

def calculate(k):

    if k % 2 == 0:
        print(-1)
        return

    if k % 5 == 0:
        print(-1)
        return

    res = 1

    m = (((10 ** res) - 1) // 9) * 7


    while m % k > 0:
        res += 1
        m = m % k
        m = m * 10 + 7

    print(res)


calculate(K)



Measured memory_bytes: 9000
#include<bits/stdc++.h>
#define ll long long
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define per(i,n,a) for(int i=n;i>=a;i--)
#define endl '\n'
#define mem(a,b) memset(a,b,sizeof(a))
#define IO ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
const int INF=0x3f3f3f3f;
const ll inf=0x3f3f3f3f3f3f3f3f;
const int mod=1e9+7;
const int maxn=1e5+5;
int main(){
	string s,t;cin>>s>>t;
	if(t.length()==s.length()+1){
		int flag=0;
		for(int i=0;i<s.length();i++){
			if(s[i]!=t[i]){
				flag=1;break;
			}
		}
		if(flag) puts("No");
		else puts("Yes");
	}else{
		puts("No");
	}
}


Measured memory_bytes: 3628
W,H,N = list(map(int, input().split()))
mesh = [[0]*W for i in range(H)]
points = []
for i in range(N):
    points.append(list(map(int, input().split())))

for i in range(N):
    selection = points[i][2]
    if selection == 1:
        for j in range(0,H):
            for k in range(0, points[i][0]):
                mesh[j][k] = 1
    elif selection == 2:
        for j in range(0,H):
            for k in range(points[i][0], W):
                mesh[j][k] = 1
    elif selection == 3:
        for j in range(0, points[i][1]):
            for k in range(0,W):
                mesh[j][k] = 1
    elif selection == 4:
        for j in range(points[i][1], H):
            for k in range(0,W):
                mesh[j][k] = 1
    else:
        print("invalid value!")

colored_sum = 0
for i in range(H):
    colored_sum += sum(mesh[i])

white_sum = W*H - colored_sum
print(white_sum)


Measured memory_bytes: 3188
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>

#include <bits/stdc++.h>
#include <cmath>
#include <limits>

using namespace std;

int main(int argc, char* argv[]){
	int sx, sy, tx, ty;
	int dx, dy;

	cin >> sx >> sy >> tx >> ty;

	dx = abs(sx - tx);
	dy = abs(sy - ty);

	for(int i=0; i<dx; i++) putchar('R');
	for(int i=0; i<dy; i++) putchar('U');
	for(int i=0; i<dx; i++) putchar('L');
	for(int i=0; i<dy; i++) putchar('D');
	putchar('D');
	for(int i=0; i<dx+1; i++) putchar('R');
	for(int i=0; i<dy+1; i++) putchar('U');
	putchar('L');
	putchar('U');
	for(int i=0; i<dx+1; i++) putchar('L');
	for(int i=0; i<dy+1; i++) putchar('D');
	putchar('R');
	putchar('\n');

	return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int64_t zyou(int a,int b){
  int i,ans=1;
  for(i=0;i<b;i++){
    ans=ans*a;
  }
  return ans;
}
int main(){
  string s;
  int64_t k,i=0;
  cin >> s >> k;
  int64_t count=0;
  while(1){
    if(s.at(i)!='1'){
      cout << s.at(i);
      return 0;
    }
    i++;
    if(i==k){
      cout << 1;
      return 0;
    }
  }
}
    


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int H,W;
    
    while(true){
        cin >> H >> W;
        if(H == 0 && W == 0)break;
        
    //for(int n = 0; n < W; n++){
    //    cout << "#" << endl;
    //}
    for(int i = 0; i < H; i++){
        for(int n = 0; n < W; n++){
            cout << "#";
        }
     cout << "\n";
    }
       cout << endl;
    }
    
    return 0;
}



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

int main(void){
    int N, M, ans=0;
    std::cin >> N >> M;
    std::vector<int> food(M, 0);

    for (int i=0; i<N; ++i){
        int K;
        std::cin >> K;
        for (int j=0; j<K; ++j){
            int a;
            std::cin >> a;
            ++food.at(a - 1);
        }
    }

    for (int i=0; i<M; ++i){
        if (food.at(i) == N) ++ans;
    }

    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 3572
N,M = map(int, input().split())
P = [list(map(int, input().split())) for m in range(M)]
C = (N+1)*[0]
D = {}

for p,y in sorted(P,key=lambda x: x[1]):
  C[p]+= 1
  D[y]="%06d%06d" % (p,C[p])

for p,y in P:
  print(D[y])

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

using namespace std;

int main(){
    int n, m;
    cin >> n >> m;
    
    if(n >= m){
        cout << 0;
        return 0;
    }
    
    vector<int> v(m);

    for(int i = 0; i < m; i++) {cin >> v[i];
        
    }
    
    sort(v.begin(), v.end() );
    
    vector<int> len(m-1);
    int sum = 0;
    for(int i = 0; i < m-1; i++){
        len[i] = v[i+1] - v[i];
        sum += len[i];
    }
    
    sort(len.begin(), len.end(), greater<int>() );
    
    for(int i = 0; i < n-1; i++){
        sum -= len[i];
    }
    
    cout << sum;
    
    return 0;
}

Measured memory_bytes: 1024
#include <cstdio>

int a[10016];

int main() {
	int n, b;
	long long s = 0, x = 0, y = 0;
	scanf("%d",&n);
	for (int i = 0; i < n; i++) {
		scanf("%d",a+i);
		s -= a[i];
	}
	for (int i = 0; i < n; i++) {
		scanf("%d",&b);
		s += b;
		if (a[i] < b) {
			x += b - a[i] >> 1;
			if ((a[i] ^ b) & 1)
				x++, y++;
		}
		else y += a[i] - b;
	}
	puts(x <= s && y <= s ? "Yes" : "No");
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 998244353;
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n,k;
	cin >> n >> k;
	vector<pair<int,int>> segments;;
	for(int i = 0; i < k;++i){
		int l,r;
		cin >> l >> r;
		segments.push_back({l,r});
	}
	vector<ll> dp(n+1,0);
	dp[1] = 1;
	vector<ll> pref(n+1,0);
	pref[1] = 1;
	for(int i = 2; i <= n;++i){
		for(int j = 0; j < k;++j){
			int l = segments[j].first;
			int r = segments[j].second;
			dp[i] = (dp[i] +  (pref[max(0,i-l)] - pref[max(0,i-r-1)] + MOD)%MOD)%MOD;
		}
		pref[i] = (pref[i-1] + dp[i])%MOD;
	}
	cout << dp[n] << "\n";
}


Measured memory_bytes: 6352
#include<stdio.h>
int main(void){
  int i,j,k,l;
  int n;

  while(1){
    int a[11][11]={0};
    int b[11][11]={0};
    scanf("%d",&n);
    if(n==0)
      break;
    for(i=0;i<n;i++)
      for(j=0;j<n;j++)
	scanf("%d",&a[i][j]);

    for(i=0;i<n;i++)
      for(j=0;j<n;j++)
	a[i][n]+=a[i][j];
    for(j=0;j<n;j++)
      for(i=0;i<n;i++)
	a[n][j]+=a[i][j];
    for(i=0;i<n;i++)
      a[n][n]+=a[i][n];

    for(i=0;i<n+1;i++){
      for(j=0;j<n+1;j++)
	printf("%5d",a[i][j]);
      printf("\n");
    }
  }
  return 0;
}

Measured memory_bytes: 616
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cout << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cout<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 200010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 29;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
///////////////////////////////////////////////////////////////////////////////////////////////////

int N, M;
int A[MAX_N];
int cnt[20];

int dp[(1 << 16)];
int ok[(1 << 16)];
vector<int> vec;

void solve() {
	cin >> N;
	rep(i, 0, N - 1) {
		int a, b, c;
		cin >> a >> b >> c;
		A[a] ^= c;
		A[b] ^= c;
	}
	rep(i, 0, N) cnt[A[i]]++;
	// debug(vi(A, A + N));
	// debug(vi(cnt, cnt + 16));

	int ans = 0;
	rep(i, 1, 16) {
		ans += cnt[i] / 2;
		if(cnt[i] % 2) vec.pb(i);
	}

	M = sz(vec);

	rep(bit, 1, (1 << M)) {
		int tmp = 0, res = 0;
		rep(i, 0, M) {
			if(!(bit & (1 << i))) continue;
			tmp ^= vec[i];
			res++;
		}
		if(tmp == 0) ok[bit] = res - 1;
		else ok[bit] = M;
	}
	fill(dp, dp + (1 << M), M);
	dp[0] = 0;
	rep(bit, 0, (1 << M)) {
		vector<int> vt;
		rep(i, 0, M) {
			if(!(bit & (1 << i))) vt.pb(i);
		}
		rep(bit2, 1, (1 << sz(vt))) {
			int to = 0;
			rep(i, 0, sz(vt)) {
				if(bit2 & (1 << i)) to |= (1 << vt[i]);
			}
			MIN(dp[bit | to], dp[bit] + ok[to]);
		}
	}
	cout << ans + dp[(1 << M) - 1] << "\n";
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
	srand((unsigned int)time(NULL));
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}



Measured memory_bytes: 896
import sys
from sys import exit
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right #func(リスト,値)
from heapq import heapify, heappop, heappush
from itertools import product, permutations, combinations, combinations_with_replacement
from math import *

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def lgcd(l):
    return reduce(gcd,l)
def llcm(l):
    return reduce(lcm,l)
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)
def ston(c, c0='a'):
    return ord(c)-ord(c0)
def ntos(x, c0='a'):
    return chr(x+ord(c0))
class counter(dict):
    def __init__(self, *args):
        super().__init__(args)
    def add(self,x):
        self.setdefault(x,0)
        self[x] += 1

N,A = ilint()
ans = INF
tmp = 0
S = sum(A)
for i in range(N-1):
    tmp += A[i]
    ans = min(ans,abs(S-2*tmp))
print(ans)

Measured memory_bytes: 102892
from math import factorial,sqrt,ceil,gcd,pi
# from itertools import permutations as permus
# from collections import deque,Counter
# import re
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix

# slist = "abcdefghijklmnopqrstuvwxyz"
R = int(input())

ans = 2*R*pi

print(ans)
# print(*ans)   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する
# print("{:.10f}".format(ans))
# print("{:0=10d}".format(ans))


Measured memory_bytes: 9148
import itertools

x = int(input())

y = itertools.combinations(range(-1000,1000), 2)
for n in y:
    if (n[0]**5 - n[1]**5) == x:
        print(n[0], n[1])
        break
    elif (n[1]**5 - n[0]**5) == x:
        print(n[1], n[0])
        break

Measured memory_bytes: 67828
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<vector>
#include<list>
#include<functional>
#include<algorithm>
#include<string>
#include<cmath>
#include<complex>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;



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

	ll a, b, x;
	cin >> a >> b >> x;
	if (a%x) a = (a / x + 1)*x;
	b = b / x * x;
	cout << (b - a) / x + 1 << "\n";

	return 0;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	b := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&b[i])
	}

	ans := make([]int, 0)
	for i := n; i > 0; i-- {
		ok := false
		for j := i; j > 0; j-- {
			if j <= len(b) && b[j-1] == j {
				ok = true
				ans = append(ans, b[j-1])
				b = append(b[:j-1], b[j:]...)
				break
			}
		}
		if !ok {
			fmt.Println(-1)
			return
		}
	}

	for i := 0; i < len(ans); i++ {
		fmt.Println(ans[len(ans)-i-1])
	}
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}


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

typedef unsigned long long int ull;
typedef long long int ll;
typedef vector<ll> vi;

#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define nl cout<<'\n'
#define pb push_back
#define all(s) s.begin(),s.end()
#define bs binary_search

#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) (a)*(b)/(__gcd((a),(b)))

const int Mod=1e9+7;
#define sum(a,b) (((a)%Mod)+((b)%Mod))%Mod
#define sub(a,b) (((a)%Mod)-((b)%Mod))%Mod
#define mul(a,b) (((a)%Mod)*((b)%Mod))%Mod
#define digit(x) floor((log10(x))+1)


#define count1(x) __builtin_popcount(x)

#define dbg(x) cout << #x <<":"<<x<<endl;

bool isPowerOfTwo (int x)  
{  
    /* First x in the below expression is for the case when x is 0 */
    return x && (!(x&(x-1)));  
} 

ll pow(ll x, ll y, ll mod)
{
	int ans=1;
	while(y)
	{
		if(y&1)
			ans=(ans*x)%mod;
		y/=2;
		x=(x*x)%mod;
	}
	return ans;
}
#define PI 3.14159
int main()
{
	fast;
	ll r;
	cin >> r;
	printf("%f",2*PI*r);
}

Measured memory_bytes: 3772
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using static System.Math;
using System.Text;
using System.Threading;
using System.Globalization;
using System.Runtime.CompilerServices;
using Library;

namespace Program
{
    public static class SUMITRUST2019A
    {
        static public int numberOfRandomCases = 0;
        static public void MakeTestCase(List<string> _input, List<string> _output, ref Func<string[], bool> _outputChecker)
        {
        }
        static public void Solve()
        {
            var M1 = NN;
            var D1 = NN;
            var M2 = NN;
            var D2 = NN;
            if (M1 != M2) Console.WriteLine(1);
            else Console.WriteLine(0);
        }
        static class Console_
        {
            static Queue<string> param = new Queue<string>();
            public static string NextString() { if (param.Count == 0) foreach (var item in Console.ReadLine().Split(' ')) param.Enqueue(item); return param.Dequeue(); }
        }
        class Printer : StreamWriter
        {
            public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } }
            public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) { base.AutoFlush = false; }
            public Printer(Stream stream, Encoding encoding) : base(stream, encoding) { base.AutoFlush = false; }
        }
        static public void Main(string[] args) { if (args.Length == 0) { Console.SetOut(new Printer(Console.OpenStandardOutput())); } var t = new Thread(Solve, 134217728); t.Start(); t.Join(); Console.Out.Flush(); }
        static long NN => long.Parse(Console_.NextString());
        static double ND => double.Parse(Console_.NextString());
        static string NS => Console_.NextString();
        static long[] NNList(long N) => Repeat(0, N).Select(_ => NN).ToArray();
        static double[] NDList(long N) => Repeat(0, N).Select(_ => ND).ToArray();
        static string[] NSList(long N) => Repeat(0, N).Select(_ => NS).ToArray();
        static IEnumerable<T> OrderByRand<T>(this IEnumerable<T> x) => x.OrderBy(_ => xorshift);
        static long Count<T>(this IEnumerable<T> x, Func<T, bool> pred) => Enumerable.Count(x, pred);
        static IEnumerable<T> Repeat<T>(T v, long n) => Enumerable.Repeat<T>(v, (int)n);
        static IEnumerable<int> Range(long s, long c) => Enumerable.Range((int)s, (int)c);
        static uint xorshift { get { _xsi.MoveNext(); return _xsi.Current; } }
        static IEnumerator<uint> _xsi = _xsc();
        static IEnumerator<uint> _xsc() { uint x = 123456789, y = 362436069, z = 521288629, w = (uint)(DateTime.Now.Ticks & 0xffffffff); while (true) { var t = x ^ (x << 11); x = y; y = z; z = w; w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)); yield return w; } }
    }
}
namespace Library {
}


Measured memory_bytes: 14688
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
void READ() {
#define R READ();
#define INFI 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define MEMX(x,num) memset(x,num,sizeof(x))
#define prln(x) cout<<#x<<"="<<x<<endl
#define sz(x) int(x.size())
#define PB(x) push_back(x)
#define LINK(x,y) G[x].PB(y),G[y].PB(x)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
#ifndef ONLINE_JUDGE
    freopen ( "A.in", "r", stdin );
#endif
    std::ios::sync_with_stdio ( 0 );
    cin.tie ( 0 );
    cout << fixed << setprecision ( 8 );
}
//////////////////////////////////////////
const int N = 5 + 1e1;
double n,m,d;
int main() {
    cout << fixed << setprecision ( 8 );
    cin>>n>>m>>d;
    if(d==0)cout<<(m-1)/n;
    else cout<<2*(n-d)*(m-1)/n/n;
    return 0;
}


Measured memory_bytes: 256
def BubbleSort(C,N):
    for i in range(N):
        for j in range(i+1, N)[::-1]:
            if int(C[j][1]) < int(C[j - 1][1]):
                C[j],C[j-1] = C[j-1],C[j]

def SelectionSort(C,N):
    for i in range(N):
        minj = i
        for j in range(i,N):
            if int(C[j][1]) < int(C[minj][1]):
                minj = j
        C[i],C[minj] = C[minj],C[i]

N = int(input())
C = (input()).split()
ORG = C[:]
BubbleSort(C,N)
print (" ".join(C))
print ("Stable")
C2=ORG
SelectionSort(C2,N)
print(" ".join(C2))
if C == C2:
    print ("Stable")
else:
    print ("Not stable")

Measured memory_bytes: 7712
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define PRINT(v) for (auto x : (v)) cout <<x <<" " ; cout <<endl;
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using mat = vector<vector<ll>>;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
const int inf = 1001001001;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
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;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}
void hey(){ cout <<"hey" <<endl; }

template<class T> struct edge { int to; T cost;};


int main() {
  int N,W; cin >>N >>W;
  vector<int> w(N);
  vector<ll> v(N);
  rep(i, N) cin >>w[i] >>v[i];
  vector<vector<ll>> dp(2, vector<ll>(W+1, 0));
  for (int i=0; i<N; i++){
    for (int j=0; j<=W; j++){
      chmax(dp[1][j], dp[0][j]);
      if (j+w[i] <= W) chmax(dp[1][j+w[i]], dp[0][j] + v[i]);
    }
    swap(dp[0], dp[1]);
    dp[1].assign(W+1, 0);
  }
  ll res = 0;
  for (int j=0; j<=W; j++) chmax(res, dp[0][j]);
  cout <<res <<endl;
}


Measured memory_bytes: 2560
#include<iostream>
#include<iomanip>
#include<math.h>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<string>
#define INF 1000000000ll
#define MOD 1000000007ll
#define EPS 1e-8
#define REP(i, m) for(long long i=0; i<m; ++i)
#define FOR(i, n, m) for(long long i=n; i<m; ++i)
#define ALL(v) v.begin(), v.end()
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef long double ld;

vector<vector<char> > m;
vector<vector<bool> > used;
int w,h;
void dfs(P p) {
	used[p.first][p.second]=true;
	int dh[]={1,0,-1,0};
	int dw[]={0,1,0,-1};
	REP(i,4) {
		P np=P(p.first+dh[i],p.second+dw[i]);
		if(np.first>=0&&np.first<h&&np.second>=0&&np.second<w&&m[np.first][np.second]=='.'&&!used[np.first][np.second]) dfs(np);
	}
}
int main() {
	ios::sync_with_stdio(false);
	int h,w,n;
	cin>>h>>w>>n;
	vector<string> m(h);
	REP(i,h) cin>>m[i];
	P sp=P(-1,-1);
	REP(i,h) REP(j,w) {
		if(m[i][j]=='S') {
			sp.first=i;
			sp.second=j;
		}
	}
	int tgt=1;
	ll res=0;
	while(tgt<=n) {
		int dh[]={1,0,-1,0};
		int dw[]={0,1,0,-1};
		vector<vector<int> > d(h,vector<int>(w,INF));
		queue<P> q;
		q.push(sp);
		d[sp.first][sp.second]=0;
		while(!q.empty()) {
			P p=q.front();
			q.pop();
			if(m[p.first][p.second]==(char)('0'+tgt)) {
				sp.first=p.first;
				sp.second=p.second;
				res+=d[p.first][p.second];
				break;
			}
			REP(i,4) {
				ll nh=p.first+dh[i];
				ll nw=p.second+dw[i];
				if(nh>=0&&nh<h&&nw>=0&&nw<w&&m[nh][nw]!='X'&&d[nh][nw]==INF) {
					d[nh][nw]=d[p.first][p.second]+1;
					q.push(P(nh,nw));
				}
			}
		}
		++tgt;
	}
	cout<<res<<endl;
}

Measured memory_bytes: 7716
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(int i=0;i<int(n);i++)
#define V (1000)
#define LLM (9000000000000000000)
//n<=50000
struct edge{
	int to;
	long long cap;
	int rev;
};
vector<edge> g[V];
bool used[V];
int level[V];
vector<int>qv;

//辺追加(1回)
void add_edge(void){
	int x, y,s,t;
	long long z;
	scanf("%d %d %lld", &x, &y, &z);
	x--;
	y--;
s=g[y].size();
t=g[x].size()-1;
	g[x].push_back({ y, z, s });
	g[y].push_back({ x, 0, t });
}

void bfs(int stvec){
int k;
memset(level,-1,sizeof(level));
qv.clear();
level[stvec]=0;
qv.push_back(stvec);
f(ii,V){
if(ii>=qv.size())break;
else k=qv[ii];
	f(i, g[k].size()){
		edge &e = g[k][i];
		if (level[e.to]<0 && e.cap > 0){
level[e.to]=level[k]+1;
qv.push_back((e.to));
		}
	}
}
	return;
}

//増加路探索
long long dfs(int vec, int ep, long long val){
	if (vec == ep)return val;
	f(i, g[vec].size()){
		edge &e = g[vec][i];
		if (!used[e.to] && e.cap > 0&&level[vec]<level[e.to]){
			long long d = dfs((e.to), ep, min(val, e.cap));
			if (d > 0){
				e.cap -= d;
				g[e.to][e.rev].cap += d;
				return d;
			}
		}
	}
	used[vec] = true;
	return 0;
}

//最大流探索
long long max_flow(int s, int t){
	long long ret = 0;
	long long res;
	while (true){
bfs(s);
if(level[t]<0)break;
		memset(used, 0, sizeof(used));
		res = dfs(s, t, LLM);
while(res>0){
ret += res;
		res = dfs(s, t, LLM);	
}
}
	return ret;
}


int main(void){
	int n, m, s, t;
	int x, y;
	long long z, ans;
	scanf("%d %d", &n, &m);
	for (int i = 0; i < m; i++){
		scanf("%d %d %lld", &x, &y, &z);
/*		x--;
		y--;
*/
s=g[y].size();
t=g[x].size()-1;
		g[x].push_back({ y, z, s });
		g[y].push_back({ x, 0, t });
	}
/*	scanf("%d %d", &s, &t);
	s--;
	t--;
*/
s=0;
t=n-1;
	ans = max_flow(s, t);
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 2864
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-7;
const int inf=1e8;
int main(){
	ll n;
	cin>>n;
	vi co(n+1);
	loop(i,1,n+1){
		ll t=i;
		for(int j=2;j*j<=t;j++){
			while(t%j==0){
				t/=j;
				co[j]++;
			}
		}
		if(t-1)co[t]++;
	}
	ll out=1;
	rep(i,n+1)(out*=(co[i]+1))%=1000000007;
	cout<<out<<endl;
}
















Measured memory_bytes: 256
// https://atcoder.jp/contests/abc075/tasks/abc075_c
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

#define EPS (1e-9)
#define INF (1e9)
#define INFL (1e18)
#define MOD (1000000007)
#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()
#define LEN(x) (sizeof(x) / sizeof(*(x)))
// 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; }

struct UnionFind {
    vector<int> par; // 親の番号
    UnionFind(int size) : par(size, -1) {}
    // xとyの木を併合
    bool unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x != y) {
            if (par[y] < par[x])
                swap(x, y);
            par[x] += par[y];
            par[y] = x;
            return true;
        } else {
            return false;
        }
    }
    // 2つのデータx, yが属する木が同じならtrueを返す
    bool same(int x, int y) { return root(x) == root(y); }
    // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
    int root(int x) { return par[x] < 0 ? x : par[x] = root(par[x]); }
    // 頂点 v が属するグループと同じグループに属する頂点数を得る
    int size(int x) { return -par[root(x)]; }
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m, a, b, ans = 0;
    cin >> n >> m;
    vector<PII> v;
    REP(i, m) {
        cin >> a >> b;
        v.push_back(PII(--a, --b));
    }

    REP(i, m) {
        UnionFind tree(n);
        REP(j, m) {
            if (i != j) {
                tree.unite(v[j].first, v[j].second);
            }
        }
        if (!tree.same(v[i].first, v[i].second)) {
            ans++;
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
  int m,d,counter=0;
  int d1,d2;
  scanf("%d %d",&m,&d);
  if(d<20)
  {
    printf("0\n");
    return 0;
  }
  for(int i = 1;i<=m;i++)
  {
    for(int j = 20;j<=d;j++)
    {
      d1=j%10;
      if(d1<2)
        continue;
      d2=j/10;
      if(i==d1*d2)
        counter++;
    }
  }
  printf("%d\n",counter);
  return 0;
}

Measured memory_bytes: 128