akhauriyash/Code-Regression huggingface dataset:
//include
//------------------------------------------
#include <bits/stdc++.h>
using namespace std;
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const long long INF = 1000000007;
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
// chmax chmin
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main(void){
    string s; cin >> s;
    REP(i,s.size()){
        cout << s[i];
        i++;
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <typeinfo>
#include <cxxabi.h>
#ifdef LOCAL
#include "dbgtoki.hpp"
#define DUMP(i) dump((string)TOSTRING(i), demangle(typeid(i).name()), __LINE__ , i) 
#else
#define DUMP(i) 
#endif
 
#define TOSTRING(x) #x
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(s) (s).begin(), (s).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()) , v.end());
 
using namespace std;
typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
const int EPS = 1e-9;
const int MOD = 1e9+7;
 
int main (){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  int ans = 0;
  REP(i,n){
    int a;
    cin >> a;
    while(a%2 == 0 && a != 0){
      ans++;
      a /= 2;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#ifdef _MSC_VER
#include "stdc++.h"
#endif
#ifdef __GNUC__
#include<bits/stdc++.h>
#endif
using namespace std;

using ll = long long;

//vector
using vi = vector<int>;
using vii = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;

//constant
const double EPS = 1e-10;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, s, e) for (ll i = s; i < e; i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(), (x).rend()

//debug
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define DEBUG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl;

// vector
//template<typename T> vector<vector<T>> vv(ll H, ll W, T v) { return vector<vector<T>> vec(H, vector<T>(W, v)); }

// view vector
template<typename T> void view(T e) { cout << e << endl; }
template<typename T> void view(const vector<T>& v) { for (const auto& e : v) { cout << e << " "; } cout << endl; }
template<typename T> void view(const vector<vector<T> >& vv) { for (const auto& v : vv) { view(v); } }

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




// ***************************************


int main() {

    ll N, M, K;
    cin >> N >> M >> K;

    vll A(N), B(M);
    cin >> A[0];
    FOR(i, 1, N) {
        cin >> A[i];
        A[i] += A[i - 1];
    }
    cin >> B[0];
    FOR(j, 1, M) {
        cin >> B[j];
        B[j] += B[j - 1];
    }

    ll n = upper_bound(ALL(A), K) - A.begin();
    ll m = upper_bound(ALL(B), K) - B.begin();

    if (n == 0) {
        cout << m << endl;
        return 0;
    }
    if (m == 0) {
        cout << n << endl;
        return 0;
    }

    if (A[n - 1] + B[m - 1] <= K) {
        cout << n + m << endl;
        return 0;
    }

    ll cnt = max(n, m);
    for (ll i = n - 1; i >= 0; i--) {
        ll x = upper_bound(ALL(B), K - A[i]) - B.begin();
        chmax(cnt, i + 1 + x);
        if (x == m) break;
    }

    cout << cnt << endl;


    return 0;
}


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

#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long
#define INF 999999999

unsigned GetDigit(unsigned num){
    unsigned digit = 0;
    while(num != 0){
        num /= 10;
        digit++;
    }
    return digit;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n; cin >> n;
	vector<string> s(n);
	REP(i, n){ cin >> s[i]; }
	vector<int> cnt(26, INF);
	REP(i, n){
		REP(j, 26){
			cnt[j] = min(cnt[j], (int) count(s[i].begin(), s[i].end(), 'a'+j));
		}
	}
	REP(i, 26){
		REP(j, cnt[i]){
			cout << char('a'+i);
		}
	}
	cout << endl;
}


Measured memory_bytes: 256
def partition(A, p, r):
	x = A[r]
	i = p - 1
	for j in xrange(p, r):
		if A[j] <= x:
			i += 1
			[A[i], A[j]] = [A[j], A[i]]
	[A[i+1], A[r]] = [A[r], A[i+1]]
	return A, i+1

n = int(raw_input())
A = map(int, raw_input().split())

newA, q = partition(A, 0, len(A)-1)

for i in range(n-1):
	if i == q:
		print("[{:}]".format(newA[i])),
	else:
		print(newA[i]),
print newA[-1]

Measured memory_bytes: 14856
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a[3], m = 1000;
  cin >> a[0] >> a[1] >> a[2];
  sort(a,a+3);
  cout << abs(a[0]-a[1])+abs(a[1]-a[2]);
  return 0;
}

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

int main() {
  char c;
  cin >> c;

  if(c == 'a' || c == 'e' || c == 'i' || c == 'u' || c == 'o'){
    cout << "vowel" << endl;
  }
  else{
    cout << "consonant" << endl;
  }

  
  // ここにプログラムを追記
}


Measured memory_bytes: 256
IDENTIFICATION DIVISION.
       PROGRAM-ID. ABC042-B.
       DATA DIVISION.
       FILE SECTION.
       WORKING-STORAGE SECTION.
       77 INSTR PIC X(100).
       77 N PIC 9(3).
       77 L PIC 9(3).
       77 I PIC 9(3).
       01 STR.
        03 STRARR OCCURS 1 TO 100 TIMES DEPENDING ON N.
         05 STRDATA PIC X(100).
       77 ANS PIC X(10000).

       PROCEDURE DIVISION.
       MAIN-PROCEDURE.
            ACCEPT INSTR FROM SYSIN.
            UNSTRING INSTR DELIMITED " "
             INTO N L.
            PERFORM VARYING I FROM 1 BY 1
             UNTIL N < I
               ACCEPT INSTR FROM SYSIN
               MOVE INSTR TO STRARR(I)
            END-PERFORM.
            SORT STRARR ASCENDING STRDATA.
            PERFORM VARYING I FROM 1 BY 1
             UNTIL N < I
               STRING ANS STRARR(I) DELIMITED BY SPACE
                INTO ANS
            END-PERFORM.
            DISPLAY ANS.
            STOP RUN.
       END PROGRAM ABC042-B.


Measured memory_bytes: 384
n = gets.to_i
a = gets.split(" ").map(&:to_i)
max = a[0]
c = 0
1.upto(a.size-1) do |i|
  next if a[i] == max
  if a[i] > max
    max = a[i]
  else
    c += max - a[i]
  end
end
puts c

Measured memory_bytes: 28000
#include<stdio.h>
#include<math.h>
#include<cmath>
#include<iostream>
using namespace std;

int main( )
{
    long double a,b,c;
    long double eps=1.0E-14;
    cin>>a>>b>>c;
    if(sqrt(a)+sqrt(b)+eps<sqrt(c))
        printf("Yes");
    else
        printf("No");
    return 0;
}


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

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner();
		int a = sc.nextInt();
		int p = sc.nextInt();
		int num = a * 3 + p;
		System.out.println(num / 2);

	}
}

