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

#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x)  cerr << #x << " = " << x << endl
using namespace std;

typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;

const ld PI = 3.14159265359;

const ll MOD = (ll) 998244353ll;
const ll MAXN = (ll) 2e5 + 10;
const ll INF = (ll) 2242545357980376863;
const ld EPS = (ld) 1e-8;



int main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	ll n, a, b;
	 cin >> n >> a >> b;
	 cout << min(a, b) << " " << max(a + b - n, 0ll);

	return 0;
}


/*

                                 ____              ,----..               ,----..
   ,---,                       ,'  , `.           /   /   \             /   /   \
  '  .' \                   ,-+-,.' _ |          /   .     :           /   .     :
 /  ;    '.              ,-+-. ;   , ||         .   /   ;.  \         .   /   ;.  \
:  :       \            ,--.'|'   |  ;|        .   ;   /  ` ;        .   ;   /  ` ;
:  |   /\   \          |   |  ,', |  ':        ;   |  ; \ ; |        ;   |  ; \ ; |
|  :  ' ;.   :         |   | /  | |  ||        |   :  | ; | '        |   :  | ; | '
|  |  ;/  \   \        '   | :  | :  |,        .   |  ' ' ' :        .   |  ' ' ' :
'  :  | \  \ ,'        ;   . |  ; |--'         '   ;  \; /  |        '   ;  \; /  |
|  |  '  '--'          |   : |  | ,             \   \  ',  /          \   \  ',  /
|  :  :                |   : '  |/               ;   :    /            ;   :    /
|  | ,'                ;   | |`-'                 \   \ .'              \   \ .'
`--''                  |   ;/                      `---`                 `---`
                       '---'

*/


Measured memory_bytes: 256
#include <iostream>
#include <iomanip> // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple> // get<n>(xxx)
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set> // S.insert(M);
// if (S.find(key) != S.end()) { }
// for (auto it=S.begin(); it != S.end(); it++) { }
// auto it = S.lower_bound(M);
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib> // atoi(xxx)
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.
// insert #if<tab> by my emacs. #if DEBUG == 1 ... #end

typedef long long ll;

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

// const int C = 1e6+10;
// const ll M = 1000000007;

int A, B;

int solve() {
  if (A == 1 && B == 1) {
    return 2;
  }
  if (A == 1) {
    return 0;
  }
  if (B == 1) {
    return 1;
  }
  if (A == B) {
    return 2;
  }
  if (A < B) {
    return 1;
  }
  return 0;
}

