akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define maxn 100010
using namespace std;
int a[maxn];
int main()
{
	int n, m, res = 0;
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; i++)
		scanf("%d", &a[i]);
	sort(a + 1, a + n + 1);
	for (int i = 1; i <= n; i++)
	{
		if (m >= a[i]) {m -= a[i]; res++;}
	}
	if (res == n && m != 0) res--;
	printf("%d\n", res);
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    int n,b,f,r,i,v,l,k,u;
    int x[4][3][10]={};
    cin>>n;
    
    for(i=0;i<n;i++){
        cin>>b>>f>>r>>v;
        x[b-1][f-1][r-1]+=v;
    }
    for(l=0;l<3;l++){
           for(k=0;k<10;k++){
            cout<<" "<<x[0][l][k];   
           }
           cout<<endl;
       }
    cout<<"####################"<<endl;
    for(l=0;l<3;l++){
           for(k=0;k<10;k++){
            cout<<" "<<x[1][l][k];   
           }
           cout<<endl;
       }
    cout<<"####################"<<endl;
    for(l=0;l<3;l++){
           for(k=0;k<10;k++){
            cout<<" "<<x[2][l][k];   
           }
           cout<<endl;
       }
    cout<<"####################"<<endl;
    for(l=0;l<3;l++){
           for(k=0;k<10;k++){
            cout<<" "<<x[3][l][k];   
           }
           cout<<endl;
       }
    return 0;
}

    


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

#define lld long long
#define pi pair<int,int>
#define pl pair<lld,lld>
#define mem0(x) memset(x,0,sizeof(x))
#define fillnum(x,n) fill(begin(x),end(x),n)
#define asort(x) sort(x.begin(),x.end())
#define dsort(x,t) sort(x.begin(),x.end(),greater<t>())