class Scanner {
	private static final int SPACE = (int)' ';
	private static final int LINE_END_0 = 13;
	private static final int LINE_END_1 = 10;
	private static final int BEFORE = -1;
	private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	
	public String next(){
		StringBuilder sb = new StringBuilder();
		
		int length = BEFORE;
		readLoop: while(true) {
			try {
				int value = br.read();
				switch(value) {
				case LINE_END_1:
					if(length == BEFORE)
						break;
					
					if((int)sb.charAt(length) == LINE_END_0)
						sb.deleteCharAt(length);
				case SPACE:
					break readLoop;
				}
				sb.append((char)value);
				length++;

			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return sb.toString();
	}
	
	public String[] nextArray(int length) {
		String[] array = new String[length];
		for(int i = 0; i < length; i++)
			array[i] = next();
		return array;
	}
	
	public double nextDouble() {
		return Double.parseDouble(next());
	}
	
	public double[] nextDoubleArray(int length) {
		double[] array = new double[length];
		for(int i = 0; i < length; i++)
			array[i] = nextDouble();
		return array;
	}
	
	public int nextInt() {
		return Integer.parseInt(next());
	}
	
	public int[] nextIntArray(int length) {
		int[] array = new int[length];
		for(int i = 0; i < length; i++)
			array[i] = nextInt();
		return array;
	}
	
	public long nextLong() {
		return Long.parseLong(next());
	}
	
	public long[] nextLongArray(int length) {
		long[] array = new long[length];
		for(int i = 0; i < length; i++)
			array[i] = nextLong();
		return array;
	}
	
	public boolean ready() {
		try {
			return br.ready();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return false;
	}
}


Measured memory_bytes: 24404
#include <stdio.h>

int main() {
    int n, m, l;
    long long a[105][105] = {0}, b[105][105] = {0}, c[105][105] = {0};
    scanf("%d %d %d", &n, &m, &l);
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++)
            scanf("%lld", &a[i][j]);
    }
    for (int i = 0; i < m; i++) {
        for (int j = 0; j < l; j++)
            scanf("%lld", &b[i][j]);
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < l; j++) {
            for (int k = 0; k < m; k++)
                c[i][j] += a[i][k] * b[k][j];
            printf("%lld", c[i][j]);
            if (j < l - 1) printf(" ");
            else printf("\n");
        }
    }
}


Measured memory_bytes: 2112
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define fi first
#define se second
#define PI (acos(-1))

template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i];if(i<len-1) s<<" ";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i]<<endl;
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){
	s<<"{ ";
	for(auto itr=v.begin();itr!=v.end();++itr) {
		if (itr!=v.begin()) {s<< ", ";}
		s<<(*itr);
	}
	s<<" }";
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){
	s<<"{"<<endl;
	for(auto itr=m.begin();itr!=m.end();++itr){
		s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;
	}
	s<<"}"<<endl;
	return s;
}

const ll mod=1e9+7;
const ll inf=1e15;
const int INF=1e9;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,m;
	cin>>n>>m;
	vector<vector<int>> s(m);
	rep(i,m){
		int k;
		cin>>k;
		rep(j,k){
			int a;
			cin>>a;
			a--;
			s[i].push_back(a);
		}
	}
	vector<int> p(m);
	rep(i,m) cin>>p[i];
	int ans=0;
	rep(S,1<<n){
		bool flag=true;
		rep(i,m){
			int cnt=0;
			rep(j,s[i].size()){
				if(1<<s[i][j] & S){
					cnt++;
				}
			}
			if(cnt%2!=p[i]){
				flag=false;
				break;
			}
		}
		if(flag) ans++;
	}
	cout<<ans<<endl;
}

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

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define abs(a) max((a),-(a))
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repe(i,n) rep(i,(n)+1)
#define per(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define pere(i,n) rep(i,(n)+1)
#define all(x) (x).begin(),(x).end()
#define SP <<" "<<
#define RET return 0
#define MOD 1000000007
#define INF 1000000000000000000

typedef long long LL;
typedef long double LD;

int main(){
  string s;
  cin >> s;
  if(s[0]=='a'){
    cout << "square1001" << endl;
  }else{
    cout << "e869120" << endl;
  }
  return 0;
}



Measured memory_bytes: 3148
a = int(input())
b = int(input())
c = int(input())
x = int(input())
s = 0
num = 0
for i in range(a+1):
  for j in range(b+1):
    for k in range(c+1):
      s = i*500+j*100+k*50
      if s == x:
        num += 1
      if s > x:
        break
    if s>x:
      continue
  if s>x:
    continue
print(num)

Measured memory_bytes: 3188
#include<iostream>
using namespace std;
int main() {
    int n;
    cin >> n;
    int b;
    cin >> b;
    int s = b;
    long long sum = b;
    int t;
    int i;
    for (i = 1; i < n; i++) {
        cin >> t;
        if (t>=b) {
            b = t;
        } else if (t<=s) {
            s = t;
        }
        sum += t;
    }
    cout << s << " " << b << " " << sum << endl;
    return 0;
} 


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

