akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;

namespace MyProject
{
    class Program
    {
        static void Main(string[] args)
        {
#if Local
            var sw = new Stopwatch();
            sw.Start();
            Console.SetIn(new StreamReader("input.in"));
#endif

            var solver = new Solver();
            solver.Solve();
#if Local
            Console.WriteLine($"{sw.ElapsedMilliseconds}ms");
#endif
        }
    }

    class Solver
    {
        private int N;
        private int M;
        private int Q;
        private List<QueryItem> queries = new List<QueryItem>();

        private IEnumerable<IReadOnlyList<int>> CreateSequences(IReadOnlyList<int> currentSequence)
        {
            if (currentSequence.Count() == this.N)
            {
                yield return currentSequence;
            }
            else
            {
                var start = currentSequence.Count() > 0 ? currentSequence.Last() : 1;
                foreach (var num in Enumerable.Range(start, this.M - start + 1))
                {
                    var next = new List<int>(currentSequence);
                    next.Add(num);
                    foreach (var sequence in this.CreateSequences(next))
                    {
                        yield return sequence;
                    }
                }
            }
        }

        public void Solve()
        {
            // 入力
            var items = Console.ReadLine().Split().Select(elem => int.Parse(elem)).ToArray();
            this.N = items[0];
            this.M = items[1];
            this.Q = items[2];
            foreach (var i in Enumerable.Range(0, Q))
            {
                var items2 = Console.ReadLine().Split().Select(elem => int.Parse(elem)).ToArray();
                var a = items2[0];
                var b = items2[1];
                var c = items2[2];
                var d = items2[3];
                this.queries.Add(new QueryItem { a = a, b = b, c = c, d = d });
            }

            // 計算
            var answer = 0L;
            foreach (var sequence in this.CreateSequences(new List<int>()))
            {
                var score = 0;
                foreach (var query in queries)
                {
                    if (sequence[query.b - 1] - sequence[query.a - 1] == query.c)
                    {
                        score += query.d;
                    }
                }

                answer = Math.Max(answer, score);
            }

            Console.WriteLine(answer.ToString());
        }

        public class QueryItem
        {
            public int a { get; set; }
            public int b { get; set; }
            public int c { get; set; }
            public int d { get; set; }
        }
    }
}


Measured memory_bytes: 46972
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		
		String n  = sc.next();
		
		if( n.contains("7")) {
			System.out.println("Yes");
		}else {
			System.out.println("No");

		}
	}
	
	
}


Measured memory_bytes: 27004
#include<bits/stdc++.h>
#include<time.h>
#include<cctype>
#include<iostream>
#include<ostream>
#include<cstdio>
#include<algorithm>
#include<iomanip>
#include<cstring>
#include<string>
#include<cmath>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
const int inf=0x3f3f3f3f;//1061109567
const int INF=0x7fffffff;//2147483647
const int SUP=0x80000000;//-2147483648
#define MAX 1000000
int main()
{
    ll a[MAX]={0},b[MAX]={0};
    int n;
    ll sum=0;
    ll t;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>t;
        if(i+t<=n)a[i+t]++;
        if(i-t>=1)b[i-t]++;
    }
    for(int i=1;i<=n;i++)
            sum+=a[i]*b[i];
    cout<<sum;
    return 0;
}


Measured memory_bytes: 19260
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
  ll A,B;
  cin>>A>>B;
  if(A==B) cout<<"Draw"<<endl;
  else if((A>B&&B!=1)||A==1) cout<<"Alice"<<endl;
  else cout<<"Bob"<<endl;
  return 0;
}
	


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	int is = 0;
	int h=0, m=0, s=0;

	scanf("%d", &is);
	
	h = is / 3600;
	m = (is - ( h * 3600)) / 60;
	s = is % 60;

	printf("%d:%d:%d\n", h, m, s);
}



Measured memory_bytes: 2748
#include<bits/stdc++.h>
#define int long long
constexpr long long mod = 1000000007;
#define for0(i, n) for(int i = 0; i < (n); i++)
#define for1(i, n) for(int i = 1; i <= (n);i++)
#define puts(x) cout << x << "\n"
using namespace std;
int f1(int a, int p) {
	if (p == 1)return a;
	if (p % 2)return f1(a, p - 1) * a % mod;
	else return f1(a * a % mod, p / 2) % mod;
}
int n, a[10100], k[1010], ans, a1, K = 1;
set<int>s1;
signed main() {
	cin >> n;
	for1(i, n) {
		cin >> a[i]; a1 = a[i];
		for (int p = 2; p <= 997; p++) {
			int cnt = 0;
			while (a1 % p == 0) { cnt++; a1 /= p; }
			k[p] = max(k[p], cnt);
		}
		if (a1 > 1)s1.insert(a1);
	}
	for (int p = 2; p <= 997; p++)for0(valsqotch, k[p]) { K *= p; if (K > mod)K %= mod; }
	for (int p : s1) { K = K * p % mod; }
	for1(i, n) {
		a1 = a[i]; int e = K;
		for (int p = 2; p <= 997; p++)while (a1 % p == 0) {
			e *= f1(p, mod - 2); if (e > mod)e %= mod;
			a1 /= p;
		}
		if (a1 > 1)e *= f1(a1, mod - 2); if (e > mod)e %= mod;
		ans += e; ans %= mod;
	}
	puts(ans);
}