int main() {
    lld A,B,V,W,T;
    cin >> A >> V;
    cin >> B >> W;
    cin >> T;
    lld diff = abs(A-B);
    lld diff2 = V - W;
    if(diff2 > 0 && (long double)((long double)diff / (long double)diff2) <= (long double)(T)){
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
}

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

// using ll = long long;
#define int long long

#define LOG(variable) cout << #variable":\t" << (variable) << endl
#define LOGCON(i, container) for(int (i) = 0; (i) < (container).size(); ++(i)) cout << (i) << ":\t" << (container)[(i)] << endl
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(i, r, n) for (int i = (r); i < (n); ++i)
#define REPR(i, n) for(int i = (n); i >= 0; --i) // from n to 0
#define REPRS(i, r, n) for(int i = (n); i >= (r); --i) // from n to r
#define REPOBJ(itr, obj) for(auto itr = (obj).begin(); itr != (obj).end() ; ++itr)
#define REPROBJ(itr, obj) for(auto itr = (obj).rbegin(), e = (obj).rend(); itr != e; ++itr)
#define COUTB(x) cout << (x) << "\n"
#define COUTS(x) cout << (x) << " "
#define PB push_back
#define SORT(obj) sort((obj).begin(), (obj).end())
#define SORTR(obj) sort((obj).begin(), (obj).end(), greater<>())
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define PI (acos(-1))
/***** MAIN *****/
signed main() {
  int n;
  cin >> n;
  int nums[n];
  int nega_counter = 0;
  int smallest_abs = LLONG_MAX;
  int total_abs = 0;
  REP(i,n) {
    cin >> nums[i];
    if(nums[i] < 0) ++nega_counter;
    int curr_abs = abs(nums[i]);
    smallest_abs = min(smallest_abs, curr_abs);
    total_abs += curr_abs;
  }
  if(nega_counter%2) {
    cout << total_abs - 2*smallest_abs;
  } else {
    cout << total_abs;
  }
  
  cout << "\n";
  return 0;
}
/***** MAIN *****/


Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>
#include<deque>
#include<tuple>
#include<queue>
#include<map>
#include<cstdint>
#include<unordered_map>
#include<boost/multiprecision/cpp_int.hpp>


#define rep(i, n) for(int i = 0; i < ( int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define F first
#define S second

namespace mp = boost::multiprecision;

using cpp_int = mp::cpp_int;
using ll = long long;
using uint1024_t = mp::uint1024_t;
using namespace std;


int main() {
	int n, k;
	cin >> n >> k;
	deque<int>x;
	int plus = 0, minus = 0;
	rep(i, n) {
		int pos;
		cin >> pos;
		if (pos > 0) {
			plus++;
			x.push_back(pos);
		}
		else if(pos<0){
			minus++;
			x.push_back(pos);
		}
		else {
			k--;
		}
	}
	if (x.size() == 0) {
		cout << 0 << endl;
	}
	else {
		deque<int>r, l;
		rep(i, k + 1) {
			if (i <= plus && k - i <= minus) {
				r.push_back(i);
				l.push_back(k - i);
			}
		}
		//cout << r.size() << endl;
		ll ans = 1e12;
		int ite = upper_bound(all(x), 0) - x.begin();
		rep(i, r.size()) {
			ll a, b;
			if (l[i] > 0 && r[i] > 0) {
				a = abs(0 - x[ite - 1 + r[i]])
					+ abs(0 - x[ite - l[i]]) * 2;
				b = abs(0 - x[ite - 1 + r[i]]) * 2 +
					abs(0 - x[ite - l[i]]);
			}
			else if (l[i] == 0) {
				a = abs(0 - x[ite - 1 + r[i]]);
				b = a;
			}
			else if (r[i] == 0) {
				b = abs(0 - x[ite - l[i]]);
				a = b;
			}
			ans = min(ans, min(a, b));
		}
		cout << ans << endl;
	}
	

	
}


Measured memory_bytes: 1024
//by Sshwy
//#define DEBUGGER
#include<algorithm>/*{{{*/
#include<cctype>
#include<cassert>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<ctime>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<vector>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define ROF(i,a,b) for(int i=(a);i>=(b);--i)

#ifdef DEBUGGER

#define log_prefix() { fprintf(stderr, "\033[37mLine %-3d [%dms]:\033[0m  ", __LINE__,(int)clock()/1000);  }
#define ilog(...)    { fprintf(stderr, __VA_ARGS__); }
#define llog(...)    { log_prefix(); ilog(__VA_ARGS__); }
#define log(...)     { log_prefix(); ilog(__VA_ARGS__); fprintf(stderr,"\n");  }
#define red(...)     { log_prefix(); ilog("\033[31m"); ilog(__VA_ARGS__); ilog("\033[0m\n"); }
#define green(...)   { log_prefix(); ilog("\033[32m"); ilog(__VA_ARGS__); ilog("\033[0m\n"); }
#define blue(...)    { log_prefix(); ilog("\033[34m"); ilog(__VA_ARGS__); ilog("\033[0m\n"); }

#else

#define log_prefix() ;
#define ilog(...)    ;
#define llog(...)    ;
#define log(...)     ;
#define red(...)     ;
#define green(...)   ;
#define blue(...)    ;

#endif

namespace RA{
    int r(int p){return 1ll*rand()*rand()%p;}
    int r(int L,int R){return r(R-L+1)+L;}
}/*}}}*/
/******************heading******************/
const int N=1e6+5;
int n;
char a[N];
int b[N];

int binom(int n,int m){
    if((n&m)==m)return 1;
    return 0;
}

int main(){
    scanf("%d",&n);
    scanf("%s",a+1);
    FOR(i,1,n-1)b[i]=abs(a[i]-a[i+1]);
    --n;
    if(n==1){
        printf("%d\n",b[1]);
        return 0;
    }

    bool flag=1;
    FOR(i,1,n)if(b[i]==1)flag=0;
    if(flag){//只有0，2
        int res=0;
        FOR(i,1,n){
            int coef=binom(n-1,i-1);
            res^=coef*b[i];
        }
        printf("%d\n",res);
        return 0;
    }
    //有1，则答案不可能为2。所以所有的2都可以变成0
    FOR(i,1,n)if(b[i]==2)b[i]=0;
    int res=0;
    FOR(i,1,n){
        int coef=binom(n-1,i-1);
        res^=coef*b[i];
    }
    printf("%d\n",res);
    return 0;
}


Measured memory_bytes: 5120
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<queue>
#define all(x) (x).begin(),(x).end()
typedef long long ll;
 
using namespace std;
 
int main()
{
    ll x;  cin >> x;
    ll ans;
    if(x - x/11*11 > 6) ans = (x+7)/11*2;
    else if(x - x/11*11 > 0)    ans = x/11*2 + 1;
    else    ans = x/11*2;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3604
N = int(input())
*A, = map(int, input().split())
*B, = map(int, input().split())
B.reverse()

ac = [0]*(N+1)
bc = [0]*(N+1)

ok = True
for i in range(N):
    ac[A[i]] += 1
    bc[B[i]] += 1

for i in range(1, N+1):
    if (ac[i]+bc[i]) > N:
        ok = False
        break

if ok:
    l, r = 0, N-1
    for i in range(N):
        if A[i] == B[i]:
            if A[i] != B[l] and A[l] != B[i]:
                B[l], B[i] = B[i], B[l]
                l += 1
            elif A[i] != B[r] and A[r] != B[i]:
                B[r], B[i] = B[i], B[r]
                r -= 1
    print("Yes")
    print(*B)
else:
    print("No")


Measured memory_bytes: 120800
def main():
    import sys
    input = sys.stdin.readline
    H, W = (int(i) for i in input().split())
    ans = 100000
    for h in range(1,H):
        s1 = set()
        s1.add(h*W)
        w = W // 2
        s1.add((H-h) * w)
        s1.add((H-h) * (W-w))
        ans1 = max(s1) - min(s1)

        s2 = set()
        s2.add(h*W)
        hb = (H-h)//2
        hc = H - h - hb
        s2.add(hb*W)
        s2.add(hc*W)
        ans2 = max(s2) - min(s2)

        ans = min(ans,ans1,ans2)

    H,W = W,H
    for h in range(1,H):
        s1 = set()
        s1.add(h*W)
        w = W // 2
        s1.add((H-h) * w)
        s1.add((H-h) * (W-w))
        ans1 = max(s1) - min(s1)

        s2 = set()
        s2.add(h*W)
        hb = (H-h)//2
        hc = H - h - hb
        s2.add(hb*W)
        s2.add(hc*W)
        ans2 = max(s2) - min(s2)

        ans = min(ans,ans1,ans2)

    print(ans)

if __name__ == '__main__':
    main()

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

using namespace std;
using ll = long long int;
using P = pair<int, int>;

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

int main(void){

    int n, y;
    cin >> n >> y;

    loop(i, n+1){
        loop(j, n+1){
            if(0 <= n - i - j && n-i-j <= n){
                if(10000*i+5000*j+1000*(n-i-j) == y){
                    cout << i << " " << j << " " << n-i-j << endl;
                    return 0;
                }
            }
        }
    }

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

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
#define rep(i,n)for(int i=0;i<n;i++)
#define int long long
#define ggr getchar();getchar();return 0;
#define prique priority_queue
#define mod 1000000007
#define inf 1e15
#define key 1e9
using namespace std;
typedef pair<int, int>P;
void yes() { cout << "Yay!" << endl; }
void no() { cout << ":(" << endl; }
template<class T> inline void chmax(T& a, T b) {
	a = std::max(a, b);
}
template<class T> inline void chmin(T& a, T b) {
	a = std::min(a, b);
}
bool prime(int n) {
	int cnt = 0;
	for (int i = 1; i <= sqrt(n); i++) {
		if (n % i == 0)cnt++;
	}
	if (cnt != 1)return false;
	else return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y)* mod_pow(kai(y, y), mod - 2, mod) % mod;
}
void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
	cerr << " " << to_string(H);
	debug_out(T...);
}

#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
struct edge { int to, cost; };
int par[114514], rrank[114514];//親、木の深さ
void init(int n) {
	rep(i, n) {
		par[i] = i;
		rrank[i] = 0;
	}
}
int find(int x) {
	if (par[x] == x) {
		return x;
	}
	else return par[x] = find(par[x]);
}
void unite(int x, int y) {
	x = find(x);
	y = find(y);
	if (x == y)return;
	if (rrank[x] < rrank[y]) {
		par[x] = y;
	}
	else {
		par[y] = x;
		if (rrank[x] == rrank[y])rrank[x]++;
	}
}
bool same(int x, int y) {
	return find(x) == find(y);
}
int n, m;
int p[114514];
string s[114514];
int a[114514];
int f[114514];
int x[114514];
signed main() {
	cin >> n >> m;
	rep(i, m)cin >> p[i] >> s[i];
	rep(i, m) {
		if (s[i] == "AC")a[p[i] - 1]++;
	}
	int ansa = 0;
	rep(i, n) {
		if (a[i] >= 1)ansa++;
	}
	int xx = 0;
	rep(i, m) {
		if (f[p[i] - 1] == 0 && s[i] == "WA")x[p[i] - 1]++;
		else if (s[i] == "AC") {
			if (f[p[i] - 1] == 0)xx += x[p[i] - 1];
			f[p[i] - 1] = inf;
		}
	}
	cout << ansa << " " << xx << endl;
	ggr
}


Measured memory_bytes: 10624
#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>
#include <cstdio>
using namespace std;
struct var
{
    int b,c;
    var(int x, int y)
    {
        b=x,c=y;
    }
};
struct cmp
{
    bool operator() (var a, var b)  {return a.c<b.c;}
};
priority_queue< var, vector<var>, cmp > q;
vector<int> v;
int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    v.resize(n);
    for(int i=0;i<n;++i)  scanf("%d",&v[i]);
    sort(v.begin(),v.end());
    for(int i=1;i<=m;++i)
    {
        int b, c;
        scanf("%d%d",&b,&c);
        q.push(var(b,c));
    }
    long long s=0ll;
    int b=q.top().b, c=q.top().c,i=0;
    q.pop();
    for(;i<(int)v.size();++i)
    {
        if((q.empty()&&b==0)||v[i]>c)  break;
        else if(b==0) b=q.top().b, c=q.top().c,q.pop();
        s=s+max(v[i],c);
        --b;
    }
    for(;i<(int)v.size();++i)  s+=v[i];
    printf("%lld",s);
    return 0;
}


