akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
public class Main {
	public static void main(String[]args) {
		Scanner sc = new Scanner(System.in);
				int a = sc.nextInt();
				int b = sc.nextInt();
				int c = sc.nextInt();
				int d = a-b;
				int e = c-d;
      if(e<=0){
        System.out.println('0');
      }else{
				System.out.println(e);
      }
	}
}

Measured memory_bytes: 21844
#include <iostream>
using namespace std;
int main(void){
   int a,b;
   cin >> a >> b;
if (a < b){
   cout << "a < b" << endl;
}else if (a > b){
   cout << "a > b" << endl;
}else{
   cout << "a == b" << endl;
}

}

Measured memory_bytes: 1156
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main(int argc, char **argv)
{
	int n, q; cin >> n >> q;
	string str; cin >> str;

	vector<int> flags(n-1, 0);
	for (int i = 0; i < n-1; ++i)
	{
		if (str[i] == 'A' && str[i+1] == 'C')
			flags[i] = 1;
	}

	vector<int> com(n, 0);
	for (int i = 0; i < n; ++i)
		com[i+1] = com[i] + flags[i];

	for (int i = 0; i < q; ++i)
	{
		int l, r;
		cin >> l >> r;
		--l;
		--r;
		std::cout << com[r] - com[l] << std::endl;
	}
}

Measured memory_bytes: 1792
a,b=gets.split.map(&:to_i);puts (([1,3,5,7,8,10,12].include?(a) and [1,3,5,7,8,10,12].include?(b)) or ([4,6,9,11].include?(a) and [4,6,9,11].include?(b))or(2==a and 2==b)) ? 'Yes':'No'

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

int main()
{

    int n,a[200001],mx1=-1,mx2=-2;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];

        if(a[i]>=mx1)
        {
            mx2=mx1;
            mx1=a[i];
        }
        else
        {
            if(a[i]>mx2)
            mx2=a[i];
        }
    }
    //cout<<mx1<<" "<<mx2;
    for(int i=1;i<=n;i++)
    {
        if(a[i]==mx1)
            cout<<mx2<<endl;
        else
            cout<<mx1<<endl;
    }
    return 0;
}


Measured memory_bytes: 2432
#include <iostream>
#include <string>
#include <vector>

int BIT(std::vector<int> &a,int A)
{
  int c=0;
  int N=a.size();
  
  std::vector<std::vector<int>> result;
  result.reserve(N);
  for (int bit=0;bit!=(1<<N);bit++)
  {
    c++;
    std::vector<int> t;
    t.reserve(N);
    int sum=0;
    for (int i=0;i!=N;i++)
    {
      if (bit&(1<<i))
      {
        t.push_back(a[i]);
        sum+=a[i];
      }
    }
    
    if (sum==A)
    {
      result.push_back(std::move(t));
    }
  }
  
  return result.size();
}

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

  int h,w,k;
  std::cin>>h>>w>>k;

  std::vector<std::vector<char>> g(h,std::vector<char>(w,0));
  std::vector<int> HValue(h,0);
  std::vector<int> WValue(w,0);
  for(int i=0;i!=h;i++)
  {
    for(int j=0;j!=w;j++)
    {
      std::cin>>g[i][j];

      if(g[i][j]=='#')
      {
        HValue[i]++;
        WValue[j]++;
      }
    }
  }

  int result=0;
  for(int bit=0;bit!=(1<<h);bit++)
  {
    std::vector<int> hvalue=HValue;
    std::vector<int> wvalue=WValue;

    int sum=0;
    for(int i=0;i!=h;i++)
    {
      if(bit&(1<<i))
      {
        for(int j=0;j!=w;j++)
        {
          if(g[i][j]=='#')
          {
            hvalue[i]=0;
            wvalue[j]--;
          }
        }
      }
      sum+=hvalue[i];
    }

    int over=sum-k;

    if(over<0)
      continue;

    result+=BIT(wvalue,over);
  }

  std::cout<<result<<std::endl;
  
  return 0;
}

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

int main() {
	int n, k;
	char s[20];
	cin >> n;
	cin >> s;
	cin >> k;

	for (int i = 0; i < n; i++) {
		if (s[i] == s[k - 1]) cout << s[i];
		else cout << "*";
	}

	return 0;
}

Measured memory_bytes: 384
fun main(args: Array<String>) {
    val (L, R) = readLine()!!.split(" ").map { it.toLong() }

    var minMod = Long.MAX_VALUE

    for (i in L..R) {
        for (j in L..R) {
            if (i < j) {
                val mod = (i * j) % 2019

                if (mod == 0.toLong()) {
                    println(0)
                    return
                }

                minMod = Math.min(minMod, mod)
            }
        }
    }

    println(minMod)
}


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

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))

#define INF 2e9
#define INF_LL 1LL<<60
#define ll long long
#define ALL(v) (v).begin(), (v).end()

typedef pair<ll, ll> P;
map<ll, ll> mp;
vector<int> a(100001);
int dp[100001]; /*i本目の柱に行くための最小値*/

int main(){
    int n, k;
    cin >> n >> k;
    vector<bool> d(11);
    REP(i, 11) d[i] = false;
    REP(i, k) {
        int tmp;
        cin >> tmp;
        d[tmp] = true;
    }
    bool flag = false;

    REPN(i, n, 10*n+1) {
        flag = false;
        int tmp = i;
        while(tmp > 0) {
            if(d[tmp%10]) {
                flag = true;
                break;
            }
            tmp /= 10;
        }
        if(!flag) {
            cout << i << endl;
            return 0;
        }
    }



    return 0;
}


Measured memory_bytes: 640
/* ---------- STL Libraries ---------- */

// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>

/* ---------- Namespace ---------- */

using namespace std;

/* ---------- Type Abbreviation ---------- */

template <typename T>
using PQ = priority_queue<T>;
template <typename T>
using GPQ = priority_queue<T, vector<T>, greater<T>>;

using ll = long long;

#define fst first
#define snd second
#define mp make_pair
#define mt make_tuple

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)


/* ---------- conversion ---------- */

#define INT(c) static_cast<int>(c)
#define CHAR(n) static_cast<char>(n)
#define LL(n) static_cast<ll>(n)
#define DOUBLE(n) static_cast<double>(n)

/* ---------- container ---------- */

#define ALL(v) (v).begin(), (v).end()
#define SIZE(v) (LL((v).size()))
#define each(itr,v) for(auto (itr):(v))