Measured memory_bytes: 4132
#include <bits/stdc++.h>
#define ll long long
#define mk make_pair
using namespace std;
const int N = 4e4 + 5;
int n, m, cnt; 
struct line {
	long double a, b, c;
	line() {}
	void input() {
		scanf("%LF %LF %LF", &a, &b, &c);
	}
	long double calx(long double x) {
		return (c - a * x) / b;
	}
	long double caly(long double y) {
		return (c - b * y) / a;
	}
	bool operator < (const line &l) const {
		return a / -b < l.a / -l.b;
	}
} L[N];
bool cmp(line A, line B) {
	return A.b / -A.a < B.b / -B.a;
} 
long double V[N];
int B[N];
inline void Ins(int x) {
	if (x <= 0) return;
	while (x <= n) {
		++B[x];
		x += x & -x;
	}
}
inline int Query(int x) {
	int res = 0;
	while (x) {
		res += B[x];
		x -= x & -x;
	}
	return res;
}
int check(long double x) {
	int res = 0;
	for (int i = 0; i <= n; i++) B[i] = 0;
	for (int i = 1; i <= n; i++) V[i] = L[i].calx(x);
	sort(V + 1, V + 1 + n);
	m = unique(V + 1, V + 1 + n) - V - 1;
	for (int i = 1; i <= n; i++) {
		int p = lower_bound(V + 1, V + 1 + m, (L[i].calx(x))) - V;
		res += Query(p);
		Ins(p);
	} 
	return res;
}
int check1(long double y) {
	int res = 0;
	for (int i = 0; i <= n; i++) B[i] = 0;
	for (int i = 1; i <= n; i++) V[i] = L[i].caly(y);
	sort(V + 1, V + 1 + n);
	m = unique(V + 1, V + 1 + n) - V - 1;
	for (int i = 1; i <= n; i++) {
		int p = lower_bound(V + 1, V + 1 + m, (L[i].caly(y))) - V;
		res += Query(p);
		Ins(p);
	} 
	return res;
}
int main() {
	cin >> n;
	cnt = n * (n - 1) / 2;
	cnt = (cnt + 1) / 2;
	for (int i = 1; i <= n; i++) 
		L[i].input();
	sort(L + 1, L + 1 + n);
	long double mid, l = -2e8, r = 2e8;
	while (r - l > 1e-10) {
		mid = (l + r) / 2;
		if (check(mid) >= cnt)
			r = mid;
		else
			l = mid;
	}
	printf("%.13f ", (double)l);
	sort(L + 1, L + 1 + n, cmp);
	l = -2e8, r = 2e8;
	while (r - l > 1e-10) {
		mid = (l + r) / 2;
		if (check1(mid) >= cnt)
			r = mid;
		else
			l = mid;
	}
	printf("%.13f ", (double)l);
}

Measured memory_bytes: 3072
#include <iostream>
#include <list>
#include <algorithm>

using namespace std;

int main(int, char**)
{
	unsigned int h, w, n;
	list<int> d;
	std::cin >> n >> h >> w;


	cout << (n - h + 1)*(n - w + 1) << endl;
	return 0;
}


Measured memory_bytes: 256
N = int(input())
dp = dict()

dp[0] = 0
for n in range(1, N+1):
  ans = dp[n-1] + 1
  
  # メモ化
  x = 6
  while x <= n:
    ans = min(ans, dp[n-x]+1)
    x *= 6
  
  x = 9
  while x <= n:
    ans = min(ans, dp[n-x]+1)
    x *= 9
    
  dp[n] = ans
  
print(dp[N])

Measured memory_bytes: 15072
#include <iostream>
#include <string> 
#include <cmath>
using namespace std;

int compStr(int m, int n);

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

    int a, b;
    cin >> a >> b;

    if (a > b){
        cout << compStr(b, a) << "\n";
    }
    else {
        cout << compStr(a, b) << "\n";
    }

    return 0;
}

int compStr(int m, int n) {
    int x = 0;
    for (int i = 0; i < n; ++i){
        x += pow(10, i) * m;
    }
    return x;
}

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