int main () {
  cin >> A >> B;
  int s = solve();
  if (s == 0) {
    cout << "Alice" << endl;
  } else if (s == 1) {
    cout << "Bob" << endl;
  } else {
    cout << "Draw" << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
#include<iomanip>
#include<functional>

using namespace std;
typedef long long ll;



int main() {
	int n; cin >> n;
	vector<int> a(n);
	int cnt = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (a[i] % 2 == 0) cnt++;
	}
	cout << pow(3,(int)a.size()) - pow(2,cnt) << endl;
}


Measured memory_bytes: 4140
#include<iostream>
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<string>
#include<cstring>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<bitset>
#define endl "\n"
using namespace std;

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

  int x;
  cin >> x;

  if (x < 1200)
  {
    cout << "ABC" << endl;
  }
  else
  {
    cout  << "ARC" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main()
{
    int n, a, b;
    cin >> n;
    cin >> a >> b;
    int num1 = 0, num2 = 0, num3 = 0;
    rep(i, 0, n) {
        int p;
        cin >> p;
        if (p <= a) num1++;
        else if (a + 1 <= p && p <= b) num2++;
        else num3++;
    }
    cout << min({num1, num2, num3}) << endl;
    return 0;
}


Measured memory_bytes: 256
def sums(n)
  return n*(n+1)/2
end

n = gets.to_i
s = Array.new(n)
for i in 0..(n-1)
  s[i] = gets.chomp.split("").sort.join
end

strs = Hash.new(0)
for i in 0..(n-1)
  strs[s[i]] += 1
end
cnt = 0
strs.each do |key, val|
  cnt += sums(val-1) if val > 1
end
puts cnt

Measured memory_bytes: 32636
using System;

namespace Sample
{
  class Sample
  {
    static void Main(string[] args)
    {
    int N=int.Parse(Console.ReadLine());
      if(N==1){
       Console.WriteLine("Hello World"); 
      }else{
        int A=int.Parse(Console.ReadLine());
        int B=int.Parse(Console.ReadLine());
        Console.WriteLine(A+B);
      }
 
    }
    
  }

}


Measured memory_bytes: 27480
#include<iostream>
#include<algorithm>

int main(){
    int N,sum=0,L[202];
    std::cin >> N;
    for(int i=0; i<N*2; ++i) std::cin >> L[i];
    std::sort(L,L+N*2);
    for(int i=0; i<N*2; i+=2) sum += L[i];
    std::cout << sum;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define N 1005
using namespace std;

int n, m;
vector<int> G[N];
vector<int> rG[N];
int used[N], line[N], start, f;

void dfs(int x, int px){
  
  if( f ) return;
  
  used[x] = 1;
  line[x] = 1;
  
  int flg = 0;
  
  for(int nx : G[x] ){
    
    if( nx == start ){
      flg = 1;
    }
    
    if( nx != start && line[nx] ){
      line[x] = 0;
      return;
    }
    
  }
  
  for(int nx : rG[x] ){
    
    if( line[nx] && nx != px ){
      line[x] = 0;
      return;
    }
    
  }
  
  if( flg ){
    f = 1;
    return;
  }
  
  for(int nx : G[x] ){
    
    if( used[nx] ) continue;
    
    dfs( nx, x );

    if( f ) return;
    
  }
  
  line[x] = 0;
  
}

signed main(){
  
  cin>>n>>m;
  
  for(int i=0;i<m;i++){
    int a, b;
    cin>>a>>b;
    G[a-1].push_back(b-1);
    rG[b-1].push_back(a-1);
  }
  
  for(int i=0;i<n;i++){
    start = i;
    memset( used, 0, sizeof(used) );
    dfs(i,-1);
    if( f ) break;
  }
  
  if( !f ){
    cout<<-1<<endl;
    return 0;
  }
  
  int cnt = 0;
  
  for(int i=0;i<n;i++){
    if( line[i] ) cnt++;
  }
  
  cout<<cnt<<endl;
  
  for(int i=0;i<n;i++){
    if( line[i] ) cout<<i+1<<endl;
  }
  
  return 0;
}


Measured memory_bytes: 384
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        var ABC = ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
        var (A, B, C) = (ABC[0], ABC[1], ABC[2]);

        var ans = "Yes";

        if ((A == B && B == C) || (A != B && B != C && C != A))
            ans = "No";

        WriteLine(ans);
    }
}


Measured memory_bytes: 28300
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int inputValue(){
    int a;
    cin >> a;
    return a;
};

void inputArray(int * p, int a){
    REP(i, a){
        cin >> p[i];
    }
};

void inputVector(vector<int> * p, int a){
    REP(i, a){
        int input;
        cin >> input;
        p -> push_back(input);
    }
}

int main()
{
    int A = inputValue();
    int B = inputValue();
    int exc8_min = ceil(A / 0.08);
    int exc8_max = ceil((A+1) / 0.08) - 1;
    int exc10_min = B * 10;
    int exc10_max = B * 10 + 9;

    int ans = -1;
    if(exc10_min <= exc8_min && exc8_min <= exc10_max){
        ans = exc8_min;
    }else if(exc8_min <= exc10_min && exc10_min <= exc8_max){
        ans = exc10_min;
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
n = gets.to_i
a = gets.split.map(&:to_i)
h = Hash.new(0)
a.each do |x|
  h[x] += 1
end
f = true
h.each do |k, v|
  if n.odd? && k == 0
    if v != 1
      f = false
      break
    end
  elsif v != 2
    f = false
    break
  end
end
MOD = 1_000_000_007
puts (f ? 2.pow(n / 2, MOD) : 0)

Measured memory_bytes: 22676
import java.util.*;

public class Main {
    public static void main (String[] args) {
        Scanner scanner = new Scanner(System.in);
        int rectangleCnt = 0;
        int lozengeCnt = 0;
        
        while (scanner.hasNext()) {
            String input = scanner.nextLine();
            String[] data = input.split(",");
            int side1 = Integer.parseInt(data[0]);
            int side2 = Integer.parseInt(data[1]);
            int diagonal = Integer.parseInt(data[2]);
            
            if (side1*side1+side2*side2 == diagonal*diagonal) {
                rectangleCnt++;
            } else if (side1 == side2) {
                lozengeCnt++;
            }
        }
        System.out.println(rectangleCnt);
        System.out.println(lozengeCnt);
    }   
}

Measured memory_bytes: 17132
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

int main(){
	int A,B,C,D;
	cin >> A >> B >> C >> D;
	if (A * B >= C * D){
		cout << A * B << endl;
	}
	else{
		cout << C * D <<endl;
	}
	return 0;
}

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

using namespace std;
using ll = long long;

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

const int mod = 1e9 + 7;

int dp[100005][2];

int main() {
  string s;
  cin >> s;
  int n = s.size();
  dp[0][0] = 1;

  rep(i, n) {
    { // a + b = 0
      if (s[i] == '0') {
        dp[i + 1][0] = dp[i][0];
        dp[i + 1][1] = dp[i][1];
      } else {
        dp[i + 1][1] = (dp[i][0] + dp[i][1]) % mod;
      }
    }

    { // a + b = 1
      if (s[i] == '0') {
        (dp[i + 1][1] += dp[i][1] * 2 % mod) %= mod;
      } else {
        (dp[i + 1][0] += dp[i][0] * 2 % mod) %= mod;
        (dp[i + 1][1] += dp[i][1] * 2 % mod) %= mod;
      }
    }
  }

  int ans = (dp[n][0] + dp[n][1]) % mod;
  cout << ans << endl;
  return 0;
}


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

int main() {
	int n; cin >> n;
	vector<int> y(n);
	rep(i, n) cin >> y.at(i);
	rep(i, n) {
		for (int j = i + 1; j < n; j++) {
			vector<int> u = y;
			int u_ans = u.at(i);
			u.at(i) = u.at(j);
			u.at(j) = u_ans;
			vector<int> t = u;
			sort(t.begin(), t.end());
			if (u == t) {
				cout << "YES" << endl;
				return 0;
			}
		}
	}
	vector<int> u = y;
	sort(u.begin(), u.end());
	if (u == y) { cout << "YES" << endl; return 0; }
	cout << "NO" << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {

	public static void main(String args[]){

		Scanner scan = new Scanner(System.in);
		int a, b, c, d;
		a = scan.nextInt();
		b = scan.nextInt();
		c = scan.nextInt();
		d = scan.nextInt();
		
		if(a <= c && c <= b)
			if(b <= d)System.out.print(b-c);
			else System.out.print(d-c);
		else if(c <= a && a <= d)
			if(d <= b)System.out.print(d-a);
			else System.out.print(b-a);
		else System.out.print(0);
		
	}
}

Measured memory_bytes: 21844
#include<iostream>

using namespace std;

int main(){
  int h1,h2,m1,m2,k,s,t;
  cin >> h1 >> m1 >> h2 >> m2 >> k;
  if(h1 > h2)
    h2 += 24;
  s = h1*60 + m1;
  t = h2*60 + m2;
  cout << t - s - k << endl;
  return 0;
}

Measured memory_bytes: 3600
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;

class Solution {
public:
    long long solve(long long n, long long a, long long b) {
        long long res = n / (a + b) * a;
        long long rem = n % (a + b);
        rem = min(rem, a);
        res += rem;
        return res;
    }
};

int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    Solution sol;

    long long n, a, b;
    cin >> n >> a >> b;

    cout << sol.solve(n, a, b) << "\n";

    return 0;
}

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

int main(){
  int N, M;
  cin >> N >> M;
  int lmax = 0, rmin = N+1;
  for(int i = 0; i < M; ++i){
    int l, r;
    cin >> l >> r;
    lmax = max(lmax,l);
    rmin = min(rmin,r);
  }
  cout << max(0,rmin-lmax+1) << endl;
}


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

#define Min(i, j, k) min(i, min(j, k))

const int N = 1405;
int n, m;
bitset<N> G[N];
int dp[N][N];

inline int nextInt(void) {
	int res;
	scanf("%d", &res);
	return res;
}

signed main(void) {
	n = nextInt();
	m = nextInt();
	for (int i = 0; i < N; i++)
		G[i].reset();
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++)
			if (nextInt())
				G[i][j] = 1;
	memset(dp, 0, sizeof(dp));
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++) 
			if (!G[i][j]) {
				dp[i][j] = Min(dp[i - 1][j - 1], dp[i - 1][j], dp[i][j - 1]) + 1;
			}
	int ans = 0;
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++)
			ans = max(ans, dp[i][j]);
	printf("%d\n", ans*ans);
}