int p[4],q[4];
int main(){
    while(cin>>p[0]){
        for(int i=1;i<4;i++)cin>>p[i];
        for(int i=0;i<4;i++)cin>>q[i];

        int h=0,b=0;
        for(int i=0;i<4;i++){
            for(int j=0;j<4;j++){
                if(p[i]==q[j]){
                    if(i==j)h++;
                    else b++;
                }
            }
        }
        cout<<h<<" "<<b<<endl;
    }
    return 0;
}

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

int main(){
    int n;
    string s;
    cin>>n>>s;
    vector<bool>ok(n);
    string t=s;
    rep(f,4){
        f%2==1?t[0]='S':t[0]='W';
        f>=2?t[1]='S':t[1]='W';
        for(int i=1; i<n-1; ++i){
            if(s[i]=='o'){
                if(t[i]=='W'){
                    if(t[i-1]=='S')t[i+1]='W';
                    else t[i+1]='S';
                }
                else{
                    if(t[i-1]=='S')t[i+1]='S';
                    else t[i+1]='W';
                }
            }
            else{
                if(t[i]=='S'){
                    if(t[i-1]=='S')t[i+1]='W';
                    else t[i+1]='S';
                }
                else{
                    if(t[i-1]=='S')t[i+1]='S';
                    else t[i+1]='W';
                }
            }
        }
        bool ng=false;
        for(int i=1; i<=n; ++i){
            if(s[(i%n)]=='o'){
                if(t[(i%n)]=='S'){
                    if(t[(i-1)%n]!=t[(i+1)%n])ng=true;
                }
                else{
                    if(t[(i-1)%n]==t[(i+1)%n])ng=true;
                }
            }
            else{
                if(t[(i%n)]=='W'){
                    if(t[(i-1)%n]!=t[(i+1)%n])ng=true;
                }
                else{
                    if(t[(i-1)%n]==t[(i+1)%n])ng=true;
                }
            }
        }
        if(!ng){cout<<t<<endl; return 0;}
    }
    cout<<-1<<endl;
}

Measured memory_bytes: 3792
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repR(i, n) for(int i = n; i >= 0; ++i)
#define FDS(i, n) for(int i = 0; i < n; ++i)
#define FDSR(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 VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
#define itn int
#define ednl endl
using namespace std;
typedef long long ll;
int main(){
	int a,b;
	cin>>a>>b;
	cout<<max({(a+b),(a-b),a*b})<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static String Y = "Yes";
	public static String N = "No";
	public static String I = "IMPOSSIBLE";
	public static String B = "Bad";
	public static String G = "Good";
	public static long MOD = (long) (Math.pow(10, 9) + 7);
	public static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {

		String s = n();
		String t = n();
		if (s.equals(t.substring(0, s.length()))) {
			out(Y);
		} else {
			out(N);
		}

	}

	public static int count(String search, String text) {
		int nsearch = search.length();
		int ntext = text.length();
		int count = 0;

		for (int i = 0; i <= ntext - nsearch + 1; i++) {
			for (int j = i + nsearch - 1; j < ntext; j++) {
				if (search.equals(text.substring(i, j + 1))) {
					count++;
				}
			}
		}

		return count;
	}

	/*
	 * 以下メソッド集
	 */
	static int ni() {
		return sc.nextInt();
	}

	static long nl() {
		return sc.nextLong();
	}

	static String n() {
		return sc.next();
	}

	static char[] nc() {
		return sc.next().toCharArray();
	}

	static int kaijo(int n) {
		if (n == 0 || n == 1) {
			return 1;
		} else {
			return n * kaijo(n - 1);
		}
	}

	static int fib(int n) {
		return (n == 1 || n == 0) ? n : fib(n - 2) + fib(n - 1);
	}

	static long lcm(long m, long n) {

		return m * n / gcd(m, n);
	}

	static int lcm(int m, int n) {

		return m * n / gcd(m, n);
	}

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

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

	static void out(String info) {
		System.out.println(info);
	}

	static void out(int info) {
		System.out.println(info);
	}

	static void out(double info) {
		System.out.println(info);
	}

	static void out(long info) {
		System.out.println(info);
	}

	static void out(char info) {
		System.out.println(info);
	}

	static void outn(String info) {
		System.out.print(info);
	}

	static void outn(int info) {
		System.out.print(info);
	}

	static void outn(double info) {
		System.out.print(info);
	}

	static void outn(long info) {
		System.out.print(info);
	}

	static void outn(char info) {
		System.out.print(info);
	}

	static int max(int a, int b) {
		return Math.max(a, b);
	}

	static long max(long a, long b) {
		return Math.max(a, b);
	}

	static int min(int a, int b) {
		return Math.min(a, b);
	}

	static long min(long a, long b) {
		return Math.min(a, b);
	}
}


Measured memory_bytes: 35712
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
typedef int64_t int64;
typedef uint32_t uint;
typedef uint64_t uint64;
using namespace std;

//---