int main(){
  double n;
  cin >> n;
  vector<double> a(n);
  vector<double> b(n);
  double c = 0;
  for(int i = 0; i < n; i++){
    cin >> a.at(i);
    b.at(i) = 1 / a.at(i);
    c += b.at(i);
  }
  /*printf("%.6f", 1 / c);*/
  cout << 1 / c << endl;
}



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

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

	cin >> a >> c >> b;
	
	if (c == '+')
	{
		cout << a + b << endl;
	}
	else if(c == '-')
	{
		cout << a - b << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <iostream>

const int N_MAX = 1e5 + 5;
using namespace std;

int score[N_MAX];

int main() {
    int N, K, Q;

    int a;
    cin >> N >> K >> Q;
    for (int i = 0; i < Q; ++i) {
        cin >> a;
        ++score[--a];
    }

    for (int i = 0; i < N; ++i) {
        if (K - (Q - score[i]) > 0) {
            cout << "Yes";
        } else {
            cout << "No";
        }
        cout << endl;
    }
}

Measured memory_bytes: 1024
S = gets.chomp
N = S.size
a = [1] * N

S.gsub!(/RL/,"Z")
zhash = Hash.new([1,1])
r_lists = Hash.new(0)
l_lists = Hash.new(0)
z_position = -1
for i in 0...(S.size) do
    if S[i] == "R"
        r_lists[i%2] += 1
    elsif S[i] == "Z"
        z_position = i
        rv,lv = zhash[i]
        if i%2 == 0
            zhash[i] = [rv + r_lists[0], lv + r_lists[1]]
        else
            zhash[i] = [rv + r_lists[1], lv + r_lists[0]]
        end
        r_lists = Hash.new(0)
    elsif S[i] == "L"
        rv,lv = zhash[z_position]
        if z_position%2 == i%2
            zhash[z_position] = [rv, lv + 1]
        else
            zhash[z_position] = [rv + 1, lv]
        end
    end
end

ans = []
for i in 0...(S.size) do
    if S[i] == "Z"
        a,b = zhash[i]
        ans.push(a)
        ans.push(b)
    else
        ans.push(0)
    end
end

puts ans.join(" ")

=begin
def simu(a)
    tmp = a.dup
    for i in 0...N do
        if S[i] == "R"
            a[i]   -= tmp[i]
            a[i+1] += tmp[i]
        else
            a[i]   -= tmp[i]
            a[i-1] += tmp[i]
        end
    end
    p a
end

p a
simu(a)
simu(a)
simu(a)
simu(a)
simu(a)
simu(a)
simu(a)
=end

Measured memory_bytes: 13180
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const  ll INF = 1e18;
const  ll MOD = 1e9 + 7;
#define all(v) v.begin(), v.end()
#define repi(i,n,init) for(ll i=init;i<(n);i++)
#define repd(i,n,init) for(ll i=(n);i>=init;i--)
#define repm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define repb(bit,n,init) for(ll bit=init;bit<(1<<n);++bit)

int main()
{
    int n;
    cin >> n;
    ll ans = 0;
    repi(i,n+1,1){
        if(i % 3 == 0){
            continue;
        }
        if(i % 5 == 0){
            continue;
        }
        ans += i;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <algorithm>
#include <array>
#include <bitset>
#include <deque>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
//region cp_helper
using namespace std;
#define _io ios_base::sync_with_stdio(false); cin.tie(nullptr);
#define ll long long
#define ull unsigned long long
#define ii pair<int, int>
#define vi vector<int>
#define vvi vector< vector<int> >
#define vll vector<ll>
#define vii vector<ii>
#define in(n) cin >> n
#define out(n) cout << n
#define outs(n) cout << n << ' '
#define outn(n) cout << n << '\n'
#define vin(a, n) for (int i=0; i<n; i++) in(a[i])
#define vout(a) for (auto i : a) outs(i)
#define all(a) a.begin(), a.end()
#define qsort(a) sort(all(a))
#define qdsort(a) sort(all(a), greater<>())
const int mod = (int)(1e9) + 7;
//endregion

using namespace std;

int main() { _io
    int n;
    in(n);
    vector<string> arr(n);
    for (int i=0; i<n; i++) {
        in(arr[i]);
        qsort(arr[i]);
    }
    qsort(arr);
    ll total=0, temp=0;
    for (int i=1; i<n; i++) {
        if (arr[i-1] == arr[i]) temp++;
        else {
            total += temp * (temp+1) / 2;
            temp = 0;
        }
    }
    total += temp * (temp+1) / 2;
    out(total);
}



Measured memory_bytes: 5760
#include "bits/stdc++.h"
using namespace std;
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2610&lang=jp
int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	int n; cin >> n;
	if (n == 0) cout << 1 << endl;
	else if (n == 1) cout << 2 << endl;
	else if (n == 2)cout << 1 << endl;
	else cout << 0 << endl;
}

Measured memory_bytes: 3124
#include<iostream>
#include<cmath>
#define ll long long int
using namespace std;

void solve();

int main() {

   solve();

   return 0;
}

void solve() {
   char c=' ';
   int a[3];

   cin >> a[0] >> a[1] >> a[2];

   if (a[1] > a[2]) {

      swap(a[1],a[2]);

   }

   if (a[0] > a[1]) {

      swap(a[0],a[1]);

   }

   if (a[1] > a[2]) {

      swap(a[1], a[2]);

   }

   

   cout << a[0] << c << a[1] << c << a[2] << endl;

}

Measured memory_bytes: 3084
//#include "debug.h"
#include <string.h>
#include <limits.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
using namespace std;

#define MAXN 200000
typedef long long i64;

int n;
char s[10001];
int input() {
	if (scanf("%d", &n) < 0) return 0;
	scanf("%s",s);
	return 1;
}

void init() {
}

int solve() {
	for (int i=0; s[i]; i++)
		s[i] = 'A' + (s[i]-'A'+n) % 26;
	return 1;
}

void output(int ans) {
	printf("%s\n", s);
}

void cleanup() {
}

int main() {
	//precalc();
	//int ca; scanf("%d", &ca);
	while (input()) {
		init();
		output(solve());
		cleanup();
		//break;
	}
}




Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,k;
	cin>>k>>n;
	long long sum=0,cpy=0,prv=0;
	vector<int>nums(n);
	int index=0,mx=0,mxx=0,mn=1e9;
	
	for(int i=0;i<n;++i)
	{
		cin>>nums[i];
		int tmp=nums[i];
		mxx=max(mxx,nums[i]);
		mn=min(mn,nums[i]);
		nums[i]-=prv;
		prv=tmp;
		sum+=nums[i];
		if(nums[i]>mx && i>0){
			index=i;
			mx=nums[i];
		}
	}
	sum-=mn;
	for(int i=index+1;i<n;++i)
	{
		cpy+=nums[i];
	}
	cpy+=(k-mxx);
	for(int i=index-1;i>=0;--i)cpy+=nums[i];
	cout<<min(cpy,sum);
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
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; }
template<typename T>
vector<T> table(int n, T v) { return vector<T>(n, v); }

template <class... Args>
auto table(int n, Args... args) {
    auto val = table(args...);
    return vector<decltype(val)>(n, move(val));
}
const ll INF = 1000000000000000;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;
const ll MAX = 200005;
ll RepeatSquaring(ll N, ll P, ll M){
    if(P==0) return 1;
    if(P%2==0){
        ll t = RepeatSquaring(N, P/2, M);
        return t*t % M;
    }
    return N * RepeatSquaring(N, P-1, M);
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,p;
    string s;
    cin >> n >> p >> s;
    if (p == 2 || p == 5){
        ll cnt = 0;
        rep(i,n){
            if ((s[n-i-1]-'0')%p == 0) cnt += n-i;
        }
        PRINT(cnt);
        return 0;
    }
    ll a = 0;
    ll m[p] = {0};
    rep(i,n){
        a += (s[n-i-1]-'0')*RepeatSquaring(10,i,p)%p;
        a %= p;
        m[a]++;
    }
    m[0]++;
    ll ans = 0;
    rep(i,p){
        ans += m[i]*(m[i]-1)/2;
    }
    PRINT(ans);
}


Measured memory_bytes: 720
import java.util.*;

class Main
{
    static final int N = 8;
    static int[]r = new int[N];
    static int[]c = new int[N];
    static int[]dp = new int[2 * N - 1];
    static int[]dn = new int[2 * N - 1];

    static boolean[][]X = new boolean[N][N];

    public static void initialize()
    {
        for(int i = 0; i < r.length; i++)
            {
                r[i] = -1;
                c[i] = -1;
            }

        for(int i = 0; i < dp.length; i++)
            {
                dp[i] = -1;
                dn[i] = -1;
            }
    }

    public static void print()
    {
        Scanner In = new Scanner(System.in);

         for(int i = 0; i < N; i++)
            {
                for(int j = 0; j < N; j++)
                    {
                        if(X[i][j])
                            {
                                if(r[i] != j)
                                    return;
                            }
                    }
            }

        for(int i = 0; i < N; i++)
            {
                for(int j = 0; j < N; j++)
                    {
                        if(r[i] == j)
                            System.out.print("Q");
                        else
                            System.out.print(".");
                    }
                System.out.println();
            }
    }

    public static void recu(int i)
    {
        if(i == N)
            {
                print();
                return;
            }

        for(int j = 0; j < N; j++)
            {
                if(c[j] == 1 || dp[i + j] == 1 || dn[i - j + N - 1] == 1)
                    continue;

                r[i] = j;
                c[j] = dp[i + j] = dn[i - j + N - 1] = 1;

                recu(i + 1);

                r[i] = c[j] = dp[i + j] = dn[i - j + N - 1] = -1;
            }
    }

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

        initialize();

        for(int i = 0; i < N; i++)
            for(int j = 0; j < N; j++) X[i][j] = false;

        int k = In.nextInt();

        for(int i = 0; i < k; i++)
            {
                int ro = In.nextInt();
                int co = In.nextInt();
                X[ro][co] = true;
            }

        recu(0);
    }
}