Measured memory_bytes: 9148
#include <cstdio>
#include <map>
#define int long long
using namespace std;
const int M = 1e9+7;
map<int, int> a;
int n;
int dfs(int x) {
    if (a[x]) return a[x];
    if (x % 2) return a[x] = (2 * dfs(x / 2) + dfs(x / 2 - 1)) % M;
    else return a[x] = (dfs(x / 2) + 2 * dfs(x / 2 - 1)) % M;
}
signed main() {
    a[0] = 1; a[1] = 2;
    scanf("%lld", &n);
    printf("%lld", dfs(n));
    return 0;
}

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

int main(void)
{
  int i,j;
  int n,r;
  int p,c;
  int *h,*tmp;


  while(1)
    {
      scanf("%d %d",&n,&r);
      if(n==0 && r==0){break;}

      h=(int*)malloc(sizeof(int)*n);
      for(i=0;i<n;i++){
	h[i]=n-i;}

      for(i=0;i<r;i++)
	{
	  scanf("%d %d",&p,&c);
	  tmp=(int*)malloc(sizeof(int)*(p-1));

	  for(j=0;j<p-1;j++)
	    {
	      tmp[j] = h[j];
	    }

	  for(j=0;j<c;j++)
	    {
	      h[j] = h[j+p-1];
	    }

	  for(j=0;j<p-1;j++)
	    {
	      h[j+c] = tmp[j];
	    }
	}
      printf("%d\n",h[0]);
    }
  return 0;
}

Measured memory_bytes: 0
#include<cstdio>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>

#define ll long long
#define FOR(i,N) for(int i=0;i<(int)N;i++)
#define FORIN(i,a,b) for(int i=a;i<(int)b;i++)
#define ALL(x) (x).begin(),(x).end()
#define LAST(x) (x)[(x).size()-1]

using namespace std;

string to_hex(int x){
    stringstream ss;
    ss<<hex<<x;
    return ss.str();
}

string to_string(string s){
    return s;
}

template<class T>
string to_string(vector<T> v){
    string ret="{";
    FOR(i,v.size()-1){
        ret+=to_string(v[i])+",";
    }
    if(v.size()>0){
        ret+=to_string(LAST(v));
    }
    ret+="}";
    return ret;
}

void debug(){
    cerr<<endl;
}

template<class Head,class... Tail>
void debug(Head head,Tail... tail){
    cerr<<" "<<to_string(head);
    debug(tail...);
}