Measured memory_bytes: 1784
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include <numeric>
#include<map>
#include<unordered_map>
#include <queue>
 
using namespace std;
using ll=long long;
#define rep(i,n)  for(ll i=0;i<n;++i)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()

int main(){
   ll n, a, b;
   cin >> n >> a >> b;
   if((b-a)&1)cout << "Borys";
   else cout << "Alice";
}

Measured memory_bytes: 256
#pragma comment(linker, "/stack:200000000")
        #pragma GCC optimize ("Ofast")
        #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
        #include <iostream>
        #include <iomanip>
        #include <sstream>
        #include <cstring>
        #include <vector>
        #include <deque>
        #include <queue>
        #include <set>
        #include <map>
        #include <valarray>
        #include <iterator>
        #include <functional>
        #include <limits>
        #include <algorithm>
        #include <numeric>
        #include <cmath>
        #include <cassert>
        #include <unordered_map>
        #include <unordered_set>
        #include <stack>
        using namespace std;
        #define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
         #define trace(x) cerr << #x << ": " << x << " " << endl;
     
        typedef int64_t ll;
     
        #define endl '\n'
        #define int ll
        // ll mod2=1e9+7;
        // ll mod1=1e9+5;
        // ll power(ll a,ll b)
        // {
        //     if(b==0) return 1;
        //     else if(b%2==0)
        //         return power((((a%mod)*(a%mod))%mod),b/2)%mod;
        //     else return ((a%mod)*(power((((a%mod)*(a%mod))%mod),b/2)%mod))%mod;
        // }
        int subCount(int arr[], int n, int k) 
{ 
    // create auxiliary hash array to count frequency 
    // of remainders 
    map<int,int> mod; 
    //memset(mod, 0, sizeof(mod)); 
  
    int cumSum = 0,result=0;
    int pre[n+1];
    memset(pre,0,sizeof(pre)); 
    for (int i = 0; i < n; i++) { 
        cumSum += arr[i];
        pre[i]=cumSum%k;
        int p=(cumSum % k); 
            if(i-k>=0)
           {
            mod[pre[i-k]]--;
           }
        result += (mod[p]);

       
        mod[p]++;
       
    } 
    int x=0;
    for(int i=0;i<min(n,k-1);++i)
    {   
        x+=arr[i];
        x%=k;
        if(x==0)
            result++;
    }
  
   
    //result += mod[0]; 
  
    return result; 
} 
     int32_t main()
        {
        IOS
       

        int n,k;
        cin>>n>>k;
        int a[n];
        for(int i=0;i<n;++i)
        {
            cin>>a[i];
            a[i]--;
            a[i]%=k;
            //cout<<a[i]<<endl;
        }
        
        cout<<subCount(a,n,k);



        }


Measured memory_bytes: 15872
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        char input = scanner.next().charAt(0);

        if (input >= 'a' && input <= 'z') {
            System.out.println('a');
        } else {
            System.out.println('A');
        }

    }
}


Measured memory_bytes: 35540
#include <bits/stdc++.h> 
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define size_of_array(array) (sizeof(array)/sizeof(array[0]))
#define MAX 100005
#define DEBUG 0 
#define LIMIT (LONG_MAX / 10)
#define POSITIVE_LAST_D (LONG_MAX % 10)
using ll =long long;
using namespace std;
using Graph=vector<vector<int>>;


int main(){
    ll a;
    double b;
    cin>>a>>b;
    ll c=b*100+0.1;
    ll d=(a*c)/100;
    cout<<d<<endl;
    return 0;
}


Measured memory_bytes: 3716
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
BC = [list(map(int, input().split())) for _ in range(Q)]

cnt = [0] * (100001)
s = sum(A)
for a in A:
    cnt[a] += 1

for b, c in BC:
    cnt[c] += cnt[b]
    s += cnt[b] * (c-b)
    cnt[b] = 0
    print(s)

Measured memory_bytes: 32188
#include<cstdio>
#include<algorithm>
#define N_ 101000
using namespace std;
long long D[N_][3];
int A[N_], B[N_], C[N_], n, K;
int main() {
	scanf("%d", &n);
	int i, j;
	for (i = 1; i <= n; i++) {
		scanf("%d%d%d", &A[i],&B[i],&C[i]);
		D[i][0] = max(D[i - 1][1], D[i - 1][2]) + A[i];
		D[i][1] = max(D[i - 1][0], D[i - 1][2]) + B[i];
		D[i][2] = max(D[i - 1][1], D[i - 1][0]) + C[i];
	}
	i--;
	printf("%lld\n", max(max(D[i][0], D[i][1]), D[i][2]));
}

Measured memory_bytes: 3712
#include <algorithm>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
// const int INF = (1 << 30) - 1;
const ll LL_INF = (1LL << 62) - 1;
// const ll MOD = 1e9 + 7;