Measured memory_bytes: 27716
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define rush() int T;scanf("%d",&T);while(T--)
#define mm(a,b) memset(a,b,sizeof(a))
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define sc(a) scanf("%d",&a)
#define sc2(a,b) scanf("%d%d",&a,&b)
#define pf(a) printf("%d\n",a)
#define pf2(a,b) printf("%d %d\n",a,b)
#define p_f(a) printf("%d ",a)
#define fi first
#define se second
#define db double
#define ll long long
using namespace std;
const int inf=0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f3f;
const db eps=1e-9;
map<string,int>m;
int main()
{
    m["SUN"]=0;
	m["MON"]=1;
	m["TUE"]=2;
	m["WED"]=3;
	m["THU"]=4;
	m["FRI"]=5;
	m["SAT"]=6;
	string s;
	cin>>s;
	int t=m[s];
	cout<<7-t<<endl;
    return 0;
}


Measured memory_bytes: 256
x1, y1, x2, y2 = tuple(int(i) for i in input().split())

vx, vy = x2-x1, y2-y1

x3, y3 = x2 - vy, y2 + vx
x4, y4 = x3- vx, y3 - vy

print(x3, y3, x4, y4)

Measured memory_bytes: 2940
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>

using namespace std;

using ll = long long int;

pair<int, int> arr[100010];

int main() {

	ll n, m;
	cin >> n >> m;

	for (int i = 0; i < n; i++) {
		int a, b;
		cin >> a >> b;

		arr[i].first = a;
		arr[i].second = b;
	}

	sort(arr, arr + n);

	int result = 0;
	while (m > 0) {

		//cout << m << endl;
		m -= arr[result].second;
		result++;

	}
	cout << arr[result - 1].first << endl;

}

Measured memory_bytes: 1024
N,K=map(int,input().split())

R,S,P=map(int,input().split())
total=0
I=input()
count=0
T=list(I)
for i in range(N):
    if T[i]=='r':
        total+=P
    if T[i]=='s':
        total+=R
    if T[i]=='p':
        total+=S
for k in range(K):
    for i in range(count,N,K):
        if T[i-K]==T[i] and i>=K :
            if T[i] == 'r':
                total -= P
            if T[i] == 's':
                total -= R
            if T[i] == 'p':
                total -= S
            T[i]='Y'
    count+=1
#print(T)
print(total)

Measured memory_bytes: 49392
//Algorithms and Data Structures I - Graph II - Single Source Shortest Path I
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Scanner;

class Node implements Comparable<Node> {
	public  int     u,
		            k,
			        d = Integer.MAX_VALUE;
	public  int[][] adj;
	boolean S;

	Node(int u, int k) {
		this.u = u;
		this.k = k;
		adj    = new int[2][k];
	}

	public int compareTo(Node n) {
		return this.d - n.d;
	}
}

class Main {

	private static ArrayList<Node>       Q   = new ArrayList<Node>();
	private static HashMap<Integer,Node> map = new HashMap<Integer,Node>();

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		Node source = null,
			 nd;
		for(int i=0;i<n;i++){
			nd = new Node(sc.nextInt(), sc.nextInt());
			for (int j = 0; j < nd.k; j++) {
				nd.adj[0][j] = sc.nextInt();
				nd.adj[1][j] = sc.nextInt();
			}
			if (nd.u == 0) { nd.d   = 0 ;
			                 source = nd;}
			else           {Q.add(nd)   ;}
			map.put(nd.u, nd);
		}
		relax(source);

		while(!Q.isEmpty()){
			Collections.sort(Q);
			relax(Q.remove(0));
		}

		for(int i=0;i<n;i++){
			nd = map.get(i);
			System.out.println(nd.u+" "+nd.d);
		}
	}

	private static void relax(Node n){
		Node t;
		int  l;
		for(int i=0;i<n.k;i++){
			t = map.get(n.adj[0][i]);
			l = n.d+n.adj[1][i];
			if(!t.S && l<t.d){
				t.d=l;
			}
		}
		n.S = true;
	}
}

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

std::vector<int> a(5);
void input()
{
    for(int i=0;i<5;i++)std::cin>>a[i];
}

int main()
{
    input();
    int res = 10000000;
    do{
        int cur = 0;
        for(int i=0;i<5;i++){
            cur += a[i];
            if(i!=4&&cur%10)cur += 10,cur -= cur%10;
        }
        res = std::min(res,cur);
    }while(std::next_permutation(a.begin(),a.end()));
    std::cout<<res<<std::endl;

}

Measured memory_bytes: 256
import Control.Applicative((<$>))
import Control.Monad
import Data.Map ((!))
import qualified Data.Map as M
-- import Data.IntMap ((!))
-- import qualified Data.IntMap as M
import qualified Data.List as L
import Data.Maybe (catMaybes)
-- import qualified Data.Char as C
-- import qualified Data.IntSet as I
import Debug.Trace
--------------------------------------------
readInt    = read :: String -> Int
getInt     = readInt <$> getLine
getIntList = map readInt . words <$> getLine
int2bin 0 =  []
int2bin n =  n `mod` 2 : int2bin (n `div` 2)
----------------------------------------------

-- hoge n =
--   if length (show n) == 3 then show n
--   else if length (show n) == 2 then "0" ++ show n
--   else "00" ++ show n


main :: IO ()
main = do
  n <- getInt
  putStrLn $ if n <= 999 then "ABC" else "ABD"


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