int main(){
    int H,W;
    cin>>H>>W;
    vector<vector<int>> c(10,vector<int>(10));
    FOR(y,10){
        FOR(x,10){
            cin>>c[y][x];
        }
    }
    FOR(k,10){
        FOR(y,10){
            FOR(x,10){
                if(c[y][x]>c[y][k]+c[k][x]){
                    c[y][x]=c[y][k]+c[k][x];
                }
            }
        }
    }
    int ans=0;
    FOR(y,H){
        FOR(x,W){
            int A;
            cin>>A;
            if(A>=0)ans+=c[A][1];
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
n, x = gets.split.map(&:to_i)
tmp = gets.split.map(&:to_i)
tmp << x
tmp.sort!
hoge = []
n.times do |i|
  hoge << tmp[i+1]-tmp[i]
end
ans = hoge[0]
(n-1).times do |i|
  ans = hoge[i+1].gcd(ans)
end
puts ans


Measured memory_bytes: 10480
#include <cstdio>
#include <cmath>
#include <iostream>
#include <set>
#include <algorithm>
#include <vector>
#include <map>
#include <cassert>
#include <string>
#include <cstring>
#include <queue>

using namespace std;

#define rep(i,a,b) for(int i = a; i < b; i++)
#define S(x) scanf("%d",&x)
#define S2(x,y) scanf("%d%d",&x,&y)
#define P(x) printf("%d\n",x)
#define all(v) v.begin(),v.end()
#define FF first
#define SS second
#define pb push_back
#define mp make_pair

typedef long long int LL;
typedef pair<int, int > pii;
typedef vector<int > vi;

const int N = 101;

vi g[N];
int D[N];
pii E[N];

int getHeight(int c, int p, int d) {
  int mx = 0;
  int cnt = 0;
  rep(i,0,g[c].size()) {
    int u = g[c][i];
    if(u != p) {
      cnt++;
      mx = max(mx, 1 + getHeight(u, c, d + 1));
    }
  }
  D[d] = max(D[d], cnt);
  return mx;
}

int main() {
  int n;
  S(n);
  rep(i,0,n-1) {
    int u,v;
    S2(u,v);
    g[u].pb(v);
    g[v].pb(u);
    E[i] = mp(u, v);
  }

  int colors = n;
  LL leafs = 1e18;

  // process vertices.. 
  rep(i,1,n+1) {
    memset(D, 0, sizeof(D));
    int c = getHeight(i, -1, 0);
    if(c <= colors) {
      LL res = 1;
      rep(i,0,c+1) {
        res *= max(D[i], 1);
      }
      if(c < colors || (c == colors && res < leafs)) {
        leafs = res;
      }
      colors = c;
    }
  }

  // process edges
  rep(i,0,n-1) {
    memset(D, 0, sizeof(D));
    int u = E[i].FF;
    int v = E[i].SS;
    int c1 = getHeight(u, v, 0);
    int c2 = getHeight(v, u, 0);
    int c = max(c1, c2);
    D[0] = 2 * max(g[u].size() - 1, g[v].size() - 1);
    if(c <= colors) {
      LL res = 1;
      rep(i,0,c+1) {
        res *= max(D[i], 1);
      }
      if(c < colors || (c == colors && res < leafs)) {
        leafs = res;
      }
      colors = c;
    }
  }

  // edge case
  if(n == 2) leafs = 2;

  printf("%d %lld\n",colors + 1, leafs);
  return 0;
}


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

using namespace std;

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long

int main(){
    int a,b; cin>>a>>b; cout<<(b-a)*(b-a+1)/2-b<<endl;
}

Measured memory_bytes: 256
h, w = map(int, input().split())

A = []
t = 0
u = 0
for i in range(h):
    s = list(input().split())
    # t  = s.index("snuke")
    if s.count("snuke") >= 1:
        t = s.index("snuke")
        u = i
        break

print(chr(ord('A') + t) + str(u+1))

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


int main() {
    int n, d;
    cin >> n >> d;
    vector<int> x(n), y(n);
    for (int i=0; i < n; i++) cin >> x.at(i) >> y.at(i);

    int cnt = 0;
    for (int i=0; i < n; i++) {
        if (sqrt(pow(x.at(i), 2)+pow(y.at(i),2)) <= d) cnt++;
    }
    cout << cnt << endl;

    return 0;
}

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

typedef long long ll;
ll dp[110][5][2];
int k;
vector<int>num;
ll solve(int pos,int K,int flag)
{
	if(pos==(int)num.size()){
		if(K==k){
			return 1;
		}
		else{
			return 0;
		}
	}
	if(K>k){
		return 0;
	}
	if(dp[pos][K][flag]!=-1){
		return dp[pos][K][flag];
	}
	ll sum = 0;
	int lmt;
	if(flag==0){
		lmt = num[pos];
	}
	else{
		lmt = 9;
	}
	for(int i=0;i<=lmt;i++){
		int nflag,nk = K;
		if(flag==1){
			nflag = 1;
		}
		else{
			if(i==lmt){
				nflag = 0;
			}
			else{
				nflag = 1;
			}
		}
		if(i!=0){
			nk++;
		}
		sum += solve(pos+1,nk,nflag);
	}
	return dp[pos][K][flag] = sum;
}
int main()
{
	string N;
	cin >> N >> k;
	for(auto it:N)
	{
		num.push_back(it-48);
	}
	memset(dp,-1,sizeof dp);
	printf("%lld\n",solve(0,0,0));
}


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

int n;
string a,b;

int main() {
	cin >> n >> a >> b;
	for(register int i = 0;i < n;i ++) putchar(a[i]),putchar(b[i]);
	puts("");
	return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

// increment
#define rep_n(_1, _2, _3, NAME, ...) NAME
#define rep_2(i, n) for (int(i) = 0; (i) < (int)(n); ++(i))
#define rep_3(i, initial, n) for (int(i) = (int)(initial); (i) < (int)(n); ++(i))
#define rep(...) rep_n(__VA_ARGS__, rep_3, rep_2, rep_1)(__VA_ARGS__)
// decrement
#define rep_r_n(_1, _2, _3, NAME, ...) NAME
#define rep_r_2(i, n) for (int(i) = (int)(n); (i) > 0; (i)--)
#define rep_r_3(i, initial, n) for (int(i) = (int)(initial); (i) > (int)(n); (i)--)
#define rep_r(...) rep_r_n(__VA_ARGS__, rep_r_3, rep_r_2)(__VA_ARGS__)
// define type definition
using namespace std;
typedef long long ll;
using mpint = boost::multiprecision::cpp_int; // 多倍長整数（任意精度）
typedef pair<int, int> P;

// define construct variable
const double EPS = numeric_limits<double>::epsilon();
// 10^9 + 7
const ll MOD = ll(1e9) + 7;
const ll INF = ll(1e10);
const string ALPHABET = "abcdefghijklmnopqrstuvwxyz";
const double PI = acos(-1);

// define methods
// 最大公約数
ll gcd(const ll a, const ll b) { return b ? gcd(b, a % b) : a; }
// 最小公倍数
ll lcm(const ll a, const ll b) { return a / gcd(a, b) * b; }
// char -> int
int ctoi(char c) { return (int)(c - '0'); }
// 素因数分解
vector< pair<ll, ll> > prime_factorize(ll n)
{
	vector<pair<ll, ll>> p;
	for (ll i = 2; i * i <= n; i++)
	{
		if ((n % i) != 0)
			continue;
		pair<ll, ll> a = make_pair(i, 0);
		while ((n % i) == 0)
		{
			n /= i;
			a.second += 1;
		}
		p.push_back(a);
	}

	if (n != 1)
		p.push_back(make_pair(n, 1));
	return p;
}
// 組み合わせの整合性を保つ（後ほど解析する）
ll modinv(ll a)
{
	ll b = MOD, u = 1, v = 0;
	while (b)
	{
		ll t = a / b;
		a -= t * b;
		swap(a, b);
		u -= t * v;
		swap(u, v);
	}
	u %= MOD;
	if (u < 0)
	{
		u += MOD;
	}
	return u;
}
// 順列
ll permutation(const ll n, const ll m)
{
	ll result = 1;
	for (ll i = n; i > n - m; i--)
	{
		result = (result * i) % MOD;
	}
	return result;
}

// 繰り返し n 乗法
ll repeat_square(const ll n, const ll x)
{
	if (x == 0)
		return 1;
	ll res = repeat_square(n, x / 2);
	res = res * res % MOD;
	if ((x % 2) == 1)
		res = res * n % MOD;
	return res;
}
// 組み合わせ nCm
ll combination(ll n, ll m)
{
	ll p = permutation(n, m);
	ll div = 1;
	for (ll i = 2; i <= m; i++)
	{
		div = (div * i) % MOD;
	}
	return (p * modinv(div)) % MOD;
}

void fill(int x, vector<int> &dp) {
	if(dp[x]) return;
	for(int i = 1; i*x <= 1e6; i++) {
		dp[i*x] = true;
	}
	return;
}

int main() {
	int N;
	cin >> N;

	vector<int> v;
	map<int, int> dic;
	vector<int> dp(1e6 + 1, false);

	rep(i, N) {
		int x;
		cin >> x;
		dic[x]++;
	}


	for(auto itr : dic) {
		if(itr.second == 1) v.push_back(itr.first);
		else fill(itr.first, dp);
	}

	sort(v.begin(), v.end());
	int res = 0;
	rep(i, v.size()) {
		if(dp[v[i]] == false) res++;
		fill(v[i], dp);
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 17524
from sys import stdin
import itertools
import numpy as np
from numba import njit

@njit("i8(i8,i8,i8[:],i8[:],i8[:],i8[:],i8[:,:])",cache=True)
def f(l,Q,a,b,c,d,arrays):
    max_res=0
    for i in range(l):
        res=0
        for j in range(Q):
            if arrays[i][b[j]-1]-arrays[i][a[j]-1]==c[j]:
                res+=d[j]
        max_res=max(max_res,res)
    return max_res
  
def main():
#入力
    readline=stdin.readline
    N,M,Q=map(int,readline().split())
    a=np.zeros(Q,dtype=np.int64)
    b=np.zeros(Q,dtype=np.int64)
    c=np.zeros(Q,dtype=np.int64)
    d=np.zeros(Q,dtype=np.int64)
    for i in range(Q):
        a[i],b[i],c[i],d[i]=map(int,readline().split())

    arrays=np.array(list(itertools.combinations_with_replacement(range(1,M+1),N)),dtype=np.int64)
    l=len(arrays)

    print(f(l,Q,a,b,c,d,arrays))
    
if __name__=="__main__":
	main()

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for (ll i=(a);i<(b);i++)
#define RFOR(i,a,b) for (ll i=(b)-1;i>=(a);i--)
#define REP(i,n) for (ll i=0;i<(n);i++)
#define RREP(i,n) for (ll i=(n)-1;i>=0;i--)
#define debug(x) cout<<#x<<": "<<x<<endl
#define pb push_back
#define ALL(a) (a).begin(),(a).end()

const ll linf = 1e18;
const int inf = 1e9;
const double eps = 1e-12;
const double pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
	EACH(x,vec) is >> x;
	return is;
}
/*
template<class... T>
ostream& operator<<(ostream& os, tuple<T...>& t) {
	for (size_t i = 0; i < tuple_size< tuple<T...> >::value; ++i) {
		if (i) os << " ";
		os << get<0>(t);
	}
	return os;
}
*/
template<typename T>
ostream& operator<<(ostream& os, vector<T>& vec) {
	REP(i,vec.size()) {
		if (i) os << " ";
		os << vec[i];
	}
	return os;
}
template<typename T>
ostream& operator<<(ostream& os, vector< vector<T> >& vec) {
	REP(i,vec.size()) {
		if (i) os << endl;
		os << vec[i];
	}
	return os;
}

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	int N, M, s, g1, g2;
	while ( cin >> N >> M >> s >> g1 >> g2, N || M || s || g1 || g2 ) {
		--s, --g1, --g2;
		ll m[100][100]; fill(m[0], m[100], linf);
		REP(i, N) m[i][i] = 0;
		REP(i, M) {
			ll a, b, c; cin >> a >> b >> c; --a, --b;
			m[a][b] = min(m[a][b], c);
//			m[b][a] = min(m[b][a], c);
		}
		REP(k, N) REP(i, N) REP(j, N) m[i][j] = min(m[i][j], m[i][k] + m[k][j]);
		ll ans = linf;
		REP(i, N) {
			ans = min(ans, m[s][i]+m[i][g1]+m[i][g2]);
		}
		cout << ans << endl;
	}
}

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


int main() {
  int n;
  double xa, ya, ra, xb, yb, rb;
  double d;
  cin >> n;
  while(n--) {
    cin >> xa >> ya >> ra >> xb >> yb >> rb;
    d = sqrt((xa-xb)*(xa-xb) + (ya-yb)*(ya-yb));
    if (d > ra+rb) {
      cout << "0" << endl;
    } else if (d >= abs(ra-rb)) {
      cout << "1" << endl;
    } else if (ra > rb) {
      cout << "2" << endl;
    } else {
      cout << "-2" << endl;
    }
  }

  return 0;
}

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

int main() {
  char S;
  cin >> S;
  
  	if (S=='a' or S=='i' or S=='u' or S=='e' or S=='o'){
    	cout << "vowel" << endl;}
  	else{
    	cout << "consonant" << endl;}

}

Measured memory_bytes: 3604
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <map>
#include <math.h>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

typedef long long ll;

const int MAX_K = 1000000;

bool seen[MAX_K];

int main() {

   int K;
   scanf("%d", &K);

   int ans = 1;
   int rem = 7 % K;
   while (rem > 0) {
      if (seen[rem]) {
         ans = -1;
         break;
      }
      seen[rem] = true;
      rem = (10 * rem + 7) % K;
      ans++;
   }
   printf("%d\n", ans);

   return 0;
}

Measured memory_bytes: 2708
#if 1

#include <bits/stdc++.h>
using namespace std;
int n,k;
int ap;

int main()
{
    scanf("%d %d", &n, &k);
    int x;
    for(int i = 1;i <= n;i++)
    {
        scanf("%d",&x);
    }
    printf("%d",(n-2)/(k-1)+1);
}

#endif // 1++


Measured memory_bytes: 256
/*
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
typedef mp::cpp_int mint; //*/
#include <bits/stdc++.h>
#define  re(i,j,n) for(li i=(j);i<(n);i++)
#define  rep(i,n) re(i,0,(n))
#define  red(i,n) for(li i=n-1;i>=0;i--)
#define  all(a) begin(a),end(a)
#define  pb(a) push_back(a)
using namespace std;
typedef long int li;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<li> vli;
typedef vector<string> vs;


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

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

using namespace std;

int main(){
	int n,m;
	double t,a;
	cin >> n >> t >> a;
	double h[n];
	double ans = 1e18;

	for(int i = 0; i < n; i++){
		cin >> h[i];
		if(ans > abs(a-(t-h[i]*0.006))){
			ans = abs(a-(t-h[i]*0.006));
			m = i+1;
		}
	}
	cout << m << endl;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.NoSuchElementException;

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		}

		ptr = 0;
		try {
			buflen = in.read(buffer);
		} catch (IOException e) {
			e.printStackTrace();
		}

		return buflen > 0;
	}

	private int readByte() {
		return hasNextByte() ? buffer[ptr++] : -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
			ptr++;
		}
		return hasNextByte();
	}

	public String next() {
		if (!hasNext()) {
			throw new NoSuchElementException();
		}
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext()) {
			throw new NoSuchElementException();
		}
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) {
			throw new NumberFormatException();
		}
		return (int) nl;
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		FastScanner fs = new FastScanner();
		int n = fs.nextInt();
		int m = fs.nextInt();

		HashMap<Integer, HashSet<Integer>> conMap = new HashMap<Integer, HashSet<Integer>>();
		for (int i = 0; i < m; ++i) {
			int a = fs.nextInt();
			int b = fs.nextInt();
			conMap.putIfAbsent(a, new HashSet<Integer>());
			conMap.get(a).add(b);
			conMap.putIfAbsent(b, new HashSet<Integer>());
			conMap.get(b).add(a);
		}

		int[] distances = new int[n + 10];
		Arrays.fill(distances, 2, n + 1, 1 << 30);
		int[] traces = new int[n + 10];

		ArrayDeque<Integer> adjacent = new ArrayDeque<Integer>();
		adjacent.add(1);
		while (!adjacent.isEmpty()) {
			int current = adjacent.removeFirst();
			HashSet<Integer> destinations = conMap.get(current);
			for (int node : destinations) {
				int d = Math.min(distances[current] + 1, distances[node]);
				if (d < distances[node]) {
					adjacent.addLast(node);
					distances[node] = d;
					traces[node] = current;
				}
			}
		}

		PrintWriter pw = new PrintWriter(System.out);
		pw.println("Yes");
		for (int i = 2; i <= n; ++i) {
			pw.println(traces[i]);
		}
		pw.flush();
	}

}


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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<=(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define Eback(s) s.erase(s.end()-1,s.end())
#define rev(v) reverse(all(v))
#define minvec(v) *min_element(all(v))
#define maxvec(v) *max_element(all(v))
#define pb push_back
#define pf push_front
#define mod 1000000007
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK puts("OK")
#define OK1 puts("OK1")
#define OK2 puts("OK2")
#define SIZE(s) (int)s.size()
#define INF ((1LL<<62)-(1LL<<31))
#define zero(x,n) setw(x) << setfill('0') << n

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;
typedef vector<string> vs;
const double pi = acos(-1.0);

template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>&p) {
	ost << "{" << p.first << ", " << p.second << "} ";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost, const vector<T>&v) {
	ost << "{";
	for (int i = 0; i<(int)v.size(); i++) {
		if (i)ost << " ";
		ost << v[i];
	}
	ost << "} \n";
	return ost;
}