template <typename T>
inline void print(const T& rhs){ std::cout<<" = "<<rhs<<std::endl; }
template <typename T>
inline void print(const std::vector<T>& rhs){
    std::cout<<" = [ ";
    for(uint i=0; i<rhs.size(); ++i){ std::cout<<rhs[i]<<' '; }
    std::cout<<"]"<<std::endl;
}
template <typename T>
inline void print(const std::vector<std::vector<T>>& rhs){
    std::cout<<" = "<<std::endl;
    std::cout<<"[[ ";
    for(uint p=0; p<rhs.size(); ++p){
        if(p!=0){ std::cout<<" [ "; }
        for(uint q=0; q<rhs[p].size(); ++q){
            std::cout<<rhs[p][q]<<' ';
        }
        if(p!=rhs.size()-1){ std::cout<<"]"<<std::endl; }
    }
    std::cout<<"]]"<<std::endl;
}
template <typename TL, typename TR>
inline void print(const std::vector<std::pair<TR,TL>>& rhs){
    std::cout<<" = [";
    uint i=0;
    for(; i<rhs.size()-1; ++i){ std::cout<<"[f: "<<rhs[i].first<<", s: "<<rhs[i].second<<"], "; }
    std::cout<<"[f: "<<rhs[i].first<<", s: "<<rhs[i].second<<"]]" << endl;
}
#define printn(var) {printf("%s", #var);print(var);}
#define printn_all(var) {printf("%s(%d): ", __func__, __LINE__);printf("%s", #var);print(var);}

//---

template<typename T>
T nearest_down(const vector<T>& v, const T& value){
    uint idx = upper_bound(v.begin(), v.end(), value) - v.begin();
    return v[ (idx!=0 ? idx-1:0) ];
}
template<typename T>
T nearest_up  (const vector<T>& v, const T& value){
    uint idx = lower_bound(v.begin(), v.end(), value) - v.begin();
    return v[ (idx!=v.size() ? idx:v.size()-1) ];
}
template<typename T>
T nearest(const vector<T>& v, const T& value){
    T val1 = nearest_down(v, value);
    T val2 = nearest_up  (v, value);
    return (abs(val1-value)<abs(val2-value) ? val1 : val2);
}
template<typename T>
uint argnearest_down(const vector<T>& v, const T& value){
    uint idx = upper_bound(v.begin(), v.end(), value) - v.begin();
    return (idx!=0 ? idx-1:0);
}
template<typename T>
uint argnearest_up(const vector<T>& v, const T& value){
    uint idx = lower_bound(v.begin(), v.end(), value) - v.begin();
    return (idx!=v.size() ? idx:v.size()-1);
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int N; cin >> N;
    vector<int> vA(N); for(int i=0; i<N; ++i){ cin >> vA[i]; }
    sort(vA.begin(), vA.end());

    int maxVal = vA[vA.size()-1];
    int nHalf = nearest(vA, maxVal/2);
    if(maxVal==nHalf){ nHalf=vA[0]; }
    
    cout << maxVal << ' ' << nHalf << endl;
    
    return 0;
}

Measured memory_bytes: 640
fn read_stdin() -> String {
    use std::io::Read;
    let mut input = String::new();
    std::io::stdin().read_to_string(&mut input).unwrap();
    input
}

fn scan<'a, I: Iterator<Item = &'a str>, T: std::str::FromStr>(tokens: &mut I) -> T {
    tokens.next().unwrap().parse().ok().unwrap()
}

fn rep<T, F: FnMut() -> T>(n: usize, mut f: F) -> Vec<T> {
    (0..n).map(|_| f()).collect()
}

fn main() {
    use std::collections::HashMap;
    let input = read_stdin();
    let tokens = &mut input.split_whitespace();
    let n: usize = scan(tokens);
    let k: usize = scan(tokens);
    let a: Vec<usize> = rep(n, || scan(tokens));
    let mut c = vec![0; n + 1];
    for i in 0..n {
        c[i + 1] = (c[i] + a[i] - 1) % k;
    }
    let mut ans = 0;
    let mut count: HashMap<usize, usize> = HashMap::new();
    for i in 0..n + 1 {
        if i >= k {
            *count.get_mut(&c[i - k]).unwrap() -= 1;
        }
        let x = count.entry(c[i]).or_insert(0);
        ans += *x;
        *x += 1;
    }
    println!("{}", ans);
}


Measured memory_bytes: 23316
n = int(input())
x = list(map(int, input().split()))

x_sort = sorted(x)
l_mid = x_sort[int(n/2)-1]
r_mid = x_sort[int(n/2)]

for i in range(n):
    if x[i] <= l_mid:
        print(r_mid)
    else:
        print(l_mid)


Measured memory_bytes: 25228
#include<bits/stdc++.h>
using namespace std;
 
void fast()
{
    std::ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}


int main()
{
    fast();
    long long int n , i , ans = 0 , cnt = 0, j  ;
    cin>>n;
    string s ;
    vector<string> v ;
    for(i=0;i<n;i++)
    {
    	cin>>s;
    	sort(s.begin(), s.end()) ;
    	v.push_back(s) ;
	}
	sort(v.begin(),v.end()) ;
	for(i=0;i<n;i++)
	{
		cnt = 0 ; 
		for( j = i+1; j<n;j++)
		{
			if(v[i]==v[j])
				cnt++;
			else
				break;
		}
		ans+= cnt*(cnt+1)/2 ;
		i = j-1 ; 
	}
	cout<<ans;
	return 0 ;
}

Measured memory_bytes: 5748
/*できずC: Half and Half
まず、AB ピザを奇数枚買って 1 枚余らせるのは無意味なので、AB ピザは 2 枚 1 組で考えます。つまり、
2C 円で A ピザ 1 枚と B ピザ 1 枚を買えると考えることにし、この 2 枚の組み合わせをこれ以降 AB セッ
トと呼ぶことにします。
この問題の重要な制約は、X, Y ≤ 105 です。これは、A ピザ、B ピザ、AB セットのどれについても、買
う個数は 10 万個以下でよいことを意味します。したがって、この三種類のうちどれか一種類を選んで、それ
を買う個数を 0 から 10 万まですべて試す、という方針が考えられます。*4
さて、三つのうちどれについて購入個数を全列挙するべきでしょうか？結論を述べると、AB セットです。
AB セットを i 個 (0 ≤ i ≤ 105
) 購入した場合、i ≥ X であれば A ピザを買い増す必要はなく、i < X であれ
ば A ピザを X −i 枚買い増す必要があります。これらをまとめて、買い増すべき A ピザの数は max(0, X −i)
枚であるということもできます。同様に、B ピザを max(0, Y − i) 枚買い増す必要があります。以上から、
AB セットを i 枚購入した場合の所要金額は i × 2C + max(0, X − i) × A + max(0, Y − i) × B 円であり、こ
の値を 0 以上 10 万以下のすべての整数 i について計算して最小値を取ることで答えが求まります。
なお、定数時間で答えを求めることもできます。練習問題として解説は省きます。*/
#include <bits/stdc++.h>