ll N;

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

  ll ans = LL_INF;
  for (ll i = 1; i <= 1000000; i++) {
    if (N % i == 0) {
      ll j = N / i;
      ans = min(ans, i - 1 + j - 1);
    }
  }

  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    a, b, h = map(int, read().split())

    print((a + b) * h // 2)

    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 9020
n = int(input())
a = map(int, input().split())

color_set = set()
color_free_num = 0
for a_i in a:
    if a_i >= 3200:
        color_free_num += 1
    else:
        color_set.add(a_i // 400)

ans_min = max(len(color_set), 1)
ans_max = len(color_set) + color_free_num
ans = "{} {}".format(ans_min, ans_max)
print(ans)

Measured memory_bytes: 9020
#include<iostream>
#include<cstring>
using namespace std;
int mem(int tt,int bb);
int T,B;
char t[1001];
char b[1001];
int memo[1001][1001];
int main(){
  cin >> t;
  cin >> b;
  memset(memo,-1,sizeof(memo));
  T=strlen(t);
  B=strlen(b);
  cout << mem(0,0) << endl;
  return(0);
}

int mem(int tt,int bb){
  if(memo[tt][bb]>=0){
    return memo[tt][bb];
  }
  if(bb==B){
    return 1;
  }
  if(tt==T){
    return 0;
  }
  int ans;
  if(t[tt]!=b[bb]){
    ans= mem(tt+1,bb)%1000000007;
  }else{
    ans=(mem(tt+1,bb+1)+mem(tt+1,bb))%1000000007;
  }
  return memo[tt][bb]=ans;
}
  



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

typedef long long ll;
static const ll MAX = 3234566667;

vector<ll> ans;

void dfs(ll x){
    if(MAX < x) return;
    ans.push_back(x);
    ll tmp = x % 10;
    if(tmp == 0){
        dfs(10*x);
        dfs(10*x+1);
    }

    else if(tmp == 9){
        dfs(10*x+8);
        dfs(10*x+9);
    }

    else{
        dfs(10*x+tmp-1);
        dfs(10*x+tmp);
        dfs(10*x+tmp+1);
    }
}

int main(){
    ll K;
    cin>>K;
    K--;
    for(int i=1; i<=9; i++){
        dfs(i);
    }
    sort(ans.begin(),ans.end());

    cout<<ans[K]<<endl;

    return 0;
}

Measured memory_bytes: 1400
#include<bits/stdc++.h> 
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
#include <assert.h>
using namespace std;
typedef long long ll;
vector<ll> g[200005];
ll ok[200005]={0};
ll n,m; 
int main()
{
	scanf("%lld%lld",&n,&m);
	for(ll i=0;i<m;i++)
	{
		ll u,v;
		scanf("%lld%lld",&u,&v);
		g[u].push_back(v);
		g[v].push_back(u);
	}
	queue<ll> q;
	ok[1]=1;
	q.push(1);
	while(q.size())
	{
		ll p=q.front();q.pop();
//		printf("%lld %lld\n",p,ok[p]);
		for(ll i=0;i<g[p].size();i++)
		{
			ll v=g[p][i];
			if(ok[v]==0)
			{
				ok[v]=p;
				q.push(v);
			}
		}
	}
	bool okk=true;
	for(ll i=1;i<=n;i++)
	{
		if(ok[i]==0) okk=false;
	}
	if(okk)
	{
		printf("Yes\n");
		for(ll i=2;i<=n;i++)
		{
			printf("%lld\n",ok[i]);
		}
	}
	else printf("No");
}

Measured memory_bytes: 15580
#include <stdio.h>
#define N (100+5)

int main()
{
	int n,s[N];
	scanf("%d",&n);
	int ms=0,min=200;
	for(int i=0;i<n;i++){
		scanf("%d",s+i); 
		ms+=s[i];
		if(s[i]%10!=0 && s[i]<min)
			min=s[i];
	}
	if(ms%10==0)
		ms-=min;
	if(ms%10!=0)		
		printf("%d",ms);
	else
		printf("0");
	return 0; 
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a; i<b; i++)
#define lli long long
#define pb push_back
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;

int main()
{
    fast
    int n,sum;
    cin>>n;
    sum= pow(n,1)+ pow(n,2)+ pow(n,3);
    cout<<sum;

    return 0;
}


Measured memory_bytes: 3984
#include<iostream>
#include<vector>
#include<string>
#include<set>
#include<algorithm>
#include<map>
#include<queue>
#include<functional>
using namespace std;

const int MAX = 301;
const int Q_MAX = 100001;

int main() {
	int H, W, D;
	int Q;
	int L[Q_MAX], R[Q_MAX];

	int cost[MAX * MAX] = { 0 };
	pair<int, int> P[MAX * MAX];

	cin >> H >> W >> D;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			int n;
			cin >> n;
			P[n] = make_pair(j, i);
		}
	}

	cin >> Q;
	for (int i = 0; i < Q; i++) {
		cin >> L[i] >> R[i];
	}

	for (int i = 1; i <= D; i++) {
		for (int j = i; j <= H * W; j += D) {
			if (j - D < 1)continue;
			cost[j] = abs(P[j].first - P[j - D].first) + abs(P[j].second - P[j - D].second) + cost[j - D];
		}
	}

	for (int i = 0; i < Q; i++) {
		cout << cost[R[i]] - cost[L[i]] << endl;
	}

	return 0;
}


Measured memory_bytes: 2944
#include <stdio.h>
#include <string.h>
#include <utility>

using namespace std;

int p[100][100];
pair<int,int> f[100][100];

int dfs(int x,int y){
	p[x][y] = 1;
	if(p[f[x][y].first][f[x][y].second] == 1) return 1;
	else if(p[f[x][y].first][f[x][y].second] == 0) return 0;
	else return dfs(f[x][y].first,f[x][y].second);
}

int main(void){
	int i, j, k, l, n, c;
	while(1){
		scanf("%d",&n);
		if(!n) break;
		c = 0;
		memset(p,-1,sizeof(p));
		for(i = 0;i < n;i++){
			for(j = 0;j < n;j++){
				scanf("%d%d",&f[j][i].first,&f[j][i].second);
			}
		}
		for(i = 0;i < n;i++){
			for(j = 0;j < n;j++){
				if(p[j][i] == -1 && dfs(j,i)) c++;
				for(k = 0;k < n;k++){
					for(l = 0;l < n;l++) if(p[k][l] == 1) p[k][l] = 0;	
				}
			}
		}
		printf("%d\n",c);
	}
	return 0;
}