template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}

template<class T>
inline bool chmax(T& a, T b){if(a<b){a=b;return true;} return false;}

template<class T>
inline bool chmin(T& a, T b){if(a>b){a=b;return true;} return false;}

ll gcd(ll x, ll y) {return __gcd(x,y);}
ll lcm(ll x, ll y) {return x/__gcd(x,y)*y;}

int main()
{
	ll n;
	vector<vector<double>> v;
	vector<double> ave;
	while(cin >> n,n){
		vector<double> tmp(n);
		double a=0.0;
		rep(i,n){
			cin >> tmp[i];
			a+=tmp[i];
		}
		v.pb(tmp);
		ave.pb(a/n);
	}
	rep(i,SIZE(v)){
		double sum=0.0;
		rep(j,SIZE(v[i])) sum+=pow(v[i][j]-ave[i],2);
		cout << DOUBLE << sqrt(sum/SIZE(v[i])) << endl;
	}
	return 0;
}


Measured memory_bytes: 3232
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=100000;
int a[maxn],b[maxn+10];

int main()
{
    int n;
    int tag=0;
    scanf("%d",&n);
    for(int i=1; i<=n; i++)
    {
        scanf("%d",&a[i]);
        if(a[i]-1<0)
        {
            b[a[i]+1]++;
            b[a[i]]++;
            tag++;
        }
        else
        {
            b[a[i]-1]++;
            b[a[i]+1]++;
            b[a[i]]++;
        }
    }
    int ans=-1;
    ans=max(tag,ans);
    for(int i=0; i<=maxn+1; i++)
        ans=max(ans,b[i]);
    cout<<ans<<endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod=1000000007;
int q[100009],w[100009];

int main(){
  ll N;
  cin >> N;
  vector<ll> A(N);
  for(int i=0;i<=100000;i++)q[i]=3;
  ll ans=3;
  for(int i=0;i<N;i++){cin >> A[i];}
  for(int i=0;i<N;i++){
    if(A[i]>i){cout << 0 << endl; return 0;}
  }
  q[0]--;
  for(int i=1;i<N;i++){
    if(q[A[i]]==0){cout << 0 << endl; return 0;}
    else if(A[i]==0){ans=(ans*q[0])%mod; q[A[i]]--;}
    else{ans=(ans*((3-q[A[i]-1])-w[A[i]]))%mod; q[A[i]]--; w[A[i]]++;}
  }
  cout << ans << endl;
}

Measured memory_bytes: 1792
n=int(input())

x=[-1]*(10**7+5)
x[0]=0
x[1]=1
i=2
prime=[]
while i<=10**7+1:

    if x[i]==-1:
        x[i]=i
        prime.append(i)

    for j in prime:
        if i*j>10**7+1 or j>x[i]:break
        x[j*i]=j
    i+=1



def f(k):
    if k==1:
        return 1

    z=[]
    p=x[k]
    m=1
    ans=1
    while k>=2:
        k=k//p
        if p==x[k]:
            m+=1
        else:
            z.append(m)
            m=1
            p=x[k]

    for i in range(len(z)):
        ans*=z[i]+1
    return ans
ans=0
for i in range(1,n+1):
    #print(i,f(i))
    ans += i*f(i)

print(ans)

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

int main() {
  string n;
  cin >> n;
  for(int i=0;i<n.size();i++){
	if(n.at(i) == '1'){
      n.at(i) = '9';
    }else if(n.at(i) == '9'){
      n.at(i) = '1';
    }
  }
  cout << n << endl;
  return 0;
}


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

typedef long long ll;
const ll mod=1e9+7;
const ll N=1e5+1;
const double PI=acos(-1.0);

bool comp1(pair<ll,ll> a,pair<ll,ll> b){
	//if(a.second==b.second) return a.first>b.first; 
	return a.second<b.second;
}
bool comp2(pair<ll,ll> a,pair<ll,ll> b){
	//if(a.first==b.first) return a.second<b.second;
	return a.first>b.first;
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	int n;
	cin>>n;
	vector<pair<ll,ll>> pl,pr;
	for(int i=0;i<n;i++){
		string s;
		cin>>s;
		int a=0,b=0;
		for(char ch:s) ch=='('?a++:(a?a--:b++);
		a>=b?pl.push_back({a,b}):pr.push_back({a,b});
	}
	sort(pl.begin(),pl.end(),comp1);
	sort(pr.begin(),pr.end(),comp2);
	for(auto i:pr) pl.push_back(i);
	int sum=0,ans=1;
	for(int i=0;i<pl.size();i++){
		sum-=pl[i].second;
		if(sum<0){
			ans=false;
			break;
		}
		sum+=pl[i].first;
	}
	if(ans and sum) ans=false;
	cout<<(ans?"Yes":"No");
}


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

using namespace std;

#define REP1(i,n) for(int i=1, i##_len=(n); i<i##_len; ++i)
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define pow(x) x*x
#define ll long long
static const ll MAX = 1000000;
static const ll INFTY = 1e12;

struct edge {
    ll to;
    char cost;
};

using Graph = vector<vector<int>>;
using _Graph = vector<vector<edge>>;
// 入力
int H, W;
vector<vector<char>> field;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

// 深さ優先探索
vector<bool> seen;
vector<int> colors;

int N;

int main(void){
    
    ll L, R;
    cin >> L >> R;
    const int _mod = 2019;

    if (R - L > 1e4) {
        cout << 0 << endl;
        return 0;
    }

    int ans = _mod;
    for(int i = L; i < R; i++){
        for(int j = L+1; j <= R; j++){
            ans = min(ans, ((i%_mod)*(j%_mod)%_mod));
            if(ans == 0)break;
            // cout << i << " " << j <<  endl;
        }
    }
    
    cout << ans << endl;

}
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         pass System Test!
*/


Measured memory_bytes: 384
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(true){
			int n = sc.nextInt();
			if(n==0) break;
			
			int[] a = new int[n];
			int[] b = new int[n];
			int suma = 0;
			int sumb = 0;
			for(int i=0;i<n;i++){
				a[i] = sc.nextInt();
				b[i] = sc.nextInt();
				suma += a[i];
				sumb += b[i];
			}
			Arrays.sort(a);
			Arrays.sort(b);
			
			int W = 0;
			if(suma-a[n-1]<a[n-1]) W = a[n-1] - (suma-a[n-1]);
			
			if(W==0){
				System.out.println(suma+sumb);
			}else{			
				int[][] dp = new int[n][W+1];
				
				for(int i=0;i<n-1;i++){
					for(int j=0;j<=W;j++){
						if(j<b[i]) dp[i+1][j] = dp[i][j];
						else dp[i+1][j] = Math.max(dp[i][j], dp[i][j-b[i]]+b[i]);
					}
				}
				System.out.println(2*a[n-1] + (sumb-dp[n-1][W]));
			}
		}
	}
}