#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;i<n;i++)
#define ll long long
 
#define pi pair < ll , ll >
#define pb push_back
#define mp make_pair
#define F first
#define S second
 
#define fastIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
 
#define debug(x) cout<<#x<<" :: "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n";
using namespace std;

void solve() {
    ll n, m, a[3], b[3], i, j, k, poss = 1;
    fo(i,3)b[i]=0;
    cin>>n>>m;
    if(n==1) {
        fo(i,m) {
            cin>>j>>k;
            if(b[j-1]==1 and a[j-1]!=k) {
                poss = 0;break;
            }
            b[j-1] = 1;
            a[j-1] = k;
        }
        if(poss==0){cout<<-1;return;}
        else if(b[0]==0)cout<<0;
        else cout<<a[0];
        return;
    }
    if(n==2) {
        fo(i,m) {
            cin>>j>>k;
            if(j==1 and k==0) {
                poss = 0;break;
            }
            if(b[j-1]==1 and a[j-1]!=k) {
                poss = 0;break;
            }
            b[j-1] = 1;
            a[j-1] = k;
        }
        if(poss==0){cout<<-1;return;}
        else {
            if(b[0]==0)a[0]=1;
            if(b[1]==0)a[1]=0;
        }
        cout<<a[0]<<a[1];
        return;
    }
    fo(i,m) {
        cin>>j>>k;
        if(j==1 and k==0) {
            poss = 0;break;
        }
        if(b[j-1]==1 and a[j-1]!=k) {
            poss = 0;break;
        }
        b[j-1] = 1;
        a[j-1] = k;
    }
    if(poss==0){cout<<-1;return;}
    else {
        if(b[0]==0)a[0]=1;
        if(b[1]==0)a[1]=0;
        if(b[2]==0)a[2]=0;
    }
    cout<<a[0]<<a[1]<<a[2];
}

int main()
{
    ll t = 1;
    // cin>>t;
    while(t--) {
        solve();
    }
}

Measured memory_bytes: 256
#include <stdio.h>
int main(int argc, char *argv[]){
	int A, B, K;
	int i;
	scanf("%d %d %d", &A, &B, &K);
	if(A+K-1<B-K+1){
		for(i=A; i<A+K; i++) printf("%d\n", i);
		for(i=B-K+1; i<=B; i++) printf("%d\n", i);
	} else {
		for(i=A; i<=B; i++) printf("%d\n", i);
	}
	return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <queue>
#include <map>

using namespace std;

int main(int argc, char *argv[])
{

  int a[5], k;
  for (int i = 0; i < 5; i++) {
    cin >> a[i];
  }
  cin >> k;

  for (int i = 0; i < 5; i++) {
    for (int j = 0; j < 5; j++) {
      if (abs(a[i]-a[j]) > k) {
        cout << ":(" << endl;
        return 0;
      }
    }
  }

  cout << "Yay!" << endl;
 }


Measured memory_bytes: 256
#include<stdio.h>
    #include<string.h>
    int judgestr(char str[],int len)
    {
      int i,n;
      for(n = 0;n<len-1;n++)
        for(i=n+1;i<len;i++)
          if(str[n] - str[i] == 0)
            return 1;
      return 0;
    }
     
    int main()
    {
      char str[27];
      fgets(str,27,stdin);
      if(str[strlen(str)-1] == '\n')
        str[strlen(str)-1] = '\0';
      if(judgestr(str,strlen(str)) == 0)
        printf("yes\n");
      else
        printf("no\n");
      return 0;
    }

Measured memory_bytes: 128
#include <stdio.h>
#include <limits.h>

int main(){
  long n, m;
  long ans;

  scanf("%ld\t%ld", &n, &m);

  if(n==1 && m==1){ ans=1; }
  else if(n==1){    ans=m-2; }
  else if(m==1){    ans=n-2; }
  else{             ans=(n-2)*(m-2); }

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

  return 0;

}


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

typedef long long ll;
typedef pair<ll,ll> ii;
typedef long double ld;
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ALL(x) x.begin(),x.end()
#define SZ(x) (int)x.size()
const int INF=2012345678;
const ll LLINF=4012345678012345678LL;
const ll MOD=1000000007; //998244353; //
const ld PI=3.1415926535898;
const ld EPS=1e-9;
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(b==0)return a;return gcd(b,a%b);}
inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
inline ll expo(ll b,ll p,ll m){ll res=1; while(p){if(p&1)res=(res*b)%m; b=(b*b)%m; p>>=1;} return res;}
inline ll modinv(ll a,ll m){return expo(a,m-2,m);}

int main(){
	ll a;ld b;
	scanf("%lld%Lf",&a,&b);
	printf("%lld",(ll)floor(a*b));
}


Measured memory_bytes: 3836
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <iomanip>
#include <climits>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<PII> VPI;
typedef vector<PLL> VPL;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define pf push_front
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ub upper_bound
#define lb lower_bound

int main(){
  int N;
  cin>>N;
  VL A(N);
  rep(i,N) cin>>A[i];
  int Q;
  cin>>Q;
  VL B(Q),C(Q);
  rep(i,Q) cin>>B[i]>>C[i];
  ll sum=0;
  rep(i,N) sum+=A[i];
  VL X(100001);
  rep(i,N) X[A[i]]++;
  rep(i,Q){
    if(X[B[i]]){
      sum-=X[B[i]]*B[i];
      sum+=X[B[i]]*C[i];
      X[C[i]]+=X[B[i]];
      X[B[i]]=0;
    }
    cout<<sum<<endl;
  }
}


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