Measured memory_bytes: 1152
import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    static int n;
    static int[] dp;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        dp = new int[n];
        int ans = 0;
        for (int i = 0; i < n; i++) {
            int p = sc.nextInt();
            ans += p;
            dp[i] = p;
        }
        Arrays.sort(dp);
        if (ans%10 != 0) {
            System.out.println(ans);
        } else {
            for (int i = 0; i < n; i++) {
                if (dp[i]%10 == 0) {
                    continue;
                } else {
                    ans -= dp[i];
                    break;
                }
            }
            System.out.println(ans%10==0?0:ans);
        }
    }
}


Measured memory_bytes: 21844
// In the name of GOD
#include<bits/stdc++.h>
using namespace std;

#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";

#define     IOS         ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define 	setprecn(x) cout<<fixed<<setprecision(x);
#define 	ll          long long int
#define 	pb          push_back
#define 	pll         pair<ll,ll>
#define 	vll         vector<ll>
#define 	ff          first
#define 	ss          second
#define 	all(a)      (a).begin(),(a).end()
#define 	sz(x)       (ll)x.size()
#define 	mod         1000000007
#define 	inf         10000000000000007
#define 	rep(i,n)    for(ll i=0;i<n;i++)
#define 	repe(i,a,b) for(ll i=a;i<b;i++)
#define 	lbnd        lower_bound
#define 	ubnd        upper_bound
#define 	bs          binary_search

ll power(ll a,ll b,ll m=mod)
{
	if(b==0)
		return 1;
	if(b==1)
		return a;
	ll c=power(a,b/2,m);
	if(b%2==0)
		return((c%m)*(c%m))%m;
	return ((((c%m)*(c%m))%m)*(a%m))%m;
}
/********************************************************/
//	d.erase(unique(all(d)), d.end());



int main()
{
	IOS;
	ll n,k,m,i,j,c=0,cs=0,t;
	t=1;

	// cin>>t;
	string s;
	while(t--)
	{
		cin>>n;
		// n=s.length();
		ll a[n];
		map<ll,ll> mp;
		rep(i,n)
		{
			cin>>a[i];
			c+=(mp[i-a[i]]);
			mp[i+a[i]]++;
		}
		
		cout<<c;

		
		cout<<"\n";
	}
	return 0;
}

Measured memory_bytes: 27844
n = int(input())
list = [int(i) for i in input().split()]

count = 0
list_count = []

for i in range(n):
    a = list[i]
    while a % 2 == 0:
        count += 1
        a /= 2
    list_count.append(count)
    count = 0

print(min(list_count))


Measured memory_bytes: 2940
#include <bits/stdc++.h>
//#include <iostream>
//#include <string>
//#include <sstream>
//#include <vector>
//#include <algorithm>
//#include <map>
//#include <set>
//#include <math.h>
//#include <unordered_map>
//#include <queue>
//#include <stack>
//#include <iomanip>

using namespace std;

#define PI 3.141592653589793238462643383279502884
#define Max 100005
#define ll long long
#define mod 1000000007
#define EPS 1E-9



int main()
{
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

    ll w,a,b;
    cin >> w >> a >> b;
    if(a<b)
    {
        if((a+w)<b)
        cout << b-(a+w) << endl;
    else
        cout << 0 << endl;
    }
    else
    {
        if((b+w)<a)
            cout << a-(b+w) << endl;
        else
            cout << 0 << endl;
    }



	return 0;
}


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

cset = [chr(ord('a')+i) for i in range(N)]
sset = ['a'] * N
def rec(di, usedci):
    if di >= len(sset):
        print(''.join(sset))
        return
    for i in range(usedci+1):
        sset[di] = cset[i]
        rec(di+1, usedci)
    sset[di] = cset[usedci+1]
    rec(di+1, usedci+1)

rec(1, 0)


Measured memory_bytes: 4340
#!/usr/bin/env python3

import sys
import math
# from string import ascii_lowercase, ascii_upper_case, ascii_letters, digits, hexdigits
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from operator import itemgetter              # itemgetter(1), itemgetter('key')
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product, permutations  # product(iter, repeat=n), permutations(iter[,r])
# from itertools import combinations, combinations_with_replacement
# from itertools import accumulate             # accumulate(iter[, f])
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict (e.g. list is not allowed)
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from copy import deepcopy                    # to copy multi-dimentional matrix without reference
# from fractions import gcd                    # for Python 3.4 (previous contest @AtCoder)


def main():
    mod = 1000000007                # 10^9+7
    inf = float('inf')              # sys.float_info.max = 1.79...e+308
    # inf = 2 ** 64 - 1               # (for fast JIT compile in PyPy) 1.84...e+19
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())
    
    
    n = ii()
    L = [ii() for _ in range(5)]
    min_ind = 0
    minimum = inf
    for i in range(5):
        if L[i] < minimum:
            min_ind, minimum = i, L[i]
    print(min_ind + math.ceil(n / minimum) + (4 - min_ind))

if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
const int INF = 100000000;
const int MAX_N = 100;
typedef pair<int , int> P;
typedef long long ll;
 
int main () {
  double R, ans;
  cin >> R;
  ans = 2 * R * M_PI;
  printf("%lf\n", ans);
  return 0;
}

Measured memory_bytes: 3788
#include<cstdio>
#include<algorithm>
using namespace std;
int a[100005];
int h[100005];
int main(void)
{
    int n;
    scanf("%d" ,&n);
    for(int i=1;i<=n;i++)
        scanf("%d" ,&h[i]);
    a[n]=0;
    for(int i=n-1;i>=1;i--)
    {
        if(h[i]>=h[i+1])
            a[i]=a[i+1]+1;
        else a[i]=0;
    }
    printf("%d" ,*max_element(a+1,a+n+1));
    return 0;
}


Measured memory_bytes: 896
#include <cstdio>
#include <cctype>
#include <utility>
#include <string>
#include <vector>
#include <climits>
using namespace std;

const auto gcu = getchar_unlocked;
const auto pcu = putchar_unlocked;
#define _DEF(r, n, ...) inline r n(__VA_ARGS__) noexcept
#define _T template <typename T>
#define _HT template <typename H,typename... T>
_T _DEF(T,in,int c){T n=0;int m=1;while(isspace(c)){c=gcu();}if(c=='-')m=-1,c=gcu();
	do{n=10*n+(c-'0'),c=gcu();}while(c>='0'&&c<='9');return m*n;}