#define FIND(v, k) (v).find(k) != (v).end()
#define VFIND(v, k) find(ALL(v), k) != (v).end()

#define gsort(b, e) sort(b, e, greater<decltype(*b)>())

/* ----------- debug ---------- */

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

template <class T>
ostream& operator<<(ostream& os, set<T> v) {
	os << "[";
	for (auto vv : v)
		os << vv << ",";
	return os << "]";
}

template <class L, class R>
ostream& operator<<(ostream& os, pair<L, R> p) {
	return os << "(" << p.fst << "," << p.snd << ")";
}

/* ---------- Constants ---------- */

// const ll MOD = 1e9 + 7;
// const int INF = 1 << 25;
// const ll INF = 1LL << 50;
// const double PI = acos(-1);
// const double EPS = 1e-10;
// mt19937 mert(LL(time(0)));

/* ---------- Short Functions ---------- */

template <typename T>
T sq(T a) {
	return a * a;
}

template <typename T>
T gcd(T a, T b) {
	if (a > b) return gcd(b, a);
	return a == 0 ? b : gcd(b % a, a);
}

template <typename T, typename U>
T mypow(T b, U n) {
	if (n == 0) return 1;
	if (n == 1) return b /* % MOD */;
	if (n % 2 == 0) {
		return mypow(b * b /* % MOD */, n / 2);
	}
	else {
		return mypow(b, n - 1) * b /* % MOD */;
	}
}

ll pcnt(ll b) {
	return __builtin_popcountll(b);
}



// const ll dx[4] = {0, -1, 1, 0};
// const ll dy[4] = {-1, 0, 0, 1};
// const ll dx[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
// const ll dy[8] = {-1, -1, -1, 0, 0, 1, 1, 1};

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll N, K;
	cin >> N >> K;
	pair<long long, long long> P[N];
	REP(i, N) {
		cin >> P[i].first >> P[i].second;
	}
	sort(P, P + N);
	ll i = 0, cnt = 0;
	while (true) {
		cnt += P[i].second;
		if (cnt >= K) {
			cout << P[i].first << endl;
			break;
		}
		i++;
	}
	return 0;

}

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

#define fi first
#define se second
#define be begin
#define en end
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ALL(a) (a).be() , (a).en()
#define REP(i,n) for(int i=0;i<(n);i++)        //repeat n times
#define REP2(i,s,n) for(int i=(s);i<(n);i++)   //repeat from s to n 
#define REPD(i,n) for(int i=(n);i>=0;i--)      //repeat from n to 0
#define REPD2(i,s,e) for(int i=(s);i>=(e);i--) //repeat from s to e
#define RANGE(i,v) for(auto &i:v)                  //repeat range
#define ASIZE(a) (sizeof(a) / sizeof(a[0]))          //array size

using LL = long long;

template<typename T1,typename T2> using P = pair< T1, T2 >;
using Pii = P<int,int>;
using Pll = P<LL,LL>;
using Pdd = P<double,double>;
using Psi = P<string,double>;

template<typename T> using V = vector< T >;
using Vi = V<int>;
using Vll = V<LL>;
using Vs = V<string>;

int main(){
    int N;
    cin>>N;
    Vi A(N);
    REP(i,N) cin>>A[i];

    sort(ALL(A));

    V<bool> dp(1000005,true);
    
    LL cnt = 0;
    REP(i,N){
        if((i<N && A[i] != A[i+1]) && dp[A[i]]) cnt++;
        int j = 1;
        while(A[i]*j<=A[A.size()-1]){
            dp[A[i]*j] = false;
            j++;
        }
    }

    cout<<cnt<<endl;

    return 0;
}

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

const long long INF=1LL<<60;

vector<long long> h(110010);
vector<long long> dp(110010,INF);


int main(){
  int N;
  cin>>N;
  for(int i=0; i<N; i++){
    cin>>h.at(i);
  }
  dp.at(0)=0;
  for(int i=0; i<N; i++){
    dp.at(i+1)=min(dp.at(i+1),dp.at(i)+abs(h.at(i)-h.at(i+1)));
    dp.at(i+2)=min(dp.at(i+2),dp.at(i)+abs(h.at(i)-h.at(i+2)));
  }
  
  cout<<dp.at(N-1)<<endl;
}
  



Measured memory_bytes: 4948
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

int main(int argc, const char* argv[])
{
	int a;
	int b;
	int c;
	int A[]={1,2,3};
	scanf("%d",&a);
	scanf("%d",&b);
	for(int i=0;i<3;i++)
	{
		if(A[i]==a||A[i]==b)
		A[i]=0;
	}
	for(int i=0;i<3;i++)
	{
		c=A[i]+c;
	}
	printf("%d",c);
	return 0;
}

Measured memory_bytes: 128
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <climits>
#include <bitset>
#include <array>
#include <deque>
#include <queue>
#include <map>
#define all(x) (x).begin(),(x).end()

int solve(int num){
    int ret = 0;
    while(num % 100 == 0){
        num /= 100;
        ret++;
    }
    return ret;
}
int main(){
    int D,N;
    cin >> D >> N;
    int cnt = 0, num = 0;
    while(cnt < N) {
        num++;
        if (solve(num) == D) cnt++;
    }
    cout << num << endl;

    return 0;
}


Measured memory_bytes: 256
/* 
 * 大文字と小文字の入れ替え
 * https://onlinejudge.u-aizu.ac.jp/courses/lesson/2/ITP1/8/ITP1_8_A
 */

#include <iostream>
#include <string>

int main()
{
	std::string str;

	std::getline( std::cin, str );
	for( int i = 0; str[i] != '\0'; i++ ){
		if( 'a' <= str[i] && str[i] <= 'z' ){
			str[i] += 'A' - 'a';
		}
		else if( 'A' <= str[i] && str[i] <= 'Z' ){
			str[i] += 'a' - 'A';
		}
	}
	std::cout << str << std::endl;
}


Measured memory_bytes: 3176
Aij = []
c = 0
for i in range(3):
    A = list(map(int, input().split()))
    Aij.append(A[0])
    Aij.append(A[1])
    Aij.append(A[2])

N = int(input())
for i in range(N):
    b = int(input())
    if b in Aij:
        Aij[Aij.index(b)] = 0

for i in range(3):
    if Aij[3*i] == Aij[3*i+1] and Aij[3*i] == Aij[3*i+2]:
        c = -1
        break

    if Aij[i] == Aij[i+3] and Aij[i] == Aij[i+6]:
        c = -1
        break