int main(){
  int n; cin>>n;
  int ans=n;
  for(int i=0;i<=n;i++){
    int s=i, t=n-i, c=0;
    while(s>0){
      c+=s%6;
      s/=6;
    }
    while(t>0){
      c+=t%9;
      t/=9;
    }
    ans=min(ans, c);
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ul;
typedef signed long long ll;
ul over = 1000000007;

mt19937 mt(time(nullptr));
// uniform_int_distribution< int > rand_int(0, 10) // rand[0, 10] inclusive

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed;
  ul n, m;
  cin >> n >> m;
  vector< ul > a(n);
  for (int i=0; i<n; ++i) cin >> a[i];
  vector< tuple< ul, ul > > b(m);
  for (int i=0; i<m; ++i) {
    ul bi, ci;
    cin >> bi >> ci;
    b.push_back(make_tuple(ci, bi));
  }

  sort(a.begin(), a.end());
  sort(b.begin(), b.end());

  ul bi = b.size()-1;
  for (int i=0; i<n; ++i) {
    ul bb = get<1>(b[bi]);
    ul cc = get<0>(b[bi]);
    if (a[i] >= cc) continue;
    a[i] = cc;
    bb--;
    b[bi] = make_tuple(cc, bb);
    if (bb == 0) bi--;
    if (bi < 0) break;
  }
  ul ans = 0;
  for (int i=0; i<n; ++i) ans += a[i];
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 5120
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (true) {
            int H = sc.nextInt();
            int W = sc.nextInt();
            if (H == 0 && W == 0) {
                break;
            }

            for (int h = 0; h < H; h++) {
                for (int w = 0; w < W; w++) {
                    if (w != (W - 1)) {
                        System.out.print("#");
                    } else if (w == (W - 1)) {
                        System.out.println("#");

                    }
                }
            }
            System.out.println();
        }
    }
}



Measured memory_bytes: 33104
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include<stdio.h>
#include<string.h>
typedef struct {
	int s;
}DATA;
int main() {
	int point[31] = { 0 },p,s,cnt,i;
	DATA data[101] = { 0 };
	while (1) {
		fscanf(stdin, "%d,%d", &p, &s);
		if (!p && !s) break;
		point[s]++, data[p].s = s;
	}
	while (~fscanf(stdin, "%d", &p)) {
		cnt = 0;
		for (i = 30; i > data[p].s; --i) if(point[i]!=0) cnt++;
		fprintf(stdout, "%d\n", cnt + 1);
	}
	return 0;
}

Measured memory_bytes: 604
package main

import (
	"bufio"
	"fmt"
	"io"
	"log"
	"os"
	"strconv"
)

func main() {
	s := readBytes()
	front := s[:len(s)/2]
	back := s[len(s)/2:]
	if len(s)%2 == 1 {
		back = s[len(s)/2+1:]
	}

	ans := 0
	for i := range front {
		if front[i] != back[len(back)-i-1] {
			ans++
		}
	}

	fmt.Println(ans)
}

// sort ------------------------------------------------------------

type xxx struct {
	x int
}

type sortArray []xxx

func (s sortArray) Len() int           { return len(s) }
func (s sortArray) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
func (s sortArray) Less(i, j int) bool { return s[i].x < s[j].x }

// -----------------------------------------------------------------

var (
	readString func() string
	readBytes  func() []byte
)