_DEF(int, in){return in<int>(gcu());}
#define _SCAN(...) _DEF(bool,scan,__VA_ARGS__)
_T _SCAN(T &n){int c=gcu();return c==EOF?false:(n=in<T>(c),true);}
_DEF(bool, scan, char &c){c=gcu();gcu();return c!=EOF;}
#ifdef _GLIBCXX_STRING
_SCAN(string &s){int c;s="";
	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=c;}}
#endif
_HT _SCAN(H &h,T&&... t){return scan(h)&&scan(t...);}
#define _OUT(...) _DEF(void,out,__VA_ARGS__)
#define _OUTL(...) _DEF(void,outl,__VA_ARGS__)
_OUT(bool b){pcu('0'+b);}
_OUT(const char *s){while(*s)pcu(*s++);}
_OUT(char c){pcu(c);}
#ifdef _GLIBCXX_STRING
_OUT(string s){for(char c:s)pcu(c);}
#endif
_T _OUT(T n){static char b[20];char *p=b,m=n<0?pcu('-'),-1:1;
	if(!n)*p++='0';else while(n)*p++=n%10*m+'0',n/=10;while(p!=b)pcu(*--p);}
_OUTL(){out('\n');}
#ifdef _GLIBCXX_VECTOR
_T _OUT(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);outl();}
#endif
_HT _OUT(H&& h, T&&... t){out(h);out(move(t)...);}
template <typename... T> _OUTL(T&&... t){out(move(t)...);outl();}
struct range{
	int e,b=0,s=1;
	range(int _b,int _e,int _s):e(_e),b(_b),s(_s){}
	range(int _b,int _e): e(_e), b(_b){}
	range(int _e):e(_e){}
	struct it {
		int v, s;
		it (int _v, int _s) : v(_v), s(_s) {}
		operator int()const{return v;}
		operator int&(){return v;}
		int operator*()const{return v;}
		it& operator++(){v+=s;return *this;}
	};
	it begin() {return {b, s};}
	it end() {return {e, s};}
};

using V = vector<int>;

int main() {
	for (int n, k; n = in(), k = in();) {
		vector<V> dp(n, V(n, INT_MAX / 2));
		range r{n};
		while (k--) {
			int o{in()}, s{in() - 1}, e{in() - 1};
			if (o) {
				int w = in();
				if (dp[s][e] > w) {
					dp[s][e] = dp[e][s] = w;
					for (int k: {s, e})
						for (int i : r)
							for (int j : range(i + 1, n))
								dp[i][j] = dp[j][i] = min(dp[i][j], dp[i][k] + dp[k][j]);
				}
			} else
				outl(dp[s][e] < INT_MAX / 2 ? dp[s][e] : -1);
		}
	}
}


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

#define debug(s) cout << #s << " = " << s << endl
#define all(v) (v).begin(), (v).end()
#define mem(a,val) memset(a, val, sizeof a)

#define maxn 100010
#define INF 1e15
#define ff first
#define ss second
#define endl '\n'
typedef long long ll;

int n;
vector<pair<int,int>> adj[16];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0); 
  cin >> n;
  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    for (int j = 0; j < a; ++j) {
      int x, y;
      cin >> x >> y;
      adj[i].push_back({x - 1, y});
    }
  }
  //for (int i = 0; i < n; ++i) {
    //debug(i);
    //for (auto p: adj[i]) {
      //cout << p.ff << " " << p.ss << endl;
    //}
  //}
  int ans = 0;
  for (int msk = 0; msk < (1 << n); ++msk) {
    bool flag = true;
    //cout << "-------------------------" << endl;
    for (int i = 0; i < n; ++i) {
      if (!flag) break;
      if (msk & (1 << i)) {
        //cout << "Here" << endl;
        //debug(i);
        for (auto p: adj[i]) {
          int x = p.ff;
          int y = p.ss;
          if ((bool)(msk & (1 << x)) != y) {
            //debug(i);
            //debug(x);
            //debug(y);
            //debug((bool)(msk & (1 << x)));
            //debug(msk);
            flag = false;
            break;
          } 
        }
      }
    }
    if (flag) ans = max(ans, __builtin_popcount(msk));
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
   int i,j,k,m,s;

   m=99;
   for (s=i=0;i<5;i++) {
      scanf("%d",&j);
      if (j%10>m || j%10==0) {
         k=(j+9)/10;
         s+=k*10;
      } else {
         if (m!=99 && m>0) s+=10;
         m=j%10;
         k=j/10;
         s+=k*10;
      }
   }
   if (m==99) m=0;
   printf("%d\n",s+m);
   return 0;
}


Measured memory_bytes: 128
import java.util.*;
import java.io.*;

class Main {

	static class Edge {
		int cost;
		int node1;
		int node2;

		Edge(int cost,int node1,int node2){
			this.cost = cost;
			this.node1 = node1;
			this.node2 = node2;
		}
	}

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(br.readLine());
		List<List<Edge>> Ed = new ArrayList<List<Edge>>();

		for (int i=0; i<n; i++) {

			String line = br.readLine();
			String[] str = line.split(" ");
			List<Edge> list = new ArrayList<Edge>();

			for (int j=2; j<str.length; j+=2) {

				int cost = Integer.parseInt(str[j+1]);
				int node = Integer.parseInt(str[j]);
				Edge edge = new Edge(cost,i,node);

				list.add(edge);
			}
			Ed.add(list);
		}

		boolean[] flag = new boolean[n];
		int[] d = new int[n];
		boolean fin = false;

		Arrays.fill(d,-1);
		flag[0] = true;
		d[0] = 0;
		int now = 0;

		while (!fin) {
			for (int i=0; i<Ed.get(now).size(); i++) {
				int to = Ed.get(now).get(i).node2;
				if (!flag[to]) {
					if (d[to] == -1)
						d[to] = d[now]+Ed.get(now).get(i).cost;
					else
						d[to] = Math.min(d[to],d[now]+Ed.get(now).get(i).cost);
				}
			}

			fin = true;
			int min = Integer.MAX_VALUE;

			for (int i=0; i<n; i++) {
				if (min > d[i] && d[i] != -1 && !flag[i]) {
					min = d[i];
					now = i;
					fin = false;
				}
			}
			flag[now] = true;
		}

		for (int i=0; i<n; i++) {
			System.out.println(i+" "+d[i]);
		}

		br.close();
	}
}