if c == Aij[4]:
    if Aij[0] == Aij[4] and Aij[4] == Aij[8]:
        c = -1
    elif Aij[2] == Aij[4] and Aij[4] == Aij[6]:
        c = -1
    else:
        pass

print(['No', 'Yes'][c])

Measured memory_bytes: 9036
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long LL;
const int N = 1e5 + 5;
int read() {
	int x = 0, f = 1; char ch;
	while(! isdigit(ch = getchar())) (ch == '-') && (f = -f);
	for(x = ch ^ 48; isdigit(ch = getchar()); x = (x << 3) + (x << 1) + (ch ^ 48));
	return x * f;
}
template <class T> T Max(T a, T b) { return a > b ? a : b; }
template <class T> T Min(T a, T b) { return a < b ? a : b; }
LL p[N];
int n, s, x[N];
LL calc(int l, int r, int t) {
	if(s < x[l]) return x[r] - s;
	if(x[r] < s) return s - x[l];
	if(p[l] >= p[r]) return p[l] += p[r], calc(l, r - 1, l) + (t == r ? x[r] - x[l] : 0);
	else return p[r] += p[l], calc(l + 1, r, r) + (t == l ? x[r] - x[l] : 0);
}
int main() {
//	freopen(".in", "r", stdin);
//	freopen(".out", "w", stdout);
	n = read(); s = read();
	for(int i = 1; i <= n; ++ i) x[i] = read(), p[i] = read();
	printf("%lld\n", calc(1, n, p[1] < p[n] ? 1 : n));
	fclose(stdin);
	fclose(stdout);
	return 0;
}


Measured memory_bytes: 5248
#include <bits/stdc++.h>
using namespace std;
 
#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
 
 
void func(long long N, long long A, long long B, long long C, long long D, long long E){
    lli num = min({A,B,C,D,E});
 
    lli tmp = (N-1)/num + 1;
    cout<<tmp+4<<endl;
}
 
int main(){
    // cout << fixed << setprecision(5);
 
    long long N;
    scanf("%lld",&N);
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long C;
    scanf("%lld",&C);
    long long D;
    scanf("%lld",&D);
    long long E;
    scanf("%lld",&E);
    func(N, A, B, C, D, E);
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

        int w = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();

        int diff = Math.max(a, b) - (Math.min(a,b)+w);

        if (diff > 0)
            System.out.println(diff);
        else
            System.out.println(0);
    }
}


Measured memory_bytes: 23252
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rrep(i,n) for (int i = (int)(n)-1; i>=0; --i)
#define For(i,a,b) for(auto i=(a);i<=(b);++i)
#define rFor(i,a,b) for(auto i=(b);i>=(a);--i)
#define call(var) cerr<<#var<<"="<<var<<"\n";
#define dup(x,y) (((x)+(y)-1)/(y))
#define all(x) (x).begin(),(x).end()
using ll=long long;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using Graph = vector<vi>;
using P = pair<int,int>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;
const double pi = acos(-1);
template<class t,class u> inline bool chmax(t&a,u b){if(a<b){a=b;return true;}return false;}
template<class t,class u> inline bool chmin(t&a,u b){if(b<a){a=b;return true;}return false;}
template<class T> istream& operator>>(istream& is, vector<T>& a){rep(i,a.size()) is >> a[i]; return is;}
template<class T> ostream& operator<<(ostream& os, vector<T>& a){rep(i,a.size()) os << a[i] << " "; return os;}
template<class T, class U> istream& operator>>(istream& is, pair<T,U>& p){is >> p.first >> p.second; return is;}
template<class T, class U> ostream& operator<<(ostream& os, const pair<T,U>& p){os << "("<< p.first << "," << p.second << ")"; return os;}
template<class T, class U> ostream& operator<<(ostream& os, const map<T,U>& mp){for(auto& t : mp) os << t.first << " " << t.second << "\n"; return os;}

int main(){
    int n;cin >> n;
    vi a(n);
    cin >> a;
    int ans = 0;
    for(int i=0;i<n;++i){
        if(i%2 == 0 && a[i]%2 == 1) ++ans;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3596
# include "bits/stdc++.h"
 
using namespace std;
 
#define endl "\n"
typedef long long int ll;
#define f first
#define s second
 
inline void fastio(){ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);}
inline void setPrecision(int n){cout.precision(n);}
 
//DEBUG
#define dbg(x) cerr<<(#x)<<": "<<x<<endl
#define dbgV(x) cerr<<(#x)<<": "; for(auto it: x) cerr<<it<<" "; cerr<<endl;
#define dbgS(x) cerr<<(#x)<<": "; for(auto it: x) cerr<<it<<" "; cerr<<endl;
#define dbgM(x) cerr<<(#x)<<": "; for(auto it: x) cerr<<"["<<it.f<<", "<<it.s<<"] "; cerr<<endl;
#define dbg2D(x) cerr<<(#x)<<": \n"; for(auto y: x) { for(auto it: y) cerr<<it<<" "; cerr<<endl; } cerr<<endl;
#define dbgA(x, n) cerr<<(#x)<<": "; for(int i=0;i<n;++i) cerr<<x[i]<<" "; cerr<<endl;
#define dbgVP(x) cerr<<(#x)<<": "; for(auto it: x) cerr<<"["<<it.f<<", "<<it.s<<"] "; cerr<<endl;
 
ll INF = 1e10;
int MOD = 1e9+7;

int main(){
    fastio();

    int h, n, x;
    cin >> h >> n;
    int sum = 0;
    for(int i = 0; i < n; ++i){
    	cin >> x;
    	sum += x;
    }

    cout << (sum >= h ? "Yes" : "No");

    return 0;
}

/*

*/

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

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

   int w,h,n,p = 0, q = 0;
   cin >> w >> h >> n;
   int x,y,a;
   rep(i,n){
      cin >> x >> y >> a;
      
      if(a == 1 && p < x){
         p = x;
      }
      if(a == 2 && w > x){
         w = x;
      }
      if(a == 3 && q < y){
         q = y;
      }
      if(a == 4 && h > y){
         h = y;
      }
   }

   if(p >= w || q >= h){
      cout << 0 << endl;
   }else{
      cout << (w - p) * (h - q) << endl;
   }

   return 0;
}

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