Measured memory_bytes: 62192
#include<bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
#define rep(i, n) for(int i = 0; i < (n); i++)
///////////////////////////
int main() {
  int n;
  cin>>n;
  vector<int> v(n),w(n);
  rep(i,n) cin>>v[i];
  w[0]=0;
  w[1]=abs(v[1]-v[0]);
  for(int i=2;i<n;i++) w[i]=min(w[i-1]+abs(v[i]-v[i-1]),w[i-2]+abs(v[i]-v[i-2]));
  cout<<w[n-1]<<endl;
}
///////////////////////////


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)

int main() {
    string a, b;
    cin >> a >> b;

    string c = a + b;
    ll cNum = stoi(c);

    for(ll i = 1; i*i <= cNum; i++) {
        if(i*i == cNum) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <map>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <math.h>
#include <string>
using namespace std;
typedef long long ll;
typedef double d;
typedef int i;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n , m , a , b , g[9][9] = {} , z = 0;
    cin >> n >> m;
    for ( int i = 0 ; i < m ; i++ ) cin >> a >> b , g[a][b] = g[b][a] = 1;
    int c[8] = {1 , 2 , 3 , 4 , 5 , 6 , 7 , 8};
    do {
        bool y = 1;
        for ( int i = 1 ; i < n ; i++ ) {
            if ( g[c[i - 1]][c[i]] == 0 ) y = 0;
        }
        if ( y ) z++;
    } while ( next_permutation( c + 1 , c + n ) );
    cout << z;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#define VNUM 2000001
#define NUM 10000

int main(){

  unsigned short *A,*B;

  int C[NUM+1];
  int n,i,j;

  scanf("%d",&n);

  A = malloc(sizeof(short)*n+1);
  B = malloc(sizeof(short)*n+1);

  for(i=0;i<=NUM;i++){
    C[i] = 0;
  }

  for(i=0;i<n;i++){
    
    scanf("%hu",&A[i+1]);
    C[A[i+1]]++;
    
  }

  for(i=1;i<=NUM;i++){
    C[i] = C[i] + C[i-1];
  }

  for(j=1;j<=n;j++){

    B[C[A[j]]] = A[j];
    C[A[j]]--;
  }

  for(i=1;i<=n;i++){
    if(i>1)
      printf(" ");

    printf("%d",B[i]);
  }
  printf("\n");

  return 0;
}



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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << fixed << setprecision(15);

  int n;
  string s;
  cin >> n >> s;

  int sum = 0;
  for (int i = 0; i < n - 2; ++i) {
    if (s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C') {
      ++sum;
      i += 2;
    }
  }
  cout << sum << '\n';

  return 0;
}


Measured memory_bytes: 256
from sys import stdin, stderr, setrecursionlimit, exit
from collections import Counter
setrecursionlimit(2147483647)
def getint():
    return int(stdin.readline().rstrip('\r\n'))
def getints():
    return [int(i) for i in stdin.readline().rstrip('\r\n').split()]
def getintlines(n=1):
    res = []
    for _ in range(n):
        res.append(getint())
    return res
def getintslines(n=1):
    res = []
    for _ in range(n):
        res.append(getints())
    return res
def debug(*args, **kwargs):
    print(*args, file=stderr, **kwargs)

n = getint()
a = getints()
c = Counter()

for i in a:
    c[i-1] += 1
    c[i] += 1
    c[i+1] += 1

print(c.most_common(1)[0][1])


Measured memory_bytes: 20044
/*
 * Author - Abhas Jain
 * Code is inside the solve function
 */
 
#include <bits/stdc++.h>
 
#define F first
#define S second
#define all(c) c.begin(), c.end()
#define endl '\n'
#define pb push_back

typedef long long ll;
typedef long double ld;

using namespace std;
mt19937 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
 
const ld PI = 3.141592653589793;
const ll INF = 9223372036854775807ll;
const ll mod = 1e9 + 7;
 
vector<int> a;
int n, k;

bool check(int val) {
	int left = k;
	for (int i = 0; i < n; ++i) {
		left -= ((a[i] + val - 1) / val) - 1;
	}
	return left >= 0;
}

void solve() 
{
	cin >> n >> k;
	for (int i = 0; i < n; ++i) {
		int cur;
		cin >> cur;
		a.pb(cur);
	}
	int lo = 1;
	int hi = 1e9;
	int ans = -1;
	while (hi >= lo) {
		int mid = (lo + hi) / 2;
		if (check(mid)) {
			ans = mid;
			hi = mid - 1;
		} else lo = mid + 1;
	}
	cout << ans << endl;
}
 
int main( )
{   
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());
    solve();
    return 0;
}

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