Measured memory_bytes: 80632
//testing unlocked
#include <bits/stdc++.h>
#define gc getchar()
#define pc(x) putchar(x)
template<typename T> void scan(T &x){x = 0;register bool _=0;register T c=gc;_=c==45;c=_?gc:c;while(c<48||c>57)c=gc;for(;c<48||c>57;c=gc);for(;c>47&&c<58;c=gc)x=(x<<3)+(x<<1)+(c&15);x=_?-x:x;}
template<typename T> void printn(T n){register bool _=0;_=n<0;n=_?-n:n;char snum[65];int i=0;do{snum[i++]=n%10+48;n/= 10;}while(n);--i;if (_)pc(45);while(i>=0)pc(snum[i--]);}
template<typename First, typename ... Ints> void scan(First &arg, Ints&... rest){scan(arg);scan(rest...);}
template<typename T> void print(T n){printn(n);pc(10);}
template<typename First, typename ... Ints> void print(First arg, Ints... rest){printn(arg);pc(32);print(rest...);}
 
using namespace std;
 
 
int main(){
    
    int a, b;
    scan(a, b);
    if(a > 9 || b > 9){
        return 0*puts("-1");
    }
    print(a*b);
    
    return 0;
}

Measured memory_bytes: 764
n,k = map(int,input().split())
lis = list(map(int,input().split()))
for i in range(n):
    lis[i] = (lis[i]+1)/2
now = sum(lis[:k])
ans = now
for i in range(n-k):
    now -= lis[i]
    now += lis[i+k]
    ans = max(now,ans)
print(ans)

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

using namespace std;

const double INF = 1e9;
double cost[6000];

double calc(int i, int j, int k) {
    return (380 * ((i / 5) * 5 * 0.8  + (i % 5)) +
            550 * ((j / 4) * 4 * 0.85 + (j % 4)) +
            850 * ((k / 3) * 3 * 0.88 + (k % 3)));
}

int main(void) {
    fill(cost, cost + 6000, INF);

    int n = 5000, sum;
    for (int i = 0; 200 * i <= n; i++)
        for (int j = 0; 300 * j <= n - 200 * i; j++)
            for (int k = 0; 500 * k <= n - i * 200 - j * 300; k++) {
                sum = 200 * i + 300 * j + 500 * k;
                cost[sum] = min(cost[sum], calc(i, j, k));
            }
    
    while (scanf("%d", &n), n)
        printf("%d\n", (int)cost[n]);

    return 0;
}


Measured memory_bytes: 3228
#include <bits/stdc++.h>
#include <string>
using namespace std;
void init(){
    cin.tie(0);
    cin.sync_with_stdio(0);
}

int main() {
    init();
    int n,m,q,a,b;
    cin>>n>>m>>q;
    long long arr[502][502]={0};
    for(int i=0;i<m;i++){
        cin>>a>>b;
        arr[a][b]++;
    }
    for(int i=1;i<=n;i++){
      for(int j=1;j<=n;j++){
        arr[i][j]+=arr[i][j-1];
      }}

       for(int i=n;i>=1;i--){
      for(int j=1;j<=n;j++){
        arr[i][j]+=arr[i+1][j];
      }}
     for(int i=0;i<q;i++){
        cin>>a>>b;
        cout<<arr[a][b]<<endl;
     }}





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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define repr(i,n) for(int i=(int)(n-1);i>=0;i--)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout << #x" = " << x << endl
#define print(x) cout << x << endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<int, P> PIP;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;
typedef set<int> S;

#define INF INT_MAX/3
#define MAX_N 1000000001

struct State {
  int v, c, rest;
};

bool operator<(const State &a, const State &b) {
  return a.c > b.c;
}

int main(){
  cin.sync_with_stdio(false);
  int n, m, l;
  while(cin >> n >> m >> l, n) {
    P cost[n][n];
    rep(i, n)rep(j, n) cost[i][j] = P(INF, INF);
    rep(i, m) {
      int u, v, len, num;
      cin >> u >> v >> len >> num; u--, v--;
      cost[u][v] = cost[v][u] = P(len, num);
    }

    priority_queue<State> q;
    q.push(State{0, 0, l});
    bool visited[n][l + 1] = {};
    int ans = 0;
    while(!q.empty()) {
      State s = q.top(); q.pop();

      if (s.v == n - 1) {
        ans = s.c;
        break;
      }

      if (visited[s.v][s.rest]) continue;
      else visited[s.v][s.rest] = true;

      rep(i, n) {
        if (cost[s.v][i] != P(INF, INF)) {
          q.push(State{i, s.c + cost[s.v][i].se, s.rest});
          if (cost[s.v][i].fi <= s.rest) q.push(State{i, s.c, s.rest - cost[s.v][i].fi});
        }
      }
    }

    cout << ans << endl;
  }

  return 0;
}

/*
12 11 55
2 4 22 86
4 9 72 80
6 11 73 85
7 8 93 98
5 11 4 85
8 10 20 41
5 12 74 41
6 7 3 9
1 3 64 71
2 10 27 43
3 9 16 70
*/

Measured memory_bytes: 3500
#include<bits/stdc++.h>
#define mod 998244353ll
#define LL long long
using namespace std;
long long Pow[200200];
long long Fac[200200];
LL e_gcd(LL a, LL b, LL &x, LL &y){  
	if(b == 0){  
        x = 1; y = 0;  
        return a;  
    }  
    LL ans = e_gcd(b, a%b, y, x);  
    y -= x*(a/b);  
    return ans;  
}  
LL clac(LL a, LL m){  
        LL x, y;  
        e_gcd(a, m, x, y);  
        return (m + x%m)%m;  
    }  
    LL C(int n, int m){  
        return Fac[n]*clac(Fac[m]*Fac[n-m]%mod, mod)%mod;  
    }  
int main()
{
	Pow[0]=1ll;
	Fac[0]=1ll;
	long long N,M,K;
	cin>>N>>M>>K;
	for(int i=1;i<=N;i++)
	{
		Pow[i]=Pow[i-1]*(M-1)%mod;
		Fac[i]=Fac[i-1]*i%mod;
	}
	long long Ans=0;
	for(int i=N;i>=N-K;i--)
	{
		long long Tmp=Pow[i-1]*M%mod;
		//cout<<"C("<<N-1<<","<<N-i<<"):"<<C(N-1,N-i)<<endl;
		Tmp=Tmp*C(N-1,N-i)%mod;
		Ans=(Ans+Tmp)%mod;
	}
	cout<<Ans<<endl;
	return 0;
}