func init() {
	log.SetFlags(log.Lshortfile)
	readString, readBytes = newReadString(os.Stdin)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Bytes()
	}
	return f1, f2
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

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

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func sum(a []int) int {
	var ret int
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumFloat64(a []float64) float64 {
	var ret float64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func gcd(m, n int) int {
	for m%n != 0 {
		m, n = n, m%n
	}
	return n
}

func lcm(m, n int) int {
	return m / gcd(m, n) * n
}


Measured memory_bytes: 640
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
using namespace std;
typedef long long ll;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int INF = 0x3f3f3f3f3f;
const int maxn = 1e5+500;
ll T,n,m;
int a[10][2] ={{4,22},{6,23},{6,32},{8,24},{9,23},{10,25},{12,26},{12,34},{14,27},{15,35}};
int main() {
    cin>>n>>m;
    int cnt = 0;
    for(int i=1;i<n+1;i++){
    	for(int j=1;j<=m;j++){
    		int x = j/10;
    		int y = j%10;
    		if(x>=2&&y>=2&&x*y==i)
    			cnt++;
		}
	}
	cout<<cnt<<endl;
    return 0;
}



Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std; typedef long long int lint; typedef pair<lint, lint> plint; typedef pair<double long, double long> pld;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define FOR(i, begin, end) for(lint i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(lint i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define endk '\n'
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; }
const lint mod = 1e9 + 7, INF = 1e18;
lint dx[8] = { 0, -1, 1, 0, 1, -1, 1, -1 }, dy[8] = { 1, 0, 0, -1, -1, -1, 1, 1 };

lint N, K;
lint X[100000], Y[100000];
char c;
lint dp[2001][2001];

int main() {
	cin.tie(0); ios_base::sync_with_stdio(false);
	cin >> N >> K;
	REP(i, N) {
		cin >> X[i] >> Y[i] >> c;
		if (c == 'B') Y[i] += K;
		X[i] %= 2 * K;
		Y[i] %= 2 * K;
	}
	REP(i, N) {
		dp[X[i] + 1][Y[i] + 1]++;
	}
	REP(i, 2 * K + 1) {
		REP(j, 2 * K) {
			dp[i][j + 1] += dp[i][j];
		}
	}
	REP(j, 2 * K + 1) {
		REP(i, 2 * K) {
			dp[i + 1][j] += dp[i][j];
		}
	}
	lint maxv = 0;
	REP(i, K + 1) {
		REP(j, K + 1) {
			lint curr = 0;
			curr += dp[i][j];
			curr += dp[i][2 * K] - dp[i][j + K];
			curr += dp[2 * K][j] - dp[i + K][j];
			curr += dp[i + K][j + K] - dp[i][j + K] - dp[i + K][j] + dp[i][j];
			curr += dp[2 * K][2 * K] - dp[2 * K][j + K] - dp[i + K][2 * K] + dp[i + K][j + K];
			chmax(maxv, max(N - curr, curr));
		}
	}
	cout << maxv << endl;
}

Measured memory_bytes: 36492
#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 FOR(i,m,n) for(int i=m;i<n;++i)
#define RFOR(i,m,n) for(int i=n-1;i>=m;--i)
#define ALL(v) v.begin(),v.end()
#define PB(a) push_back(a)
#define INF 1000000001
#define MOD 1000000007
#define EPS 1e-9

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

typedef long long ll;
using namespace std;


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n;
	ll sum = 0;
	cin >> n;
	vector<ll> v(n);
	REP(i, n) {
		cin >> v[i];
		sum += v[i];
	}
	if (sum % (n*(n + 1) / 2) != 0) {
		cout << "NO" << endl;
		return 0;
	}
	ll k = sum / (n*(n + 1) / 2);
	vector<ll> dif(n);
	REP(i, n) dif[i] = v[(i+n-1)%n ] - v[i] + k;
	ll cnt = 0;
	REP(i, n) {
		if (dif[i] < 0) {
			cout << "NO" << endl;
			return 0;
		}
		else if (dif[i]%n ==0)cnt+=dif[i]/n;
		else {
			cout << "NO" << endl;
			return 0;
		}
	}
	if (cnt != k) cout << "NO" << endl;
	else cout << "YES" << endl;

	return 0;
}


Measured memory_bytes: 1792
H,W = [int(hoge) for hoge in input().split()]
A = [input() for j in range(H)]
Row = [r for r in range(H) if all([m=="." for m in A[r]]) ]
Col = [c for c in range(W) if all([A[r][c]=="." for r in range(H)])]
print(*["".join([A[h][w]for w in range(W) if w not in Col]) for h in range(H) if h not in Row],sep="\n")

Measured memory_bytes: 39664
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;




//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)




int main() {
	int n, Y;
	cin >> n >> Y;


	REP(i, Y / 10000 + 1)
	{
		int x = 10000 * i;

		//if (i > n) break;
		REP(j, Y / 5000 + 1)
		{
			int y = 5000 * j;
			int z = 1000 * (n - i - j);
			if (z < 0) break;

			//cout << x << " " << y << " " << z << endl;
			if (x + y + z == Y) {
				cout << i << " " << j << " " << n - i - j << endl;
				return 0;
			}

		}
	}

	cout << "-1 -1 -1" << endl;



	return 0;
}



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

using namespace std;

const int mx = 1e3 + 9;

int par[mx];
int dist[mx];
bitset <mx> mark;
vector <int> adj[mx];

int main() {
    int n, m; scanf("%d %d", &n, &m);
    for (int i = 0; i < m; i++) {
        int u, v; scanf("%d %d", &u, &v);
        adj[u].push_back(v);
    }

    int a = -1, b = -1;
    int len = max(n * n, m * m); 
    for (int s = 1; s <= n; s++) {
        mark = 0;
        memset(dist, 0, sizeof dist);
        mark[s] = 1;
        dist[s] = 1;
        queue <int> q;
        q.push(s);
        int t = -1;

        while (!q.empty() and t == -1) {
            auto u = q.front();
            q.pop();
            for (auto v : adj[u]) {
                if (v == s) {
                    t = u;
                    break;
                }
                if (mark[v]) continue;
                mark[v] = 1;
                dist[v] = 1 + dist[u];
                q.push(v);
            }
        }

        if (len > dist[t] and t != -1) {
            len = dist[t];
            a = s, b = t;
        }
    }

    if (a == -1) {
        puts("-1");
        return 0;
    }

    printf("%d\n", len);
    bool found = false;
    queue <int> q;
    q.push(a);
    mark = 0;
    mark[a] = 1;

    while (!q.empty()) {
        auto u = q.front(); q.pop();
        for (auto v : adj[u]) {
            if (mark[v]) continue;
            mark[v] = 1;
            par[v] = u;
            q.push(v);
            if (v == b) {
                found = true;
                break;
            }
        }

        if (found) break;
    }

    printf("%d\n", b);
    while (b != a) {
        b = par[b];
        printf("%d\n", b);
    }

    return 0;
}

Measured memory_bytes: 256
line1 = input().split()
n = int(line1[0])
k = int(line1[1])
list1 = []
for i in range(k):
  d = input()
  lst = input().split()
  list1 += lst

set1 = set(list1)
nothing = set(str(i+1) for i in range(n)) - set1
print(len(nothing))

Measured memory_bytes: 9512
//c
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
typedef pair<int, int> pii;

int N;

int solve(vector<pii> v){
	
	sort(v.begin(), v.end());
	
	int rl, rs = 0, ws = 0;
	bool dp[1010] = {0};
	
	rl = v[N-1].first;
	
	for(int i=0; i<N; ++i){
		rs += v[i].first;
		ws += v[i].second;
	}
	
	rs -= rl;
	
	if(rs >= rl){
		return rs + rl + ws;
	}
	
	dp[0] = true;
	
	for(int i = 0; i < N-1; ++i){
		for(int j=rl-rs; j >=0; --j){
			
			if( dp[j] && j + v[i].second <= rl - rs )
				dp[j + v[i].second] = true;
				
		}
	}
	
	int maxwrite = 0;
	
	for(int i = rl - rs; i >= 0; --i){
	
		if(dp[i])
			return 2*rl + ws - i;
	}
}

int main(){
	
	while(cin>>N, N){
		
		vector<pii> v;
		int r, w;
		
		for(int i=0; i<N; ++i){
			
			cin >> r >> w;
			v.push_back(make_pair(r, w));
		}
		
		cout << solve(v) << endl;
	}
	
	return 0;
}

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

using namespace std;
using ll = long long;

class UnionFind {
public:
  vector<int> par;
  UnionFind(int n) {
    par = vector<int>(n + 1);
    for (int i = 1; i <= n; i++) {
      par[i] = i;
    }
  }
  int root(int x) {
    if (par[x] == x) {
      return x;
    }
    return par[x] = root(par[x]);
  }
  void unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) {
      return;
    }
    par[x] = y;
  }
  bool same(int x, int y) {
    return root(x) == root(y);
  }
};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k, l;
  scanf("%d %d %d", &n, &k, &l);
  auto uf1 = UnionFind(n);
  auto uf2 = UnionFind(n);
  for (int i = 0; i < k; i++) {
    int p, q;
    scanf("%d %d", &p, &q);
    uf1.unite(p, q);
  }
  for (int i = 0; i < l; i++) {
    int r, s;
    scanf("%d %d", &r, &s);
    uf2.unite(r, s);
  }
  map<pair<int, int>, int> mp;
  for (int i = 1; i <= n; i++) {
    mp[make_pair(uf1.root(i), uf2.root(i))]++;
  }
  for (int i = 1; i <= n; i++) {
    if (i < n) {
      cout << mp[make_pair(uf1.root(i), uf2.root(i))] << " ";
    } else {
      cout << mp[make_pair(uf1.root(i), uf2.root(i))] << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 13568
#include<bits/stdc++.h>
#define INF 100000000
using namespace std;
int n,m[101][101],p[101];
void dp();

int main(){
  cin>>n;
  for(int i=0;i<n;i++)cin>>p[i-1]>>p[i];
  dp();
  cout<<m[1][n]<<endl;
   
  return 0;
}
void dp(){
  for(int l=2;l<=n;l++)
    for(int i=1;i<=n-l+1;i++){
     int j=i+l-1;
     m[i][j]=INF;
     for(int k=i;k<j;k++){
       int a=m[i][k]+m[k+1][j]+p[i-2]*p[k-1]*p[j-1];
       if(m[i][j]>a)m[i][j]=a;
     }
    } 
}



Measured memory_bytes: 3124
/*


               BASIC TEMPLATES


*/
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
//#pragma GCC target("avx,avx2")

#include<bits/stdc++.h>
#include<bits/stdc++.h>
using namespace std;

//#
//#  #
//#   #
//#    #
//#   # #
//#  #   ###
//#
#define ll long long
#define pb push_back
#define emb emplace_back
#define ff first
#define ss second
#define FAST cin.tie(0); ios_base::sync_with_stdio (false)
#define pii pair<int,int>
#define TEN6 1000000
#define TEN5 100000
#define TEN4 10000
#define TEN9 1000000000
#define ipv pair<ll,vector<ll> >
#define pll pair<ll,ll>
#define CASE(x) "Case "<<x<<": "
#define _endl "\n"


#define for_r(i,st,lim) for(ll i=st-1;i>=lim;i--)
#define fRead(x) freopen(x,"r",stdin)
#define fWrite(x) freopen (x,"w",stdout)
#define all_set(arr,val) memset(arr,val,sizeof(arr))
#define all(x) x.begin(),x.end()
#define for_(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

//lower_bound returns an iterator pointing to the first element in the range [first,last) which has a value not less than ‘val’.

//upper_bound returns an iterator pointing to the first element in the range [first,last) which has a value greater than ‘val’.
using namespace __gnu_pbds;
#define ordered_set tree<ll , null_type,less<ll  >, rb_tree_tag,tree_order_statistics_node_update>

#define MOD 998244353 ///////<<<<<<<<<<<<<<<<<<=====MOD value change here!!!!!
#define INF 5e18
#define what_is(x) cerr << #x << " is " << x << endl;

ll BMod(ll B,ll P,ll M)
{
    ll R=1;
    B=B%M;
    while(P)
    {
        if(P&1)
            R=(R*B)%M;
        P >>= 1;
        B=(B*B)%M;
    }
    return R;
}

ll invMOD(ll num,ll M)
{
    return BMod(num,M-2,M);
}


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);
}
ll my_abs(ll x)
{
    if(x<0)x*=-1;
    return x;
}