using namespace std;
#define cinf(n,x) for(int i=0;i<(n);i++) cin >> x[i];
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)

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

    int min = INT_MAX;
    REP(i, 2 * max(x,y)){
        int h = 2 * c * i + a * max(0, x-i) + b * max(0, y-i);
        if(h < min) min = h;
    }

    cout << min << endl;



    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <vector>

using namespace std;

int main(){
  int N, tmp;
  cin >> N;
  map<int, int> L_count;
  for (int i=0; i<N; i++){
    cin >> tmp;
    L_count[tmp]++;
  }
  vector<int> L_uniq;
  for (auto e : L_count){
    L_uniq.push_back(e.first);
  }
  if (L_uniq.size() < 3){
    cout << 0 << "\n";
    return 0;
  }
  bool b1, b2, b3;
  int ans = 0;
  
  for (int i=0; i<L_uniq.size()-2; i++){
    for (int j=i+1; j<L_uniq.size()-1; j++){
      for (int k=j+1; k<L_uniq.size(); k++){
        b1 = (L_uniq[i] + L_uniq[j] > L_uniq[k]);
        b2 = (L_uniq[j] + L_uniq[k] > L_uniq[i]);
        b3 = (L_uniq[k] + L_uniq[i] > L_uniq[j]);
        if (b1 & b2 & b3) {
          ans += (L_count[L_uniq[i]] * L_count[L_uniq[j]] * L_count[L_uniq[k]]);
        }
      }
    }
  }
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 3632
#define LOCAL
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rrep(i, n) for(int i=(n-1); i>=0; --i)
#define rep2(i, s, n) for(int i=s; i<(n); ++i)
#define ALL(v) (v).begin(), (v).end()
#define memr(dp, val) memset(dp, val, sizeof(dp))
using namespace std;
typedef long long ll;
static const int INTINF = (INT_MAX >> 1); // 10^9 + 10^7
static const ll LLINF = (LLONG_MAX >> 1);
static const int MAX = 1e5+1;
static const ll MOD = 1e9+7;
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; }
template<class T> inline bool int_ceil(T a, T b) { T res = a / b; if(a % b != 0) res++; return res; }
template<typename T>
using min_priority_queue = priority_queue<T, vector<T>, greater<T> >;
string to_string(string s) { return '"' + s + '"'; }
string to_string(bool b) { return b ? "true" : "false"; }
template <size_t N> string to_string(bitset<N> bs) {
  string res;
  for (size_t i = 0; i < N; ++i) res += '0' + bs[i];
  return res;
}
string to_string(vector<bool> v) {
  string res = "{";
  for (bool e : v) res += to_string(e) + ", ";
  return res += "}";
}
template <class T, class U> string to_string(pair<T, U> p);
template <class C> string to_string(C c) {
  string res = "{";
  for (auto e : c) res += to_string(e) + ", ";
  return res += "}";
}
template <class T, class U> string to_string(pair<T, U> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
void debug() { cerr << '\n'; }
template <class Head, class... Tail> void debug(Head head, Tail... tail) {
  cerr << '\t' << to_string(head), debug(tail...);
}
#ifdef LOCAL
#define print(...) cerr << "[" << #__VA_ARGS__ << "]:", debug(__VA_ARGS__)
#else
#define print(...)
#endif

int main(int argc, const char * argv[]) {
	std::cout << std::fixed << std::setprecision(15);

	map<string, int> mp;
	int n; cin >> n;
	rep(i, n){
		string s; cin >> s;
		mp[s] = 1;
	}

	cout << mp.size() << endl;

	return 0;
}


Measured memory_bytes: 19196
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<ll,ll> P;

vector<ll> a;
ll m;

ll calc(ll x) {
  vector<P> v;
  rep(i,a.size()) {
    ll y=a[i]%x;
    v.pb(P(y,x-y));
  }
  sort(all(v));
  ll c=0,d=0;
  rep(i,v.size()) d+=v[i].S;
  rep(i,v.size()) {
    d-=v[i].S;
    c+=v[i].F;
    if(c<=m&&d<=m) return 1;
  }
  return 0;
}

void Main() {
  ll n;
  cin >> n >> m;
  ll sum=0;
  rep(i,n) {
    ll x;
    R x;
    a.pb(x);
    sum+=x;
  }
  sort(all(a));
  vector<ll> v;
  for(ll i=1; i*i<=sum; i++) {
    if(sum%i==0) {
      v.pb(i);
      if(i*i!=sum) v.pb(sum/i);
    }
  }
  sort(all(v));
  ll ans=0;
  rep(i,v.size()) {
    if(calc(v[i])) ans=v[i];
  }
  pr(ans);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}

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

const double pi = 3.141592653589793;

int main()
{
	double hourlong,minutelong,hour,minute;
	scanf("%lf %lf %lf %lf",&hourlong,&minutelong,&hour,&minute);
	double hourangle,minuteangle;
	hourangle = hour*30 + minute/2;
	minuteangle = minute * 6;
	double delta;
	delta = abs(hourangle - minuteangle);
	if(delta > 180)
	{
		delta = 360 - delta;
	}
	//printf("%.10lf",delta);
	double result;
	result = sqrt(hourlong*hourlong + minutelong* minutelong - 2 * hourlong * minutelong * cos(pi*2*(delta/360)));
	printf("%.11f",result);
	return 0;
}

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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

vector<vector<int>> g;

vector<int> counter;

void dfs(int cu, int pa = -1) {
    for (auto v : g[cu]) {
        if (v == pa) {
            continue;
        }

        counter[v] += counter[cu];

        dfs(v, cu);
    }
}

int main() {

    int n, q; cin >> n >> q;

    g.resize(n);
    for (int i = 0; i < n-1; ++i) {
        int a, b; cin >> a >> b;
        --a; --b;

        g[a].push_back(b);
        g[b].push_back(a);
    }

    counter.resize(n);

    for (int i = 0; i < q; ++i) {
        int p, x; cin >> p >> x;
        --p;

        counter[p] += x;
    }

    dfs(0);

    for (int i = 0; i < n; ++i) {
        cout << counter[i] << ' ';
    }

    cout << endl;
}

Measured memory_bytes: 23552
using System;
using System.Linq;

namespace abc138_b{
  class program{
    public static void Main(){
      var n=int.Parse(Console.ReadLine());
      var list=Console.ReadLine().Split().Select(x => double.Parse(x)).ToArray();
      int i;
      double ans=0.0;
      Array.Sort(list);
      for(i=0;i<n;i++){
        ans+=1/list[i];
      }
      Console.WriteLine(1/ans);
    }
  }
}

Measured memory_bytes: 13524
#include <stdio.h>

int main(int argc,char *args[]){
    int i,j,h,w;

    while(1){
        scanf("%d %d",&h,&w);
        if(h==0 && w==0) break;
        for(i=0;i<h;i++){
            for(j=0;j<w;j++){
                printf("#");
            }
            printf("\n");
        }
        printf("\n");
    }
    return 0;
}



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

#define f first 
#define s second 
#define pb push_back               
#define mp make_pair 

using namespace std;                    

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

const int N = (int)2e5 + 123, mod = (int)1e9 + 7, inf = (int)1e9;


int n, x;
int a[N];
bool get(int a, int b){
	a++;
	cerr << a << " " << b << endl;
	while(a + b > 2){
		if(b)
        	b--;
        else
        	a--;
	}
	return b == 0;
}
int main(){                      
    cin >> n >> x;
	int c1 = x - 1, c2 = n + n - 1 - x;
	bool ok = get(min(c1, c2), max(c1, c2) - n + 1);
	a[n] = 1;
	for(int i = 1; i < n; i++){ 
		if(c1)           
			c1--, a[n - i] = 0;
		else
			c2--, a[n - i] = 2;	
		
		if(c2)           
			c2--, a[n + i] = 2;
		else
			c1--, a[n + i] = 0;	
	}
	if(ok){
		cout << "Yes" << endl;
		for(int i = 1,j = 1, q = x + 1; i <= n + n - 1; i++){
			if(a[i] == 0)
				cout << j++ << endl; 
			if(a[i] == 1)
				cout << x << endl;
			if(a[i] == 2)
				cout << q++ << endl;
		}
	}
	else
		cout << "No" ;
	return 0;
}

Measured memory_bytes: 2304
N,K=map(int,input().split())
x=list(map(int,input().split()))
x.sort()
ans=[]
for i in range(0,N-K+1):
    start=x[i]
    goal=x[i+K-1]
    if goal<0:
        ans.append(abs(start))
    elif start<0:
        test=min(2*abs(start)+goal,2*goal+abs(start))
        ans.append(test)
    else:
        ans.append(goal)
print(min(ans))


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

int N;
void dfs(vector<int>& v, int prev) {
  
  int now = N;
  for(int i=0; i<v.size(); i++) {
    now -= v[i];
  }
  
  if(now == 0) {
    for(int i=0; i<v.size(); i++) {
      if(i) cout << " ";
      cout << v[i];
    }
    cout << endl;
    return;
  }
  
  for(int i=min(prev, now); i>=1; i--) {
    v.push_back(i);
    dfs(v, i);
    v.pop_back();
  }
}

int main() {
  
  while(cin >> N && N) {
    vector<int> v;
    dfs(v, N);
  }
  
  return 0;
}

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

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

const long long INF = 1LL << 60;

bool dp[100100];

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

    vector<int>kazu(10,0);
    kazu[A] +=1;
    kazu[B] +=1;
    kazu[C] +=1;

    if (count(kazu.begin(),kazu.end(),2) == 1) cout << "Yes" << endl;
    else cout << "No" << endl;
}