Measured memory_bytes: 6696
#pragma GCC optimize "-O3"
#pragma GCC optimize("Ofast")
#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define LSOne(S) (S & (-S))
#define ll long long
#define two pair<int,int>
#define twol pair<ll,ll>
#define four pair<two,two>
#define pb push_back
#define mk make_pair
#define y1 y1922
#define INF 1000000000000000000
#define P 1000000007
#define lmax 1000000000
#define nn 1000003
#define ff first.first
#define fs first.second
#define sf second.first
#define ss second.second
#define f first
#define s second
#define vi vector<int>
#define vll vector<ll>
#define vtwo vector<two>
#define ALL(container) (container).begin(), (container).end()
#define sz(container) (int)(container.size())
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define mid(a,b) (a+b>>1)
#define minN 0
#define maxN 10000000
#define na(x) ((x)<P?(x):(x)-P)
#define ab(a) (-(a)<(a)?(a):-(a))
#define FAST std::ios::sync_with_stdio(false)
#define xRand mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define rnd rng
#define IT iterator
typedef
tree<
  int,// aq pair<int,int> shegidzlia
  null_type,
  less/*_equal*/<int>,// aqac
  rb_tree_tag,
  tree_order_statistics_node_update>
ordered_set;
// '_equal' mashin ginda roca multiset gchirdeba
template<class key, class value,class cmp = std::less<key>>
using ordered_map = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;
ordered_map<int, int> my_map;
inline int rin(){
	int x=0,w=1;char ch=getchar();
	while ((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
	if (ch=='-') w=0,ch=getchar();
	while (ch>='0'&&ch<='9') x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
	return w?x:-x;
}
inline int bin(){
	int x=0;char ch=getchar();
	while (ch<'0'||ch>'9') ch=getchar();
	while (ch>='0'&&ch<='9') x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
	return x;
}
string s;
int o;
int main(){FAST;xRand;
cin>>s;
for(int i=0;i<sz(s);i++){
	if(s[i]=='x') o++;
}
if(o<8){
	cout<<"YES"<<endl;
}else{
	cout<<"NO"<<endl;
}
}
/*

                   *         *
                  * *       * *
                 *   *     *   *
                *     *   *     *
                 *   *   * *   *
                  *   *   *   *
                   *   * *   *
                     *  *   *
					   *  *


*/






Measured memory_bytes: 256
#include <stdio.h>

int main()
{
        int num;
        int record[100000];
        int sequence[100000];
        int i;

        scanf("%d",&num);

        for(i=1; i<=num; i++)
        {
                scanf("%d",&record[i-1]);
                sequence[record[i-1]-1]=i;
        }
        for(i=0; i<num; i++)
        {
                printf("%d ",sequence[i]);
        }
        return 0;

}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
#define MOD 1000000007
int gcd(int a, int b) {
	if (a % b == 0)return b;
	return gcd(b,a%b);
}
int lcm(int a, int b) {
	return a / gcd(a, b) * b;
}
signed main() {
	int n;
	int a[11];
	cin >> n;
	rep(i, n)cin >> a[i];
	int ans = a[0];
	rep(i, n)ans = lcm(ans, a[i]);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3080
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		final Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();
		int e = sc.nextInt();
		int f = sc.nextInt();
		ArrayList<Integer> water = new ArrayList<>();
		for(int i = 0; i < 40; i++) {
			for(int j = 0; j < 40; j++) {
				if(100*a*i+100*b*j > f) {
					break;
				} else {
					water.add(100*a*i+100*b*j);
				}
			}
		}
		ArrayList<Integer> suger = new ArrayList<>();
		for(int i = 0; i < 3010; i++) {
			for(int j = 0; j < 3010; j++) {
				if(c*i+d*j > f) {
					break;
				} else {
					suger.add(c*i+d*j);
				}
			}
		}//入力終わり
		
		int zentai = 1<<20;
		int suge = 0;
		for(int i = 0; i < water.size(); i++) {
			for(int j = 0; j < suger.size(); j++) {
				if(water.get(i) * e >= suger.get(j)*100 && water.get(i)+suger.get(j)<=f) {
					if(suger.get(j) * zentai > (water.get(i)+suger.get(j))*suge) {
						
						zentai = water.get(i)+suger.get(j);
						suge = suger.get(j);
					}
				}
			}
		}
		if(zentai==1<<20) System.out.println(100*a+" "+0);
		else System.out.println(zentai+" "+suge);
	}
}

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

#define F first
#define S second 
#define mp make_pair
#define pb push_back
#define pf push_front
#define speed_up ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define sz(x) (int)x.size()
#define szc(x) (int)strlen(x)
#define all(x) x.begin(), x.end()
#define debug cerr << "OK\n";
#define ub upper_bound
#define lb lower_bound 
#define y1 y_1
#define x1 y_2
 
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef set <int> si;
typedef set <ll> sll;
typedef multiset <int> msi;
typedef multiset <ll> msll;
typedef map <int, int> mi;
typedef map <ll, int> mll;
 
const int N = 200 + 20;
const int M = 1e6 + 2;
const int mod = 998244353;
const int inf = 2e9 + 3;
const ll INF = 1e16;

void data() {
	#ifdef PC
		freopen("main.in", "r", stdin);
		freopen("main.out", "w", stdout);
	#endif
}

/*
	BIN POISK EBANA V ROT
	DP EBANA V ROT
	DO EBANA V ROT
*/

string s, t;
int ans = inf;

int main() {
	data();
	cin >> s >> t;
	for (int i = 0; i + sz(t) - 1 < sz(s); ++i) {
		int cnt = 0;
		for (int j = 0; j < sz(t); ++j) {
			cnt += s[i + j] != t[j];
		}
		ans = min(ans, cnt);
	}
	cout << ans;
}

Measured memory_bytes: 3588
#include<stdio.h>
int main(){
  int n,m,max=0,mi=1,i,a,b;
  int w[1000001]={0};
  scanf("%d %d",&n,&m);
  while(m--){
    scanf("%d %d",&a,&b);
    w[a]+=b;
    if(b>0){
      if(max<w[a]){
	max=w[a];
	mi=a;
      }
      if(max==w[a]&&mi>a)mi=a;
    }
    else{
      max=0;
      mi=1;
      for(i=1;i<=n;i++){
	if(max<w[i]){
	  max=w[i];
	  mi=i;
	}
      }
    }
    printf("%d %d\n",mi,max);
  }
  return 0;
}

Measured memory_bytes: 4512