ll val[100+10];
ll wt[100+10];
ll n,w;
ll dp[TEN5 +10];
bool taken[TEN5 +10][102];
int main()
{
    //
    // FAST;

    cin>>n>>w;

    for_(i,0,n)
    {
        cin>>wt[i]>>val[i];
    }
    all_set(dp,-1);
    all_set(taken,0);
    dp[0]=0;

    for_(i,0,(TEN5) +1)
    {
        if(dp[i]==-1 )continue;
        for_(j,0,n)
        {

            if(taken[i][j]==0)
            {

                ll next = i+val[j];
                if(dp[i]+wt[j]>w)continue;
                if(dp[next]>dp[i]+wt[j] or dp[next]==-1)
                {
                    dp[next]=dp[i]+wt[j];
                    for_(k,0,n)
                    {
                        if(k==j)taken[next][k]=1;
                        else
                            taken[next][k]=taken[i][k];

                    }

                }

            }

        }
    }
    ll mx=0;
    for_(i,0,(TEN5) +1)
    {
        if(dp[i]!=-1)
        {
            mx=max(mx,(ll)i);
        }
    }
    cout<<mx<<_endl;


}

















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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

pll A[200005];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    vector<ll> t;
    REP(i, N) {
        cin >> A[i].first >> A[i].second;
        t.push_back(A[i].first);
        t.push_back(A[i].second);
    }
    sort(t.begin(), t.end());
    t.erase(unique(t.begin(), t.end()), t.end());
    vector<ll> v(t.size() + 5, 0);
    REP(i, N) {
        ll s = lower_bound(t.begin(), t.end(), A[i].first) - t.begin();
        ll e = lower_bound(t.begin(), t.end(), A[i].second) - t.begin();
        v[s]++;
        v[e + 1]--;
    }

    REP(i, v.size() - 1) {
        v[i + 1] += v[i];
    }
    sort(A, A + N, [](pll a, pll b) { return a.second < b.second; });

    if (N % 2 == 1) {
        ll n = (N + 1) / 2;
        ll num = 0;
        ll s = INF;
        ll e = 0;
        ll index = 0;
        REP(i, t.size()) {
            //cout << v[i] << " ";
            ll x = t[i];
            while (x > A[index].second) {
                num++;
                index++;
            }

            if (num < n && num + v[i] >= n) {
                s = std::min(s, x);
                e = std::max(e, x);
            }
        }
        //cout << endl;
        // cout << s << " " << e << endl;
        cout << e - s + 1 << endl;
    }
    else {
        ll n = N / 2;
        ll num = 0;
        pll a(INF, 0), b(INF, 0);
        ll index = 0;
        REP(i, t.size()) {
            ll x = t[i];
            while (x > A[index].second) {
                num++;
                index++;
            }

            if (num < n && num + v[i] >= n) {
                a.first = std::min(a.first, x);
                a.second = std::max(a.second, x);
            }
            if (num < n + 1 && num + v[i] >= n + 1) {
                b.first = std::min(b.first, x);
                b.second = std::max(b.second, x);
            }
        }
        //cout << a.first << " " << a.second << endl;
        //cout << b.first << " " << b.second << endl;
        ll s = a.first + b.first;
        ll e = a.second + b.second;
        cout << e - s + 1 << endl;
    }
    return 0;
}

Measured memory_bytes: 12876