#define rep(i, N)  for(int i = 0; i < (N); i++)
#define reps(i, N) for(int i = 1; i <= (N); i++)
#define repr(i, N) for(int i = (N) - 1; i >= 0; i--)
#define pub push_back

template<typename T> 
void chmax(T &a, T b){ a = max(a, b); };
template<typename T> 
void chmin(T &a, T b){ a = min(a, b); };

typedef long long ll;
typedef pair<int, int> P;
const int INF = 100000000;
const ll LINF = 10000000000000000;
const int MOD = 1000000007;
const int dx[9] = { 0, 1,  0, -1, 1,  1, -1, -1, 0};
const int dy[9] = { 1, 0, -1,  0, 1, -1, -1,  1, 0};
//--------------------------------------//
int N;
int C[200000];
int b[200000];

ll dp[200001];
void solve(){
	dp[0] = 1;
	rep(i, N){
		dp[i + 1] = dp[i];
		//d2(i, b[C[i]]);
		//YN;
		if(b[C[i]] != 0 and b[C[i]] != i){
			dp[i + 1] = (dp[i + 1] + dp[b[C[i]]]) % MOD;
		}
		b[C[i]] = i + 1;
	}
	//da(dp, N + 1);
	cout << dp[N] % MOD << endl;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> N;
	rep(i, N) {
		cin >> C[i];
		C[i]--;
	}
		solve();
	return 0;
}


Measured memory_bytes: 3328
//NAME-DEEPESH BHATT
//Institute-IIT Dhanbad
//MOTTO-THINK FIRST,CODE LATER
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll MOD = 1000000007  ;
#define pb push_back
#define mp make_pair
#define endl '\n'
ll gcd(ll a,ll b)
{
    if(b==0)
        return a;
    else
        return gcd(b,a%b);
}
ll lcm(ll a ,ll b)
{
    return a/gcd(a,b)*b;
}
ll power(ll a,ll n)
{
    if (n == 0)
        return 1;
    ll p = power(a, n / 2);
    p = (p * p);
    if (n % 2)
        return (p * a);
    else
        return p;
}
int main()
{
    ios_base::sync_with_stdio(false);    //for fast I/O operation
    cin.tie(NULL);
    ll test=1;
    /*cin>>test;*/
    while(test--) {
        int n;
        cin>>n;
        ll W;
        cin>>W;//MAx weight bag can carry.
        vector<int>w(n);
        vector<ll>v(n);
        ll max_value_sum=0;//Max value that can be achieved not considering the weight.
        for(int i=0;i<n;i++){
            cin>>w[i]>>v[i];
            max_value_sum+=v[i];
        }
        vector<ll>dp(max_value_sum+1);
        for(int i=1;i<=max_value_sum;i++){
            dp[i]=1E18+7;
        }
        dp[0]=0;
        //contains min weights required to achieve that value.
        for(int i=0;i<n;i++){
            for(int j=max_value_sum-v[i];j>=0;j--){
                dp[j+v[i]]=min(dp[j+v[i]],dp[j]+w[i]);
            }
        }
        int ans=0;
        for(int i=0;i<=max_value_sum;i++){
            if(dp[i]<=W){
                ans=max(i,ans);
            }
        }
        cout<<ans;
    }
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(ll i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  string s;
  cin >> s;
  ll ans = 0;
  rep(i, 3) if(s[i] == 'R') ans = 1;
  rep(i, 2) if(s[i] == 'R' && s[i + 1] == 'R') ans = 2;
  if(s == "RRR") ans = 3;
  cout << ans << endl;
}

Measured memory_bytes: 3592
#include <iostream>
#include <string>

using namespace std;

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

    int n, cnt = 0;
    string s;
    cin >> n >> s;
    for (int i = 2; i < n; i++)
        if (s[i] == 'C' && s[i - 1] == 'B' && s[i - 2] == 'A') cnt++;
    cout << cnt << "\n";

    return 0;
}


Measured memory_bytes: 256
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.IntStream;

public class Main {

    private enum right {
        y,
        u,
        i,
        o,
        p,
        h,
        j,
        k,
        l,
        n,
        m,
        ;
   }

    static String current = "";
    static int cnt = 0;
    static List<String> hands = new ArrayList<>();

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line;
        while ((line = br.readLine().trim()) != null && !"#".equals(line)) {
            output(line);
        }
    }

    public static void output(String line) {
        IntStream.range(0, line.length()).mapToObj(i->line.substring(i,i+1)).forEach(key -> {
            if(Arrays.stream(right.values()).map(e->e.name()).anyMatch(e->key.equals(e))) {
                hands.add("r");
            } else {
                hands.add("l");
            };
        });
        IntStream.range(0, hands.size()).mapToObj(i->hands.get(i)).forEach(hand -> {
            if(!current.isEmpty() && !current.equals(hand)) {
                cnt++;
            }
            current = hand;
        });
        System.out.println(cnt);
        hands.clear();
        current = "";
        cnt = 0;
    }
}


Measured memory_bytes: 37804
import sys
def line():return sys.stdin.readline().strip()
def cin():return sys.stdin.readline().strip().split()
N,M = [int(i) for i in cin()]
A = [int(line()) for _ in range(N)]
C = [0] * N
for i in range(M):
    B = int(line())
    for j in range(N):
        if A[j] <= B:
            C[j]+=1
            break
print(max(range(len(C)),key=lambda i:C[i]) + 1)

Measured memory_bytes: 7692
N=int(input())
A=list(map(int, input().split()))

def attack(lst):
    attacker=min(lst)
    position=lst.index(attacker)
    temp=[]
    for i in range(len(lst)):
        if i!=position:
            if lst[i] % attacker!=0:
                temp.append(lst[i]%attacker)
        else:
            temp.append(lst[i])
    return temp

while len(A)>1:
    A=attack(A)
    #print(A)
print(A[0])

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

int main() {
  int N, M;
  cin >> N >> M;
  long total = 0;
  for (int i = 0; i < M; i++) {
    int x;
    cin >> x;
    total += x;
  }

  if (total > N) {
    cout << "-1" << endl;
  } else {
    cout << N - total << endl;
  }
}


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

typedef long long ll;