int main(){
	int n;
	cin >> n;
	int a[n];
	int count = 0;
	for(int i = 0;i < n;i++){
		cin >> a[i];
	}
	for(int i = 1;i < n-1;i++){
		if(a[i] > a[i-1]){
			if(a[i] <= a[i+1]){
				count++;
			}
		}else{
			if(a[i] > a[i+1]){
				count++;
			}
		}
	}
	cout << count << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define maxn 500005
#define ll long long
#define mod 1000000007
using namespace std;

typedef pair<ll, ll> P;
int n;
vector<P> v;

int main()
{
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        ll a, b;
        scanf("%lld%lld", &a, &b);
        v.push_back(P(b, a));
    }
    sort(v.begin(), v.end());
    ll now = 0;
    bool ok = 1;
    for (int i = 0; i < n; i++)
    {
        ll B = v[i].first;
        ll A = v[i].second;
        now += A;
        if (now > B)
            ok = 0;
    }
    if (!ok)
        printf("No");
    else
        printf("Yes");

    return 0;
}

Measured memory_bytes: 6512
#include <stdio.h>

int main(void){
    int S;
    int h,m,s;
    
    scanf("%d",&S);
    
    if(0<=S&&S<=86400){
        h=S/3600;
        m=(S%3600)/60;
        s=S%60;
        printf("%d:%d:%d\n",h,m,s);
    }
    else{
        printf("error\n");
    }
    
    return 0;
}