Measured memory_bytes: 256
#include<iostream>

using namespace std;

int Bubble_Sort(int dat[], int size) {
	int count = 0;
	bool judge = 1;
	for (int i = 0; judge; ++i) {
		judge = 0;
		for (int j = size - 1; j >= i + 1; --j) {
			if (dat[j] < dat[j - 1]) {
				swap(dat[j], dat[j - 1]);
				judge = 1;
				++count;
			}
		}
	}
	return count;
}

int main() {
	const int max = 100;
	int size, count,dat[max];
	cin >> size;
	for (int i = 0; i < size; ++i) {
		cin >> dat[i];
	}
	count = Bubble_Sort(dat, size);

	for (int i = 0; i < size; ++i) {
		if (i != 0)cout << " ";
		cout << dat[i];
	}
	cout << endl << count << endl;
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define int long long
#define INF 1000000000000000000
using namespace std;

typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int, int> Pii;

template<typename T>
void readv(vector<T> &a){ REP(i, a.size()) cin >> a[i]; }
void readi(vector<int> &a){ REP(i, a.size()){cin >> a[i]; a[i]--;} }



signed main(){

    string S; cin >> S;
    int ans = 0;
    REP(i, S.size()) if(S[i] == '1') ans++;
    cout << ans;
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N,L;
    cin>>N>>L;
    vector<string>vec(N);
    for (int i = 0; i < N; i++)
    {
        cin>>vec.at(i);
    }
    sort(vec.begin(),vec.end());
    string str;
    for (int i = 0; i < N; i++)
    {
        str +=vec.at(i);
    }
    
    cout<<str<<endl;
}

Measured memory_bytes: 3616
n = int(input())
x = list(map(int, input().split()))

y = list(set(x))
y.sort()

ans = 10**18
for p in range(min(y), max(y)+1):
   tmp = [(x[i]-p)**2 for i in range(n)]
   ans = min(ans, sum(tmp))

print(ans)


Measured memory_bytes: 3060
s_d=input()
t=input()
if len(s_d) < len(t):
    print("UNRESTORABLE")
    exit()
for i in range(len(s_d)-len(t),-1,-1):
    flag = True
    for j,k in zip(s_d[i:i+len(t)],t):
        if j != k:
            flag=False
            break
    if flag:
        s_d = s_d[:i]+t+s_d[i+len(t):]
        break
if not flag:
    for i in range(len(s_d) - len(t), -1, -1):
        flag = True
        for j, k in zip(s_d[i:i + len(t)], t):
            if j != "?" and j != k:
                flag = False
                break
        if flag:
            s_d = s_d[:i] + t + s_d[i + len(t):]
            break
if not flag:
    print("UNRESTORABLE")
else:
    for i in s_d:
        if i == "?":
            print("a",end="")
        else:
            print(i,end="")


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

int main(){
    while (1){
	string inp, ans;
	int n;
	cin >> n;
	if (!n) break;
	cin >> inp;
	ans = inp;
	for (int i = 0; i < n; i++){
	    inp = ans;
	    ans = "";
	    int s = 0;
	    while (s < inp.size()){
		char c = inp[s];
		int count = 0;
		while (inp[s] == c){ count++; s++; }
		if (count >= 10){
		    while (count >= 10){
			ans += (count / 10) + '0';
			count %= 10;
		    }
		}
		ans += (char)(count + '0');
		ans += c;
	    }
	}
	cout << ans << endl;
    }
}

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

#define int long long
#define flash ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define all(x) begin(x),end(x)

int mod = 1e9+7;
int inf = 4e18;
const int N = 5e5+5;
		
signed main()
{
    flash
    int tt = 1;
    //cin>>tt;
    while(tt--)
    {
		int n;
		cin>>n;
		if(n>=30)
		{
			cout<<"Yes";
		}
		else
		{
			cout<<"No";
		}		
    }
    return 0;
}


Measured memory_bytes: 3496
#include<stdio.h>
#define max 1000001

int main(void)
{
	int *d, f1, f2, n, cnt;
	d = new int [max];
	for(f1 = 0; f1 < max; f1++)
	{
		d[f1] = 1;
	}
	for(f1 = 2; f1 *f1 < max; f1++)
	{
		if(d[f1] == 1)
		{
			for(f2 = 2 * f1; f2 < max; f2 += f1)
			{
				d[f2] = 0;
			}
		}
	}
	while (scanf("%d",&n) != EOF)
	{
		cnt=  0;
		for(f1 = 2; f1 <= n; f1++)
		{
			if(d[f1] == 1)
				cnt++;
		}
		printf("%d\n",cnt);
	}
	return 0;
}
	

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <cmath>
#include <string>

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

using namespace std;

int main() {
    string s, t;
    cin >> s >> t;

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

    sort(t.begin(), t.end());
    reverse(t.begin(), t.end());

    if (s < t) cout << "Yes" << endl;
    else cout << "No" << endl;
}


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

int N, W;
int w[101];
long long v[101];
long long dp[101][100001];

long long rec(int i, int j){
	if(dp[i][j] >= 0){
		return dp[i][j];
	}
	long long res;
	if(i == N){
		res = 0;
	}
	else if(j < w[i]){
		res = rec(i+1, j);
	}
	else{
		res = max(rec(i+1, j), rec(i+1, j-w[i]) + v[i]);
	}
	return dp[i][j] = res;
}

void solve(){
	memset(dp, -1, sizeof(dp));
	cout << rec(0, W) << endl;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> N >> W;
	for(int i = 0; i < N; i++)
		cin >> w[i] >> v[i];
	solve();
	return 0;
}

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

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int degitCnt = int.Parse(input[0]);
            int queryCnt = int.Parse(input[1]);

            List<List<string>> dataList = new List<List<string>>();
            for (int loop = 0; loop < queryCnt; loop++)
            {
                dataList.Add(Console.ReadLine().Split(' ').ToList());
            }

            List<string> pro = new List<string>();
            List<string> pro2 = new List<string>();
            string[] ans = new string[degitCnt];
            foreach (List<string> data in dataList) {
                ans[int.Parse(data[0]) - 1] = data[1];
                if (pro.Contains(data[0]) && !pro2.Contains(data[0] + " " + data[1])) { 
                    Console.WriteLine(-1);
                    return;
                }
                pro.Add(data[0]);
                pro2.Add(data[0] + " " + data[1]);
            }

            for (int loop = 0; loop < ans.Count(); loop++) {
                if (ans[loop] == null || ans[loop] == "") {
                    if (loop == 0 && ans.Count() != 1)
                    {
                        ans[loop] = "1";
                    }
                    else { 
                        ans[loop] = "0";
                    }
                }
            }
            if (ans[0] == "0" && ans.Count() != 1) {
                Console.WriteLine(-1);
                return;
            }

            string ansString = string.Join("", ans);
            int intAns = 0;
            if (int.TryParse(ansString, out intAns)) { 
                Console.WriteLine(intAns);
                return;
            }
            Console.WriteLine(-1);
        }
    }
}