int main(void){
    ll N;
    cin>>N;
    
    ll A[N];
    vector<ll> B(N+1);
    B[0]=0;
    map<ll,ll> p;
    p[0]=0;
    

    for(int i=0;i<N;i++){
        cin>>A[i];
        B[i+1]=A[i]+B[i];
        p[B[i+1]]=0;
    }
    
    sort(B.begin(),B.end());
    for(int i=0;i<N+1;i++){
        p[B[i]]++;
    }
    
    unique(B.begin(),B.end());
    
    ll count=0;    
    for(int i=0;i<p.size();i++){
        if(p[B[i]]>=2)count+=(p[B[i]])*(p[B[i]]-1)/2;
    }
    
    cout<<count<<endl;
}

Measured memory_bytes: 15872
R,G,B,N=map(int, input().split())

count=0
for p1 in range(0,N+1,R):
    for p2 in range(0,N-p1+1,G):
        rR = p1
        gG = p2
        bB = N-p1-p2
        if bB%B==0:
            count+=1
print(count)

Measured memory_bytes: 3060
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	int N,K;
	scan(N);scan(K);
	if((N+1)/2>=K) prin("YES");
	else prin("NO");
	return 0;
}


Measured memory_bytes: 256
import math


def combinations_count(n):
    return math.factorial(n)


def main():
    mod = 10**9 + 7
    n,m = list(map(int, input().split()))
    if abs(n - m) > 1:
        print(0)
        exit()
    elif n == m:
        ans = (combinations_count(n) * combinations_count(m)) * 2
    else:
        ans = (combinations_count(n)) * (combinations_count(m))
    print(ans % mod)



if __name__ == '__main__':
    main()

Measured memory_bytes: 5192
// finish date: 2018/07/22
#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<double> vd;
typedef vector<vector<double>> vvd;
typedef vector<vector<vector<double>>> vvvd;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, pair<int, int>> plii;
const int bigmod = 1000000007;
const int INF = 1050000000;
const long long INFll = 100000000000000000;