Measured memory_bytes: 2104
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
int INF = 1000000009;
int main()
{
  int n,m;
  cin >> n >> m;
  vector<int> a(m),b(m);
  vector<int> cnt(51);
  rep(i, m)
  {
    cin >> a[i] >> b[i];
    cnt[a[i]]++;
    cnt[b[i]]++;
  }
  for (int i = 1;i<=n;i++){
    cout << cnt[i] << "\n";
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
// #include <math>

using namespace std;

int main(){
	long long n, a, b, sets, rem, ans;
	// scanf("%d %d %d", &n, &a, &b);
	cin >> n >> a >> b;
	sets = n / (a+b);
	ans = sets * a;
	rem = n - sets * (a+b);

	ans = ans + min(rem,a);
	cout << ans;
}

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

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

    cout << min(min((A%2!=0)*B*C, (B%2!=0)*A*C), (C%2!=0)*A*B) << endl;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
	unsigned long int a, b, c;
	int i;

	scanf("%ld%ld%ld", &a, &b, &c);

	if ((0 == b % a) || (0 == c % a) || (c / a != b / a)) {
		printf("OK");
	}

	else {
	printf("NG");
}
	return 0;
}

Measured memory_bytes: 1732
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <iostream>
#include <functional>
#include <unordered_map>

using namespace std;
typedef pair<int, int> Pi;
typedef long long ll;
#define Fi first
#define Se second
#define pb(x) push_back(x)
#define sz(x) (int)x.size()
#define rep(i, n) for(int i=0;i<n;i++)
#define all(x) x.begin(), x.end()

int n;
Pi p[510];
int ans[250050];

void solve(){
	scanf("%d", &n);
	for(int i=1;i<=n;i++){
		int x; scanf("%d", &x);
		p[i] = Pi(x, i);
	}
	sort(p+1, p+1+n);
	set <int> S;
	for(int i=1;i<=n*n;i++)S.insert(i);
	for(int i=1;i<=n;i++){
		ans[p[i].Fi] = p[i].Se;
		S.erase(p[i].Fi);
		int ok = 1;
		rep(j, p[i].Se-1){
			int t = *S.begin();
			if(t > p[i].Fi){
				ok = 0; break;
			}
			ans[t] = p[i].Se;
			S.erase(t);
		}
		if(ok == 0){
			puts("No");
			return;
		}
	}
	for(int i=n;i;i--){
		int ok = 1;
		rep(j, n-p[i].Se){
			int t = *S.rbegin();
			if(t < p[i].Fi){
				ok = 0; break;
			}
			ans[t] = p[i].Se;
			S.erase(t);
		}
		if(ok == 0){
			puts("No");
			return;
		}
	}
	puts("Yes");
	rep(i, n*n)printf("%d ", ans[i+1]);
}

int main(){
	int Tc = 1; //scanf("%d", &Tc);
	for(int tc=1;tc<=Tc;tc++){
		solve();
	}
	return 0;
}

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

int main(){
    int n,k;
    cin >> n >> k;
    string s;
    cin >> s;

    vector<int> v;
    int pre=-1;
    rep(i,n){
        if(s[i]!=pre){
            v.push_back(i);
        }
        pre=s[i];
    }
    int ans=-1;
    int r=v.size();
    rep(i,r){
        int x;    
        if(s[v[i]]=='0'){
            x=((i+2*k>=r) ? n : v[i+2*k])-v[i];
        }else{
            x=((i+2*k+1>=r) ? n : v[i+2*k+1])-v[i];
        }
        ans=max(ans,x);
    }
    cout << ans << endl;
}

Measured memory_bytes: 1020