Measured memory_bytes: 13280
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string> //文字列
#include <iomanip> //doubleの桁数指定 setprecision()
#include <list> //前後に数値を入れれる配列
#include <map> //map
#include <vector> //vecror



#define REP(i,m,n) for(ll i = (ll) (m);i < (ll) (n);i++) //forの短縮
#define rep(i,n) REP(i,0,n) //REPが0の時
#define ll long long int

using namespace std;

double PI = acos(-1); //円周率

//常設関数↓

//最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

//最小公倍数
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}

//degree → radian
long double chg_DegRad(long double deg) {
	return deg * PI / 180.0;
}

//radian → degree
long double chg_RadDeg(long double rad) {
	return rad * 180.0 / PI;
}
 
//桁数
ll CountDigit(ll n) {
	ll digit = 1;
	while ((n /= 10) != 0) digit++;
	return digit;
}

//距離
double dis(double xa, double ya, double xb, double yb) {
	return pow(pow(xa - xb, 2.0) + pow(ya - yb, 2.0), 0.5);
}

//abs()平均
//pow(,)累乗


//提出コード↓

ll k, n, m;
ll a[1000000];


int main() {
	cin >> k >> n;
	rep(i, n) cin >> a[i];
	REP(i, 1, n) {
		m = max(a[i] - a[i - 1], m);
	}
	m = max(k - a[n - 1] + a[0], m);
	cout << k - m << endl;


	return 0;
}