int main() {
    string S, T;
    cin >> S >> T;
    S += S;
    rep(i, S.length() / 2) {
        if (T == S.substr(i, S.length() / 2)){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;


    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(void){
    // Your code here!
    int a,b,c;
    string s,t,u,se,n,to;
    cin>>s>>t>>u;
    ///97-65
    se=s[0]-32;
    n=t[0]-32;
    to=u[0]-32;
    cout<<se<<n<<to<<endl;
}


Measured memory_bytes: 256
n,l=map(int, input().split())
*a,=map(int, input().split())
mx=0
ind=-1
for i in range(n-1):
    if mx<=a[i+1]+a[i]:
        ind=i
        mx=a[i+1]+a[i]
if mx>=l:
    print("Possible")
    for i in range(ind):
        print(i+1)
    for i in range(n-1,ind,-1):
        print(i)
else:
    print("Impossible")

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

int main() {
  int a,b,c=-1,n,d,e;
  cin >>a>>b;

  for(n=1000;n>0;n--){
      d=n*0.08;
      e=n*0.1;
    if(d==a && e==b)c=n;
  }
  
  cout << c << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <list>
#include <map>
#include <set>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <memory.h>
#include <ctime>
#include <bitset>
#include <vector>
#include <string>

using namespace std;

void solution() {
    char c;
    cin >> c;
    cout << ++c << endl;
}

/*-------------------*/

int main()
{
#ifdef Files
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    /*Test*/
    //freopen("input.txt", "w", stdout);

    double OcZ2X = clock();
#else
    //freopen("joke.in", "r", stdin);
    //freopen("joke.out", "w", stdout);
#endif

    solution();

#ifdef Time
    double P2HxQ = clock();
    printf("\n*** Total time = %.3f sec ***\n", (P2HxQ - OcZ2X) / CLOCKS_PER_SEC);
#endif
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
    int x,t;
    scanf("%d%d",&x,&t);
    while((1>x||x>1000000000)||(1>t||t>1000000000))
    {
        scanf("%d%d",&x,&t);
    }
    if(x-t>0)
    {
        printf("%d\n",x-t);
    }
    else
    {
        printf("%d\n",0);
    }
    return 0;
}

Measured memory_bytes: 128
#include "bits/stdc++.h"
#pragma GCC optimize("Ofast")

// Begin {{{
using namespace std;

#ifndef DEBUG
#define dump(...)
#endif

template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

template <class T>
inline vector<T> make_v(const T &initvalue, size_t sz) {
    return vector<T>(sz, initvalue);
}

template <class T, class... Args>
inline auto make_v(const T &initvalue, size_t sz, Args... args) {
    return vector<decltype(make_v<T>(initvalue, args...))>(sz, make_v<T>(initvalue, args...));
}

constexpr int INF = 0x3f3f3f3f;
constexpr int64_t LINF = 0x3f3f3f3f3f3f3f3fLL;
// }}} End

constexpr int MOD = int(1e5);

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    size_t n, m;
    cin >> n >> m;

    vector<intmax_t> cum(n);
    for (size_t i = 1; i <= n - 1; ++i) {
        intmax_t s; cin >> s;
        cum[i] = cum[i - 1] + s;
    }

    intmax_t now = 1, res = 0;
    for (size_t i = 0; i < m; ++i) {
        intmax_t a; cin >> a;
        res += abs(cum[now + a - 1] - cum[now - 1]);
        res %= MOD;
        now += a;
    }

    cout << res << "\n";

    return 0;
}



Measured memory_bytes: 3636
#include <iostream>
#include <fstream>

#include <cmath>

using namespace std;

int main(){
  
    int n,s[1000];
    double sum,sigmaSum;

    while(cin >> n){
        if(!n){break;}
        sum = sigmaSum = 0;
        for(int i=0;i<n;i++){
            cin >> s[i];
            sum += s[i];
        }
        double avg = sum / n;
        for(int i=0;i<n;i++){
            sigmaSum += pow(s[i]-avg,2);
        }
        double sigma = sqrt(sigmaSum / n);

        printf("%.5f\n",sigma);
    }
    return 0;
}


Measured memory_bytes: 3212
import numpy as np

N, S = map(int, input().split())
A = np.array(list(map(int, input().split())))
P = 998244353
table = np.zeros((N, S+1), dtype=int)
table[0, 0] = 2
if A[0] <= S:
    table[0, A[0]] = 1
for i in range(1, N):
    Ai = A[i]
    table[i] += 2*table[i-1]
    if Ai <= S:
        table[i][Ai:] += table[i-1][:S-Ai+1]
    table[i] = table[i]%P

print(table[N-1][S])


Measured memory_bytes: 97360
import java.util.*;
class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();sc.nextLine();
    int count=1;
    String hashh[]=new String[n];
    for(int i=0;i<n;i++){
      hashh[i]=sc.nextLine();
    }
    Arrays.sort(hashh);
    for(int i=1;i<n;i++){
      if(!hashh[i-1].equals(hashh[i])){
        count++;
      }
    }
    pl(count+"");
  }

  public static void pr(String str){
    System.out.print(str);
  }
  public static void pl(String str){
    System.out.println(str);
  }
}


Measured memory_bytes: 73972
#include <iostream>
#include <algorithm>
#include <vector>
using namespace  std;
const long long INF = 1<<30;
const int MAX = 100;
int KnapSack(vector<pair<int, int>> &A, int N, int W){
    vector<vector<int>> dp(N+10, vector<int>(N*MAX+10, INF));
    for(int i=0; i<=N; i++) dp[i][0] = 0;
    for(int i=0; i<N; i++){
        for(int j=0; j<=N*MAX; j++){
            if(j-A[i].first>=0 and dp[i][j-A[i].first]!=INF){
                dp[i+1][j] = min(A[i].second + dp[i][j-A[i].first], dp[i][j]);
            }
            else dp[i+1][j] = dp[i][j];
        }
    }
    int res = 0;
    for(int i=1; i<=N*MAX; i++){
        if(dp[N][i]<=W) res = max(res, i);
    }
    return res;
}
signed main(){
    int N, L;
    cin>>N>>L;
    vector<pair<int, int>> A(N);
    for(int i=0; i<N; i++){
        int v, w; cin>>v>>w;
        A[i] = make_pair(v, w);
    }
    cout << KnapSack(A, N, L) << endl;
    return 0;
}


Measured memory_bytes: 7100
#include "bits/stdc++.h"

using namespace std;

int n;
string x[2];

const int MOD = 1000000007;

map <pair <int, pair <int, int>>, int> ODW;

int go(int akt, pair <int, int> poprz)
{
  if(akt == n)
    return 1;
  if(ODW.find(make_pair(akt, poprz)) != ODW.end())
    return ODW[make_pair(akt, poprz)];
  int score = 0;
  if(x[0][akt] == x[1][akt])
  {
    for(int i=0; i<3; i++)
      if(i != poprz.first and i != poprz.second)
        score = (score+go(akt+1, {i,i}))%MOD;
  }
  else
  {
    for(int i=0; i<3; i++)
      for(int j=0; j<3; j++)
        if(i != poprz.first and j != poprz.second and i != j)
          score = (score+go(akt+2, {i,j}))%MOD;
  }
  return ODW[make_pair(akt, poprz)] = score;
}

int main()
{
  cin >> n;
  cin >> x[0] >> x[1];



  cout << go(0, {-1, -1}) << "\n";
}


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

int main(){
	string in;
	double x[4], y[4];
	while(1){
		getline( cin, in );
		if( in.length() == 0 )	return 0;
		sscanf( in.c_str(), "%lf %lf %lf %lf %lf %lf %lf %lf", &x[0], &y[0], &x[1], &y[1], &x[2], &y[2], &x[3], &y[3] );
		double v1[2] = {x[1]-x[0], y[1]-y[0]},
			   v2[2] = {x[3]-x[2], y[3]-y[2]};
		if( v1[0]*v2[0]+v1[1]*v2[1] == 0.0 )
			printf("YES\n");
		else
			printf("NO\n");
	}
	return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
#include <stdlib.h>
#include <math.h>


int main(void)
{

    int n;
    scanf("%d", &n);
    int v[n];
    for (int i=0; i < n; i++)
        scanf("%d", &v[i]);
    int c[n];
    for (int i=0; i < n; i++)
        scanf("%d", &c[i]);

    int d = 0;
    for (int i=0; i < n; i++){
        if (c[i] < v[i])
            d += v[i] - c[i];
    }


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


    return 0;
} 



Measured memory_bytes: 128
#import<bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef long long LL;
LL i,j,k,m,n,p=1,v,a[1050000],l[1050000],r[1050000];
LL M(LL x,LL y,LL d)
{
	if(x<=l[d]&&r[d]<=y)return a[d];
	if(r[d]<x||y<l[d])return 0;
	return max(M(x,y,d<<1),M(x,y,(d<<1)+1));
}
void REP(int i,LL k)
{
	for(a[i+=p]=k;i>>=1;)
	{
		a[i]=max(a[i<<1],a[(i<<1)+1]);
	}
}
main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>k;
	for(p=524288;i<p;i++)l[p+i]=r[p+i]=i;
	for(i=p;--i;)
	{
		l[i]=l[i<<1];
		r[i]=r[(i<<1)+1];
	}
	for(i=0;i++<n;)
	{
		cin>>v;
		REP(v,M(max(0LL,v-k),min(300000LL,v+k),1)+1);
		m=max(m,a[v+p]);
	}
	cout<<m;
}

Measured memory_bytes: 24780
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	string s;
	cin>>s;
	if(s[2]==s[3] && s[4]==s[5])
	 cout<<"Yes";
	else
	 cout<<"No";
	return 0;
}

Measured memory_bytes: 3616
#include<stdio.h>
int main(){
	unsigned long int n,a,b,c,d,e,t,i=1,ans;
	scanf("%lu%lu%lu%lu%lu%lu",&n,&a,&b,&c,&d,&e);
	t=a;
	if(t>b){t=b;}
	if(t>c){t=c;}
	if(t>d){t=d;}
	if(t>e){t=e;}
	if(n%t==0){i=0;}
	ans=n/t+i+4;
	printf("%lu",ans);
	return 0;
}

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


def main():
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))

    A2 = sorted(A)
    B2 = sorted(B)
    
    for i in range(0, N):
        if A2[i] > B2[i]:
            print('No')
            return

    for i in range(1, N):
        if A2[i] <= B2[i-1]:
            print('Yes')
            return
            
    B3 = sorted(map(lambda x: (x[1][1], x[0]),
                  enumerate(sorted(map(lambda x: (x[1], x[0]),
                                       enumerate(B))))))
    C = list(map(lambda x: x[1][1], sorted(zip(A, B3))))

    p = 0
    for i in range(N-1):
         p = C[p]
         if p == 0:
             print('Yes')
             return
            
    print('No')


if __name__ == '__main__':
    main()


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

class Main {
	public static void main(String args[]) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		Solver solver = new Solver();
		solver.init();
		solver.readHead(in.readLine());
		// for (; solver.hasNext();) {
		// solver.readBody(in.readLine());
		// }
		// solver.solve();
	}
}

class Solver {
	int N;
	int cnt;

	public void init() {
		N = 0;
		cnt = 0;
	}

	public void readHead(String str) {
		String[] strArr = str.split(" ");
		// N = Integer.parseInt(strArr[0]);
		// System.out.println(N);
		long A = Long.parseLong(strArr[0]);
		long B = Long.parseLong(strArr[1]);
		long C = Long.parseLong(strArr[2]);

		long ans = Long.min(C, A + B + 1) + B;
		System.out.println(ans);
	}

	public boolean hasNext() {
		return cnt < N;
	}

	public void readBody(String str) {
		// System.out.println(str);
		cnt++;
	}

	public void solve() {

	}
}


Measured memory_bytes: 21076
//#define _USE_MATH_DEFINES
#include <iostream>
//#include <stdio.h>
//#include <iomanip>
#include <vector>
//#include <string>
//#include <algorithm>
//#include <functional>
//#include <cmath>
//#include <time.h>

using namespace std;


int main(){

	int w, n;
	int a, b;
	char c;
	vector <int> aa;

	cin >> w;

	for (int i = 0; i < w; i++){
		aa.push_back(i + 1);
	}
	
	cin >> n;

	while (n--){
		cin >> a >> c >> b;
		swap(aa[a - 1], aa[b - 1]);
	}

	for (int i = 0; i < w; i++){
		cout << aa[i] << endl;
	}


	return 0;
}

Measured memory_bytes: 1216
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (b == 0) return a;
  return gcd(b, a%b);
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}
bool is_prime(ll n) {
  for (ll i = 2; i*i <= n; i++) {
    if (n%i == 0) return false;
  }
  return n != 1;
}
ll mod_pow(ll x, ll n, ll mod) {
  if (n == 0) return 1;
  ll res = mod_pow(x*x%mod, n/2, mod);
  if (n & 1) res = res * x % mod;
  return res;
}

int main() {
  double n;
  cin >> n;
  double res = (n/3.0) * (n/3.0);
  n -= 2.0 * (n/3.0);
  res *= n;
  cout << fixed << setprecision(10);
  cout << res << endl;
}

Measured memory_bytes: 256
s=input()
n=len(s)
# ある桁まで、ぴったり支払う時の解、+1円支払う時の解
# はじめは0円に対して考えるので、0と1。
dp=0,1
# 上からi+1桁目にたいして 
for i in range(n):
  si=int(s[i])
  # i+i桁目までぴったり払うときの最小値。ひとつ上の桁で+1払っているときは、繰り下がりを考慮。
  a=min(dp[0]+si,dp[1]+10-si)
  # i+1桁目までぴったり＋1を払う時の最小値。
  # つまり、次の桁に繰り下がりの1を残す。この桁における1は次の桁から見れば10。なのでdp[1]からの遷移には10が計算の項にある。
  b=min(dp[0]+si+1,dp[1]+10-(si+1))
  dp=a,b
print(dp[0])

Measured memory_bytes: 75928
#include <bits/stdc++.h>
using namespace std;
#define REP(i,b,e) for(int i=(b);i<(e);++i)
#define RREP(i,b,e) for(int i=(b)-1;i>=e;--i)
#define rep(i,e) for(int i=0;i<(e);++i)

constexpr int MOD = 1000000007;
constexpr int INF = 1LL << 30;
constexpr long long LLINF = 1LL << 62;

template<typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "[";
  for (auto it = vec.begin(); it != vec.end(); ++it) {
    if (it != vec.begin()) os << ", ";
    os << *it;
  }
  return os << "]";
}

inline void print(void) { cout<<'\n'; }
template<class T> inline void print(const T &x) { cout<<x<<'\n'; }
template<class T, class... U> inline void print(const T &x, const U&... y) { cout<<x<<" "; print(y...); }

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

int h, w;
char g[55][55];
int dists[55][55];

void bfs() {
  rep(i, h) rep(j, w) dists[i][j] = INF;
  dists[0][0] = 1;
  queue<pair<int, int>> q;
  q.emplace(0, 0);
  while (!q.empty()) {
    int x, y;
    tie(y, x) = q.front(); q.pop();
    rep(i, 4) {
      int nx = x + dx[i];
      int ny = y + dy[i];
      if (dists[ny][nx] != INF or nx < 0 or w <= nx or ny < 0 or h <= ny) continue;
      if (g[ny][nx] == '#') continue;
      dists[ny][nx] = dists[y][x] + 1;
      q.emplace(ny, nx);
    }
  }
}