Measured memory_bytes: 1792
#define _USE_MA_DEFINES
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    int r,g,b,n;
    cin>>r>>g>>b>>n;
    int ans=0;
    rep(i,n+1){
        rep(j,n+1){
            if(i*r+j*g>n)continue;
            if((n-(i*r+j*g))%b==0)ans++;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
const int maxn=0x7fffff;
int main(){
	int n;
	cin>>n;
	vector<int> a(n);
	vector<int> b(n);
	vector<int> c(n);
	for(int i=0;i<n;i++) cin>>a[i];
	for(int i=0;i<n;i++) cin>>b[i];
	for(int i=0;i<n;i++) cin>>c[i];
	sort(a.begin(),a.end());
	sort(c.begin(),c.end());
	long long ans=0;
	for(int i=0;i<n;i++){
		long long j=lower_bound(a.begin(),a.end(),b[i])-a.begin();
		long long k=upper_bound(c.begin(),c.end(),b[i])-c.begin();
		ans+=j*(c.size()-k);
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 1408
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>
#include <deque>
#include <string.h>
using namespace std;

#define REP(i,n) for(int i = 0; i < n; i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef pair<string,string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pi> vpi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

double EPS = 1e-9;
int INFi = 1000000005;
long long INFll = 1000000000000000005ll;
double PI = acos(-1);
int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};
ll MOD = 1000000007;

int N;
const int MAX_N = 100000;
ll A[MAX_N];

int main(){
  cin >> N;
  ll s = 0, maxb = 0;
  ll B[N];
  REP(i, N) {
    cin >> A[i];
    s += A[i];
  }
  REP(i, N) {
    if(i != (N - 1)) B[i] = A[i + 1] - A[i];
    else B[i] = A[0] - A[i];
    maxb = max(maxb, B[i]);
  }

  ll ct = 0;
  REP(i, N) {
    if((maxb - B[i]) % N != 0) {
      cout << "NO" << endl;
      return 0;
    }
    ct += (maxb - B[i]) / N;
  }

  s -= ct * N * (N + 1) / 2;

  if(s >= 0 && s % (N * N * (N + 1) / 2) == 0) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }

  return 0;
}



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

const int MAX_N = 20;

int W, H;
int sx, sy;                 // ?????????????????§?¨?
int dx[4] = {-1, 0, 0, 1};
int dy[4] = { 0,-1, 1, 0};

bool isVisited[MAX_N][MAX_N];

int dfs(const vector<vector<char>>& masu, int x, int y) {
    if (!isVisited[y][x] && masu[y][x] != '#') {
        isVisited[y][x] = true;

        int ret = 1;
        for (int i = 0; i < 4; i++) {
            if (0 <= x+dx[i] && x+dx[i] < W && 0 <= y+dy[i] && y+dy[i] < H) {
                // cout << "#: x=" << x+dx[i] << ", y=" << y+dx[i] << endl;
                ret += dfs(masu, x+dx[i], y+dy[i]);
            }
        }

        return ret;
    }
    return 0;
}

int main(void) {

    while (cin >> W >> H, W) {
        for (int i = 0; i < MAX_N; i++) {
            for (int j = 0; j < MAX_N; j++) {
                isVisited[i][j] = false;
            }
        }

        vector<vector<char>> masu(H, vector<char>(W));
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                cin >> masu[i][j];
                if (masu[i][j] == '@') {
                    sx = j;
                    sy = i;
                }
            }
        }

        cout << dfs(masu, sx, sy) << endl;
    }

    return 0;
}

Measured memory_bytes: 1236
#include <stdio.h>
int A[100];
int k=0;
void selectionSort(int);

int main()
{
  int N,i,l,b;
  double f;
  scanf("%d",&N);
  for(i=0;i<N;i++){
    scanf("%d",&A[i]);
  }
  selectionSort(N);
  for(i=0;i<N;i++){
    if(i>0) printf(" ");
    printf("%d",A[i]);
  }
  //f=(double)k/2;
  //f=10*f;
  //b=f;
  //if(b%10>=5) k=b/10+1;
  //else k=f/10;
  printf("\n%d\n",k);
  return 0;
}

void selectionSort(int h)
{
  int i,minj,j,temp;
  for(i=0;i<=h-2;i++){
    minj=i;
    for(j=i;j<=h-1;j++){
      if(A[j]<A[minj]){
	minj=j;
	//k++;
      }
    }
    temp=A[i];
    A[i]=A[minj];
    A[minj]=temp;
    if(i!=minj) k++;
  }
}

Measured memory_bytes: 604