int main() {
  cin>>h>>w;
  rep(i, h) rep(j, w) cin>>g[i][j];

  int bs = 0;
  rep(i, h) rep(j, w) if (g[i][j] == '#') ++bs;
  bfs();

  int dist = dists[h-1][w-1];
  if (dist == INF) print(-1);
  else print(h*w - dist - bs);

  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main( void ) {
	int i, n, sum, min, max, tmp;

	for ( ; scanf( "%d", &n ), n; printf( "%d\n", ( sum - min - max ) / ( n - 2 ) ) ) {
		max = sum = 0;
		min = 1000;
		for ( i = n; i--; sum += tmp ) {
			scanf( "%d", &tmp );

			if ( tmp < min )
				min = tmp;
			if ( max < tmp )
				max = tmp;
		}
	}

	return 0;
}

Measured memory_bytes: 600
#include<stdio.h>
int main()
{
  int X,Y;
  scanf("%d %d",&X,&Y);
  int a,b,flag=0;
  for(a=0;a<100;a++){
    for(b=0;b<100;b++){
      if(a+b==X && 2*a+4*b==Y){flag = 1;}
    }
  }
  if(flag==1){
    printf("Yes");
  }else{
    printf("No");
  }
}

Measured memory_bytes: 1732
N = int(input())
A = list(map(int, input().split()))

MODN = int(1e9 +7)

def modpow(a, n, modn):
  res = 1
  while n>0:
    if n % 2 == 1:
      res = res * a % modn
    a = a * a % modn
    n = n // 2
  return res

fact = [1] * (N+1)
for i in range(1,N+1):
  fact[i] = fact[i-1] * i % MODN
  
# sum(1/i) for i in 1 to N with MODN condition
divsum = [0] * (N+1) #1-indexed
for i in range(1,N+1):
  divsum[i] = (divsum[i-1] + modpow(i, MODN-2, MODN)) % MODN
  
#print(fact)
#print(divsum)

ans = 0
for i in range(N):
  work = 1 + (divsum[i+1] - 1 if i > 0 else 0) + (divsum[N-i] - 1 if i < N-1 else 0)
  #print(work, A[i], i)
  ans += work * A[i] % MODN
  
print(ans * fact[N] % MODN)


Measured memory_bytes: 17228
#include <iostream>
#include <string>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#define rep(i,j,k) for(i=j;i<(k);i++)
#define rrep(i,j,k) for(i=j;i>(k);i--)
typedef long long int lli;

using namespace std;

int main() {
    lli N,n,h;
    double w;
    lli i,j;
    cin>>N;
    rep(h,1,3501){
        rep(n,h,3501){
            if(4*h*n-N*n-N*h>0){
                w=(double)N*(double)h*(double)n/(4.0*(double)h*(double)n-(double)N*(double)n-(double)N*(double)h);
                if(floor(w)==w&&w>0&&w<3501){
                    cout<<h<<" "<<n<<" "<<(int)w<<" "<<endl;
                    exit(0);
                }
            }
        }
    }
}


Measured memory_bytes: 256
using System;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            string input = Console.ReadLine();
            string[] array = input.Split(' ');
            int min = 0, max = 0;
            long sum = 0;
            int[] outp = new int[n];

            for (int t = 0; t < array.Length; t++)
            {
                outp[t] = int.Parse(array[t]);
                sum = sum + outp[t];
            }

            for (int i = 0; i < outp.Length; i++)
            {
                for (int j = outp.Length - 1; j > i; j--)
                {
                    if (outp[i] > outp[j])
                    {
                        int w = outp[i];
                        outp[i] = outp[j];
                        outp[j] = w;
                    }
                }
            }
            min = outp[0];
            max = outp[outp.Length - 1];

            Console.WriteLine(string.Format("{0} {1} {2}", min, max, sum));
        }
    }
}

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

using namespace std;

long long INF=1e15;

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

    long long n,x;
    cin>>n>>x;

    vector<long long> a(n);
    for(int i=0;i<n;i++)cin>>a[i];

    long long ans=0;

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

    vector<long long> MIN=a;

    for(int i=0;i<n;i++){
        long long sum=0;
        for(int j=0;j<n;j++){
            if((j-i)<0)MIN[j]=min(MIN[j],a[(j-i+n)]);
            else MIN[j]=min(MIN[j],a[(j-i)]);
        }
        for(int j=0;j<n;j++)sum+=MIN[j];
        ans=min(ans,sum+x*i);
    }

    cout<<ans<<endl;

}

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

#define ll long long

int main(){
	int n;
	cin >> n;
	if(n >= 400 && n < 600){
		cout << 8 << endl;
	}else if(n >= 600 && n < 800){
		cout << 7 << endl;
	}else if(n >= 800 && n < 1000){
		cout << 6 << endl;
	}else if(n >= 1000 && n < 1200){
		cout << 5 << endl;
	}else if(n >= 1200 && n < 1400){
		cout << 4 << endl;
	}else if(n >= 1400 && n < 1600){
		cout << 3 << endl;
	}else if(n >= 1600 && n < 1800){
		cout << 2 << endl;
	}else if(n >= 1800 && n < 2000){
		cout << 1 << endl;
	}
}

Measured memory_bytes: 3628
import java.util.Scanner;

class Card{
    public String suit;
    public int value;
    public int index;
}

public class Main{
    public static void main(String[] args){
	int i, q;
	
	Scanner s = new Scanner(System.in);
	int n = s.nextInt();
    	Card[] A = new Card[n];
	Card[] B = new Card[n];

	for(i=0; i<n; i++){
	    A[i] = new Card();
	    B[i] = new Card();
	}

	for(i=0; i<n; i++){
	    A[i].suit = s.next();
	    A[i].value = s.nextInt();
	    A[i].index = i; 
	}

	quickSort(A, n, 0, n-1);

	;

	if(isStable(A) == true){
	    System.out.print("Stable\n");
	}else{
	    System.out.print("Not stable\n");
	}
	for(i=0; i<n; i++){
	    System.out.printf("%s %d\n", A[i].suit, A[i].value);
	    
	}
    }
    
    public static int partition(Card[] A, int n, int p, int r){
	int x, i, j;
	Card tmp;
	x = A[r].value;
	i = p-1;
	for(j=p; j<r; j++){
	    if(A[j].value<=x){
		i++;
		tmp = A[i]; A[i] = A[j]; A[j] = tmp;
	    }
	}
	tmp = A[i+1]; A[i+1] = A[r]; A[r] = tmp;
	return i+1;
    }

    public static void quickSort(Card[] A, int n, int p, int r){
	int q;
	if(p < r){
	    q = partition(A, n, p, r);
	    quickSort(A, n, p, q - 1);
	    quickSort(A, n, q + 1, r); 
	}
    }
    static boolean isStable(Card[] A){
	for(int i = 0; i < A.length; i++){
	    for(int j = i + 1; j < A.length; j++){
		if(A[i].value == A[j].value && A[i].index > A[j].index)
		    return false;
	    }
	}
    return true;
    }	    
}

Measured memory_bytes: 132440
#include <stdio.h>
#include <string.h>
int main(void) {
  int n,tmp,max,min;
  long long sum;
  scanf("%d",&n);
  fflush(stdin);
  scanf("%d",&tmp);
  sum=max=min=tmp;
  while(--n>0){
    scanf("%d",&tmp);
    sum+=tmp;
    max=max<tmp?tmp:max;
    min=min>tmp?tmp:min;
  }
  printf("%d %d %ld\n",min,max,sum);
  return 0;
}

Measured memory_bytes: 604
#include<stdio.h>

int n;
int A[1000];

int solve(int i,int m){
	if(m == 0)return 1;
	if(i >= n)return 0;
	int res = solve(i + 1,m)||solve(i + 1,m - A[i]);
	return res;
}

int main(){
	int q,M,i;
	scanf("%d",&n);
	for(i=0;i<n;i++)scanf("%d",&A[i]);
	scanf("%d",&q);
	for(i=0;i<q;i++){
		scanf("%d",&M);
		if(solve(0,M))printf("yes\n");
		else printf("no\n");
	}
	return 0;
}


Measured memory_bytes: 2140