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

using namespace std;

typedef long long ll;

struct node {int p; int q;};
char ara[22][22];
int row, col;
int Dx[]= {-1, 1, 0, 0};
int Dy[]= {0, 0, 1, -1};

int bfs (int x1, int x2, int d1, int d2) {
   queue <node > qu;
   bool visited[row][col];
   for (int i = 0; i < row; i++)
      memset (visited[i], 0, sizeof (visited[i]));
   int level[row][col];
   for(int i = 0; i < row; i++) {
     for(int j = 0; j < col; j++) {
       level[i][j] = 100000000;
     }
   }
   node u;
   u.p = x1; u.q = x2;
   qu.push (u);
   visited[u.p][u.q] = 1;
   level[x1][x2] = 0;
   while (qu.empty() == 0) {
      u = qu.front(); qu.pop();
      //printf ("Out: %d %d\n", u.p, u.q);
      for (int i = 0; i < 4; i++) {
         node v;
         v.p = u.p + Dx[i];
         v.q = u.q + Dy[i];
         if (!visited[v.p][v.q]  && ara[v.p][v.q] != '#' && 0 <= v.p && v.p < row && 0 <= v.q && v.q < col) {
            visited[v.p][v.q] = 1;
            level[v.p][v.q] = min(level[v.p][v.q], level[u.p][u.q] + 1);
            qu.push (v);
         }
      }
   }
   return level[d1][d2];
}

int main() {
  cin >> row >> col;
  for(int i = 0; i < row; i++) {
    for(int j = 0; j < col; j++) {
      cin >> ara[i][j];
    }
  }
  int mx = 0;
  for(int i = 0; i < row; i++) {
    for(int j = 0; j < col; j++) {
      for(int p = 0; p < row; p++) {
        for(int q = 0; q < col; q++) {
          if(ara[i][j] == '#' or ara[p][q] == '#') continue;
          int cur = bfs(i, j, p, q);
          if(cur < 100000000) mx = max(mx, cur);
        }
      }
    }
  }
  cout << mx << '\n';
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedList;
import java.util.ListIterator;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
	
	public static final int BEGIN = 6;
	public static final int END = 22;
	
	public static final int MAX = END - BEGIN;
	
	public static final int BIT_MAX = 1 << MAX;
	
	public static final int MAX_G = 100;
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		long[] DP = new long[BIT_MAX];
		
		int[] bits = new int[MAX_G];
		long[] benefits = new long[MAX_G];
		
		while(true){
			final int n = sc.nextInt();
			
			if(n == 0){
				break;
			}
			
			for(int i = 0; i < n; i++){
				final int m = sc.nextInt();
				final int l = sc.nextInt();
				benefits[i] = l;
				bits[i] = 0;
				
				for(int j = 0; j < m; j++){
					final int s = sc.nextInt() - BEGIN;
					final int e = sc.nextInt() - BEGIN - 1;
					
					for(int k = s; k <= e; k++){
						bits[i] |= 1 << k;
					}
				}
			}
			/*
			System.out.println(Arrays.toString(benefits));
			//*/
			
			Arrays.fill(DP, -1);
			DP[0] = 0;
			long max = 0;
			for(int guy = 0; guy < n; guy++){
				final long guy_ben = benefits[guy];
				final int  guy_bit = bits[guy];
				
				for(int bit = BIT_MAX - 1; bit >= 0; bit--){
					if(DP[bit] < 0){
						continue;
					}else if((bit & guy_bit) != 0){
						continue;
					}
					
					DP[bit | guy_bit] = Math.max(DP[bit | guy_bit], DP[bit] + guy_ben);
					max = Math.max(max, DP[bit | guy_bit]);
				}
			}
			/*
			for(int i = 0; i < MAX; i++){
				System.out.println((i + BEGIN) + " : " + Arrays.toString(DP[i]));
			}
			*/
			
			System.out.println(max);
		}
		
	}

}

Measured memory_bytes: 56524
n=int(input())
d = {}
for i in range(n):
    a = str(input())
    a = sorted(a)
    a = tuple(a)
    
    if a in d:
        d[a] +=1
    else:
        d[a] = 1

ans = 0
for k in d:
    v = d[k]
    if v>1:
        ans += (1+v-1)*(v-1)/2
        
print(int(ans))

Measured memory_bytes: 130264
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) 
	{
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		long[] a = new long[n];
		long[] min = new long[n+1];
		long[] max = new long[n+1];
		min[n] = 2;
		max[n] = 2;
		
		for(int i = 0; i < n; i++)
		{
			a[i] = sc.nextLong();
		}
		
		for(int i = n-1; i >= 0; i--)
		{
			//divisor: a[i]
			{
				min[i] = a[i];
				if(min[i] < min[i+1])
				{
					min[i] = (min[i+1]/a[i])*a[i];
					if(min[i]<min[i+1])
						min[i] = (min[i+1]/a[i]+1)*a[i];
				}
				long reser = min[i] - (min[i]%a[i]);
				if(min[i]<min[i+1] || reser < min[i+1] || reser > max[i+1])
				{
					System.out.println(-1);
					return;
				}
			}
			
			max[i] = ((max[i+1]/a[i])*a[i]) + (a[i]-1);
			long reser = max[i] - (max[i]%a[i]);
			if(max[i] < min[i+1] || reser < min[i+1] || reser > max[i+1])
			{
				System.out.println(-1);
				return;
			}
//			System.out.println(min[i] + " " + max[i]);
		}
			
//		System.out.println(Arrays.toString(min));
//		System.out.println(Arrays.toString(max));
		System.out.println(min[0] + " " + max[0]);
	}

}


Measured memory_bytes: 63712
//C
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>


//Hang in there!

using namespace std;


int main() {
	int N, K;
	cin >> N >> K;
	int ans = K;
	for (int i = 1; i < N; i++) {
		ans *= K - 1;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<fstream>
#include<iomanip>
#include<cstdio>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#include<list>
#include<unordered_map>
#include<random>
#include<functional>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define mat vector<vector<ll>>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
// #define int ll
using namespace std;
const ll INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
const ll mod = 998244353;
const ll MAX = 1100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[4] ={1,0,-1,0} , dy[4] ={0,1,0,-1};


ll sumofdigits(ll n){
    int sum =0;
    while(n>0){
        sum += n%10;
        n /=10;
    }
    return sum;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll m,d[200010],c[200010],sum=0,n=0;
    cin>>m;
    rep(i,m){
        cin>>d[i]>>c[i];
        sum+=d[i]*c[i];
        n+=c[i];
    }
    ll ans=n-1;
    ans+=(sum/9)-(sum%9==0);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3328
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author vdewansa
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        DKnapsack1 solver = new DKnapsack1();
        solver.solve(1, in, out);
        out.close();
    }

    static class DKnapsack1 {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int N = in.nextInt();
            int W = in.nextInt();
            int[] w = new int[N + 1];
            int[] v = new int[N + 1];
            for (int i = 1; i <= N; i++) {
                w[i] = in.nextInt();
                v[i] = in.nextInt();
            }

            long[][] best = new long[N + 1][W + 1];
            for (int i = 1; i <= N; i++) {
                for (int j = 1; j <= W; j++) {
                    best[i][j] = best[i - 1][j];
                    if (j - w[i] >= 0) {
                        best[i][j] = Math.max(best[i][j], v[i] + best[i - 1][j - w[i]]);
                    }
                }
            }
            out.println(best[N][W]);
        }

    }
}



Measured memory_bytes: 127060
input = require('fs').readFileSync('/dev/stdin', 'utf8')
lines = input.split('\n')
line = lines.shift().split(' ')
N = line[0] * 1
K = line[1] * 1 

MOD = 1000000007

dp = new Array(N+1).fill(0)
dp[0] = 1

A = []
for (i=0; i<K; i++) {
    A[lines[i] * 1] = true
}

for (i=0; i<N; i++) {
    dp[i+1] += A[i+1] ? 0 : dp[i] % MOD
    dp[i+2] += A[i+2] ? 0 : dp[i] % MOD
}

console.log(dp[N] % MOD)


Measured memory_bytes: 29028
#include<iostream>
#include<vector>
#include <unordered_map>  
#include <algorithm>
#include <functional>
#include <map>
#include <string>
#include <sstream>
#include <cmath>
using namespace std;

int main() {
	int a, b, c, count = 0;
	cin >> a >> b >> c;
	if (a >= b && a >= c) {
		while (a != b && a != c) {
			++count;
			++b;
			++c;
		}
		if (a == b) {
			while (a - 1 >= c) {
				c += 2;
				count++;
			}
			if(a != c){
				count += 1;
			}
		}
		else {
			while (a - 1 >= b) {
				b += 2;
				count++;
			}
			if (a != b) {
				count += 1;
			}
		}
	}
	else if(b >= c) {
		while (b != a && b != c) {
			++count;
			++a;
			++c;
		}
		if (b == a) {
			while (b - 1 >= c) {
				c += 2;
				count++;
			}
			if (b != c) {
				count += 1;
			}
		}
		else {
			while (b - 1 >= a) {
				a += 2;
				count++;
			}
			if (b != a) {
				count += 1;
			}
		}
	}
	else {
		while (c != a && c != b) {
			++count;
			++a;
			++b;
		}
		if (c == a) {
			while (c - 1 >= b) {
				b += 2;
				count++;
			}
			if (c != b) {
				count += 1;
			}
		}
		else {
			while (c - 1 >= a) {
				a += 2;
				count++;
			}
			if (c != a) {
				count += 1;
			}
		}
	}
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 256
s = input()
start = -1
for i in range(len(s)):
    if s[i] == "A":
        start = i
        break
end = len(s)
for i in range(len(s) - 1, -1, -1):
    if s[i] == "Z":
        end = i
        break
        
print(end - start + 1)

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

public class Main {
    public static void main(String[] args) {
        FastScanner fs = new FastScanner();
        long a = fs.nextLong();
        long b = fs.nextLong();
        long c = gcd(a,b);
        long r = c;
        ArrayList<Long> pf = new ArrayList<Long>();
        for(long i=2; i*i<=r; i++) {
            if (c%i != 0) continue;
            while(c%i == 0) {
                c /= i;
                if(!(pf.contains(i))) {
                    pf.add(i);
                }
            }
        }
        if(c != 1) {
            if(!(pf.contains(c))) {
                pf.add(c);
            }
        }
        System.out.println(pf.size()+1);
    }

    public static long gcd(long a,long b) {
        long temp;
        while((temp = a%b) != 0) {
            a = b;
            b = temp;
        }
        return b;
    }
}
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;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
 
    private int readByte() {
        if (hasNextByte())
            return buffer[ptr++];
        else
            return -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());
    }
}


Measured memory_bytes: 21588
#include <bits/stdc++.h>
#include <queue>
using namespace std;
using ll = long long;
#define MAX_N 100000
#define MAX_M 100000
const int MAX = 100100;
const int MOD = 1000000007;
#define vec vector<int>
#define vecll vector<ll>
#define vecllvec vector<vector<ll>>
#define vecb vector<bool>
#define vecBvec vector<vector<bool>>
#define vecst vector<string>
#define vecch vector<char>
#define vecd vector<double>
#define vecvec vector<vector<int>>
#define vecDvec vector<vector<double>>
#define vecHvec vector<vector<char>>
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, m, n) for (int i = m; i < (int)n; ++i)
#define print(x) cout << x << endl
#define INF 1e+9
using P = pair<int, int>;
const string YES = "Yes";
const string NO = "No";
#define MAX_V 1000
#define PI 3.141592653589793
// cout << setprecision(15) << std::fixed;

// テレンス「もしかしてACですかーッ!?」　ジョセフ「Yse! Yse! Yse! Oh~MyGod」

int main()
{
  vector<queue<int>> vect(3);
  string s = " ";
  for (int i = 0; i < 3; i++)
  {
    cin >> s;
    for (int j = 0; j < s.size(); j++)
    {
      // print(s[j]);
      int n = 0;
      if (s[j] == 'a')
      {
        n = 0;
      }
      else if (s[j] == 'b')
      {
        n = 1;
      }
      else
      {
        n = 2;
      }
      vect[i].push(n);
    }
  }

  int now = vect[0].front();
  vect[0].pop();
  while (true)
  {
    int bnow = now;
    if (vect[now].empty())
    {
      if (now == 0)
      {
        print("A");
      }
      else if (now == 1)
      {
        print("B");
      }
      else
      {
        print("C");
      }
      break;
    }
    now = vect[now].front();
    vect[bnow].pop();
  }
}

Measured memory_bytes: 3624
X, N = map(int, input().split())

def Base_10_to_n(X, n):
    X_dumy = X
    out = ''
    while X_dumy>0:
        out = str(X_dumy%n)+out
        X_dumy = int(X_dumy/n)
    return out

 
aws = Base_10_to_n(X,N)
a = len(aws)
print(a)

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

using namespace std;

#define rep(i, n) for(int i = 0; i < static_cast<int>(n); ++i)
#define per(i, n) for(int i = static_cast<int>(n)-1; i >= 0; --i)
#define eee(a) (cerr << (#a) << ": " << (a) << endl);
#define ppp(a) (cout << (a) << endl); 
#define cop(a) for(auto x:(a)){cout << x << endl;}

using ll = long long;

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

constexpr char sp = ' ';
constexpr ll MOD = 1e9+7;
constexpr ll Mod = 998244353;
constexpr int INF = 1e9;
constexpr ll LINF = 1e18;
constexpr double phi = (1+sqrt(5))/2;
constexpr double pi = 3.14159265358979323846264338327950288;
inline ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
inline ll lcm(ll a, ll b){return a/gcd(a,b)*b;}
inline ll inverse(ll n, ll m=MOD){ll a=n,b=m,x=1,y=0;while(b){ll t=a/b;a-=t*b;swap(a,b);x-=t*y;swap(x,y);}return (a%m+m)%m;}
inline void Yes(){puts("Yes");}
inline void No(){puts("No");}
inline void Judge(bool b){b?Yes():No();}
inline void YES(){puts("YES");}
inline void NO(){puts("NO");}
inline void JUDGE(bool b){b?YES():NO();}
inline ll powmod(ll b, ll e, ll m=MOD){ll r=1;while(e>0){if(e&1)r=(r%m)*(b%m)%m;b=(b%m)*(b%m)%m;e>>=1;}return r;}
inline double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));}
inline double d2r(double d){return d*pi/180;}
inline double r2d(double r){return r*180/pi;}

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
    s<<'[';for(size_t i=0;i<v.size();++i){s << v[i];if(i < v.size()-1) s << ", ";}s<<']';return s;
}


int main(){
    cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(15);
    
    
    int n;
    cin >> n;
    vector<int> h(n);
    vector<int> dp(n+10, INF);
    rep(i, n) cin >> h[i];
    dp[0] = 0;
    for(int i = 0; i < n; ++i){
        if(i+2 < n) chmin(dp[i+2], dp[i] + abs(h[i]-h[i+2]));
        if(i+1 < n) chmin(dp[i+1], dp[i] + abs(h[i]-h[i+1]));
    }
    cout << dp[n-1] << endl;
    
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m;
  cin>>n>>m;
  vector<int> food(m);
  int cnt=0;
  for(int i=0;i<n;i++){
    int k;
    cin>>k;
    for(int j=0;j<k;j++){
      int fav;
      cin>>fav;
      food.at(fav-1)++;
    }
  }
  for(int i=0;i<m;i++){
    if(food.at(i)==n)cnt++;
  }
  cout<<cnt<<endl;
}

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

LL cost[15][15];

int main(){
	ios_base::sync_with_stdio(0);
	
	int h, w;
	LL ans=0;
	cin >> h >> w;
	for(int i=0; i<10; i++){
		for(int j=0; j<10; j++)
			cin >> cost[i][j];
	}
	
	//floyd warshall
	for(int k=0; k<10; k++){
		for(int i=0; i<10; i++){
			for(int j=0; j<10; j++){
				cost[i][j]=min(cost[i][j], cost[i][k]+cost[k][j]);
			}
		}
	}
	
	for(int i=0; i<h; i++){
		for(int j=0; j<w; j++){
			int in;
			cin >> in;
			if(in > -1)
				ans+=cost[in][1];
		}
	}
	
	cout << ans << "\n";
	
	return 0;
}

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

int main() {
    int i, j, k, N = 0;
    vector<vector<int> > vec;
    int arr[2];

    do {
        cin >> arr[0] >> arr[1];
        vec.push_back(vector<int>(arr, (arr+sizeof(int))));
        ++N;
    } while(arr[0] != 0 && arr[1] != 0);

    for(i=0; i<(N-1); ++i) {
        for(j=0; j<vec[i][0]; ++j) {
            for(k=0; k<vec[i][1]; ++k) {
                if((j+k)%2 == 0) {
                    cout << '#';
                }
                else {
                    cout << '.';
                }
            }
            cout << endl;
        }
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 3116
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<map>
using namespace std;
#define ll long long
#define pb push_back
#define pll pair<ll,ll> 
#define mll map<ll,ll>
#define pii pair<int,int>
#define rep(i,n) for(int i=0; i<n; i++)
#define All(x,v) for(auto x:v)
#define arrin(a,n) ll a[n]; rep(i,n) cin>>a[i]
#define vi vector<int>
#define nl "\n"
#define print(arr) All(x,arr) cout<<x<<" "; cout<<nl
#define sz(x) (int)x.size()
#define all(v) v.begin(),v.end()
#define ing(m,ad) rep(i,m){ int u,v; cin>>u>>v; u--;v--; ad[u].pb(v); ad[v].pb(u);}
#define vdsort(v) sort(v.begin(),v.end(),greater<int>())
#define F first
#define S second
#define mod 1000000007
const int MAXN=100005;
int spf[MAXN];
ll fac1[MAXN],fac2[MAXN],inv[MAXN];
ll gcd(ll x, ll y){ return y?gcd(y,x%y):x; }

void sieve(){  
    spf[1] = 1; 
    for (int i=2; i<MAXN; i++)  spf[i] = i; 
    for (int i=4; i<MAXN; i+=2) spf[i] = 2; 
    for (int i=3; i*i<MAXN; i++) { 
        if (spf[i] == i) 
            for (int j=i*i; j<MAXN; j+=i) 
                if (spf[j]==j)  spf[j] = i; 
    } 
} 
vector<int> getFactorization(int x){
    vector<int> ret; 
    while (x != 1) { 
        ret.push_back(spf[x]); 
        x = x / spf[x]; 
    } 
    return ret; 
}

ll exp(ll n, ll m){
    ll a = 1;
    while (m){
        if (m & 1) a = (a * n % mod) % mod;
        m /= 2;
        n = (n*n) % mod;
    }
    return a;
}

void pre(){
    fac1[0]=fac2[0]=inv[1]=1;
    for(int i=1;i<MAXN;i++){
        fac1[i]=(fac1[i-1]*i)%mod;
        if(i>1) inv[i]=( mod - ((ll)(mod/i)*inv[mod%i])%mod ) %mod;
    }
    for(int i=1;i<MAXN;i++) fac2[i]=(fac2[i-1]*inv[i])%mod;
}
ll C(int n,int k){
    if(n<k) return 0;
    return ((fac1[n]*fac2[n-k]%mod)*fac2[k]%mod);
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    // freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
    ll n,t=1;
    // cin>>t;
    while(t--){
        cin>>n;
        ll val=7;
        bool ok=1;
        rep(i,n){
            if(val%n==0){
                cout<<i+1<<nl; ok=0;
                break;
            }
            val=(val*10+7)%n;
        }
        if(ok) cout<<"-1\n";
    }
    return 0;
}

Measured memory_bytes: 3152
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct node {
    char ch[201];
    struct node *next;
} node;

void func(char *dst, const int n)
{
    int i, j;
    char src[201];

    strcpy(src, dst);

    for( i = 0, j = n; src[j]; ++i, ++j ) //残ったカード
        dst[i] = src[j];

    for( j = 0; j < n; ++i, ++j ) //取り出したカード
        dst[i] = src[j];

    dst[i] = '\0';
}

int main()
{
    int i;

    node *head = NULL, *cur = NULL;
    while( 1 ){
        node *new = (node *)malloc(sizeof(node));
        scanf("%s", new->ch);
        if( new->ch[0] == '-' ) break;
        new->next = NULL;

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

        int h;
        for( i = 0; i < m; ++i ){
            scanf("%d", &h);
            func(new->ch, h);
        }

        if( head == NULL ) head = new;
        else cur->next = new;
        cur = new;
    }

    cur = head;
    while( cur ){
        printf("%s\n", cur->ch);
        cur = cur->next;
    }

    return 0;
}

Measured memory_bytes: 592
K=((N=2*gets.to_i)**0.5).to_i
s=[[]]
t=0
K.times{|i|
	u=t+1
	s.map{|s|s<<t+=1}
	s<<[*u..t]
}
puts K*-~K==N ? [:Yes,K+1,s.map{|s|[K,*s]}]: :No

Measured memory_bytes: 9084
#include <bits/stdc++.h>
#define N 111111
#define M 444444

using namespace std;

struct Myqueue{
  int A[N],f,b;
  Myqueue(){
    f=b=0;
    memset(A,0,sizeof A);
  }
  bool empty(){return f==b;}
  void push(int a){A[b]=a;b++;}
  void pop(){f++;}
  int front(){return A[f];}
}q;

struct RD{
  int f,t,next;
}rds[M];

int pn,en,fl[N],eid=0,ans[N];

void add(int f,int t){
  rds[eid].f=f;
  rds[eid].t=t;
  rds[eid].next=fl[f];
  fl[f]=eid;
  eid++;
}
void bfs(){
  q.push(1);
  while(!q.empty()){
    int f=q.front();q.pop();
    for(int i=fl[f];i!=-1;i=rds[i].next){
      if(!ans[rds[i].t]){
        ans[rds[i].t]=f;
        q.push(rds[i].t);
      }
    }
  }
}
int main(){
  memset(fl,-1,sizeof fl);
  cin.sync_with_stdio(0);
  cin>>pn>>en;
  int a,b;
  for(int i=1;i<=en;i++){
    cin>>a>>b;
    add(a,b);
    add(b,a);
  }
  bfs();
  for(int i=2;i<=pn;i++){
    if(ans[i]==0){
      cout<<"No"<<endl;
      return 0;
    }
  }
  cout<<"Yes"<<endl;
  for(int i=2;i<=pn;i++){
    cout<<ans[i]<<endl;
  }
}

Measured memory_bytes: 9564
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxN = 2e5 + 10;

int main(){
//  freopen("abc.inp", "r", stdin); freopen("abc.out", "w", stdout);
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  int n, k; cin >> n >> k;
  vector<int> h(n+1);
  for (int i = 1; i <= n; ++i) {
    cin >> h[i];
  }
  int inf = 1 << 30;
  vector<int> dp(n+1, inf);
  dp[1] = 0;
  for (int i = 1; i <= n; ++i) {
    for (int j = i + 1; j <= n && j - i <= k; ++j) {
      dp[j] = min(dp[j], dp[i] + abs(h[i] - h[j]));
    }
  }
  cout << dp[n];
return 0;
}


Measured memory_bytes: 3988
from sys import stdin


def main() -> None:
    n = next_int()
    x = next_int()

    min_m = 10 ** 9
    ans = 0

    for i in range(n):
        m = next_int()
        x -= m
        min_m = min(min_m, m)
        ans += 1

    ans += x // min_m
    print(ans)


def next_int() -> int:
    return int(next_str())


def next_str() -> str:
    result = ""
    while True:
        tmp = stdin.read(1)
        if tmp.strip() != "":
            result += tmp
        elif tmp != '\r':
            break
    return result


if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
<?php
  
  fscanf(STDIN,"%s",$s);

$array = [
'SUN' => '7',
'MON' => '6',
'TUE' => '5',
'WED' => '4',
'THU' => '3',
'FRI' => '2',
'SAT' => '1'
  ];
  
  echo $array[$s];

Measured memory_bytes: 4728
#include<stdio.h>
#include <stdlib.h>
int main()
{
  int N,i;
  char S[100];
  scanf("%d",&N);
  scanf("%s",&S);
  if(N%2==0)
  {
    for(i=0;i<N/2;i++)
    {
     if(S[i]!=S[N/2+i])
     {
       printf("No");
       exit(0);
     }
      
    }
    printf("Yes");
  }
  else
  {
    printf("No");
  }
}
      

Measured memory_bytes: 128
#pragma GCC optimize("Ofast")
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<string>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<math.h>
#include<utility>
using namespace std;
 

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

    int counter = 0;
    int counter_f = 0;

    for(int i=0;i<s.size();i++){
        if(s[i] == 'a'){
            if(counter < a+b) {
                cout << "Yes" << endl;
                ++counter;
            }
            else cout << "No" << endl;
        }
        else if(s[i] == 'b'){
            ++counter_f;
            if(counter < a+b && counter_f <= b) {
                cout << "Yes" << endl;
                ++counter;
            }
            else cout << "No" << endl;
            
        }
        else{
            cout << "No" << endl;
        }
    }
}

Measured memory_bytes: 896
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <limits>
#include <cmath>
#include <iomanip>
#include <functional>
#include <random>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using ll = long long;

int main()
{
    // 整数の入力
    ll a,b;
    cin >> a >> b;
    if (a < b){
        for(int i = 0;i< b;i++){
            cout << a;
        }
        cout << endl;
    }else{
        for(int i = 0;i< a;i++){
            cout << b;
        }
        cout << endl;
    }
   return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  char str[3];
  int count=0;
  for(int i=0;i<3;i++){
    cin>>str[i];
    if(str[i]=='R')count++;
  }
  if((str[0]=='R')&&(str[1]=='S')&&(str[2]=='R'))count=1;
  cout<<count<<endl;
  return 0;
}


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

int main()
{
    int m, f, r, sum;

    while (true)
    {
        cin >> m >> f >> r;
        sum = m + f;

        if (m == -1 && f == -1 && r == -1)
        {
            break;
        }
        else if (sum < 30 || m == -1 || f == -1)
        {
            cout << 'F' << endl;
        }
        else if (sum >= 80)
        {
            cout << 'A' << endl;
        }
        else if (sum >= 65 && sum < 80)
        {
            cout << 'B' << endl;
        }
        else if (sum >= 50 && sum < 65)
        {
            cout << 'C' << endl;
        }
        else if (sum >= 30 && sum < 50)
        {
            if (r >= 50)
            {
                cout << 'C' << endl;
            }
            else
            {
                cout << 'D' << endl;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 3088
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
int A, B, n, cnt = 0;
int P[4010], Q[4010];
char p[4010];
vector<int>G[4010], S;
int Input(){
    cnt++;
    if(cnt > 2*n){
        while(1){}
    }
    char pp[2];
    scanf("%s",pp);
    if(pp[0]=='Y')return 1;
    return 0;
}
void Merge(int a, int b){
    int i;
    for(i=0;i<G[b].size();i++)G[a].push_back(G[b][i]);
}
int Do(vector<int>&V){
    int i, sz = V.size();
    if(sz == 1)return V[0];
    vector<int>Q;
    for(i=0;i<sz-1;i+=2){
        printf("? %d %d\n",V[i],V[i+1]);
        fflush(stdout);
        int t = Input();
        if(t == 0){
            S.push_back(V[i]);
            S.push_back(V[i+1]);
            continue;
        }
        printf("? %d %d\n",V[i+1],V[i]);
        fflush(stdout);
        t = Input();
        if(t == 0){
            S.push_back(V[i+1]);
            continue;
        }
        Merge(V[i],V[i+1]);
        Q.push_back(V[i]);
    }
    if(sz%2 == 0 && Q.empty())return -1;
    if(sz%2==1){
        int t = Do(Q);
        if(t == -1)return V[sz-1];
        S.push_back(V[sz-1]);
        return t;
    }
    return Do(Q);
}
int main(){
    scanf("%d%d",&A,&B);
    if(A <= B){
        printf("Impossible\n");
        fflush(stdout);
        return 0;
    }
    n = A+B;
    int i;
    vector<int>V;
    for(i=0;i<n;i++){
        V.push_back(i);
        G[i].push_back(i);
        p[i]='0';
    }
    int a = Do(V);
    for(i=0;i<G[a].size();i++)p[G[a][i]]='1';
    for(i=0;i<S.size();i++){
        int x = S[i];
        printf("? %d %d\n",a,x);
        fflush(stdout);
        int t = Input();
        if(t == 1){
            for(int j=0;j<G[x].size();j++)p[G[x][j]]='1';
        }
    }
    printf("! %s\n",p);
    fflush(stdout);
}

Measured memory_bytes: 1104
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#define llong long long
#define ldouble long double
#define uint unsigned int
#define ullong unsigned long long
#define udouble unsigned double
#define uldouble unsigned long double
#define modinc(x) {if(x>=P) x-=P;}
#define pii pair<int,int>
#define piii pair<pair<int,int>,int>
#define piiii pair<pair<int,int>,pair<int,int> >
#define pli pair<llong,int>
#define pll pair<llong,llong>
#define Memset(a,x) {memset(a,x,sizeof(a));}
using namespace std;

const int N = 1e5;
struct Edge
{
	int nxt,v; llong w;
} e[(N<<1)+2];
int sz[N+2];
int fe[N+2];
int mxs[N+2];
int fa[N+2];
int cnt[(N<<1)+2];
int n,en,g1,g2;

void addedge(int u,int v,llong w)
{
	en++; e[en].v = v; e[en].w = w;
	e[en].nxt = fe[u]; fe[u] = en;
}

void dfs(int u)
{
	sz[u] = 1;
	for(int i=fe[u]; i; i=e[i].nxt)
	{
		if(e[i].v==fa[u]) continue;
		fa[e[i].v] = u;
		dfs(e[i].v);
		cnt[i] = min(sz[e[i].v],n-sz[e[i].v]);
		sz[u] += sz[e[i].v];
		mxs[u] = max(mxs[u],sz[e[i].v]);
	} mxs[u] = max(mxs[u],n-sz[u]-1);
	if((sz[u]<<1)==n) {g1 = u; g2 = fa[u];}
	else if((mxs[u]<<1)<n) {g1 = u;}
}

int main()
{
	scanf("%d",&n);
	for(int i=1; i<n; i++)
	{
		int x,y; llong z; scanf("%d%d%lld",&x,&y,&z);
		addedge(x,y,z); addedge(y,x,z);
	}
	dfs(1); llong ans = 0ll;
	for(int i=1; i<=en; i++) ans += 2ll*cnt[i]*e[i].w;
	if(g2==0)
	{
		llong tmp = ans;
		for(int i=fe[g1]; i; i=e[i].nxt)
		{
			tmp = min(tmp,e[i].w);
		}
		printf("%lld\n",ans-tmp);
	}
	else
	{
		llong tmp = 0ll;
		for(int i=fe[g1]; i; i=e[i].nxt)
		{
			if(e[i].v==g2) {tmp = e[i].w; break;}
		}
		printf("%lld\n",ans-tmp);
	}
	return 0;
}

Measured memory_bytes: 9600
#include <bits/stdc++.h>
#define INF (1LL<<60)
#define MOD7 1000000007LL
#define PREP(i, s, x) for(ll (i) = (s); (i) < (x); (i) ++)
#define MREP(i, s, x) for(ll (i) = (s); (i) >= (x); (i) --)
#define REP(i, x) PREP(i, 0, x)
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;
template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return 1;}return 0;}
ll llpow(ll a, ll n){ll res=1;REP(_,n){res*=a;}return res;}


int main(){
    ll n;
    string s;
    cin >> n >> s;

    ll ans = 0;
    REP(pin, 1000){
        string pins = "000";
        for (int i = 0; i < 3; i ++){
            pins[2 - i] = (pin / llpow(10, i)) % 10 + '0';
        }
        ll now_k = 0;
        REP(i, n){
            if(s[i] == pins[now_k]){
                now_k++;
                if(now_k >= 3){
                    ans++;
                    break;
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int a,b,c,d,fl;
int main()
{
	scanf("%d %d %d %d",&a,&b,&c,&d);
	while(1)
	{
		if(fl) {a-=d;if(a<=0) {puts("No");return 0;}}
		else {c-=b;if(c<=0) {puts("Yes");return 0;}}
		fl^=1;
	}return 0;
} 

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

using namespace std;
 
int main()
{
    int n, c;
    long long ave = 0;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> c;
        ave += c;
    }
    cout << (int)(ave / n) << endl;
    return 0;
}

Measured memory_bytes: 3008
#include <cstdio>
#include <cstdlib>
#include <cstring>
#define LL long long
using namespace std;

#define N 200010

LL n,ans,a[N];

int main()
{
	scanf("%lld",&n);
	for (LL i=1;i<=n;i++) scanf("%lld",&a[i]);
	a[0] = -1;
	for (LL i=1;i<=n;i++){
		if (a[i]-a[i-1]>1){
			ans = 0;
			break;
		}
		if (a[i]==a[i-1]+1) ans ++;
			else ans+=(LL)(a[i]);
	}
	printf("%lld",ans-(LL)1);
	return 0;
}

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

int main(){
    int h;
    while(cin >> h, h){
        int d[11][6] = {0};
        for(int i = 0; i < h; i++){
            for(int j = 0; j < 5; j++){
                cin >> d[i][j];
            }
        }
        int score = 0;
        bool f = true;
        while(f){
            f = false;
            for(int i = 0; i < h; i++){
                for(int j = 0; j < 5; j++){
                    if(d[i][j] <= 0) continue;
                    int now = d[i][j];
                    int count = 1;
                    for(int k = j + 1; k < 5; k++){
                        if(d[i][k] == now){
                            count++;
                        }else{
                            break;
                        }
                    }
                    if(count >= 3){
                        f = true;
                        score += now * count;
                        for(int k = j; k < j + count; k++){
                            d[i][k] = -1;
                        }
                        break;
                    }
                }
            }
            for(int i = 0; i < 5; i++){
                for(int j = h - 1; j > 0; j--){
                    if(d[j][i] == -1){
                        for(int k = j - 1; k >= 0; k--){
                            if(d[k][i] > 0){
                                swap(d[j][i], d[k][i]);
                                break;
                            }
                        }
                    }
                }
            }
        }
        cout << score << endl;
    }
}

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

#define mod 1000000007

using namespace std;
using ll = long long;

void solve(){
    int place[10];
    bool flag[10];
    string s;
    cin >> s;
    for(int i = 0; i < 5; i++){
        place[i] = -1;
        flag[i] = false;
    }
    for(int i = 0; i < s.size(); i++){
        if(s[i] == 'K' && !flag[0]){
            place[0] = i;
            flag[0] = true;
        }else if(s[i] == 'I' && flag[0] && place[0]+1 == i && !flag[1]){
            place[1] = i;
            flag[1] = true;
        }else if(s[i] == 'H' && flag[1] && place[1]+1 == i && !flag[2]){
            place[2] = i;
            flag[2] = true;
        }else if(s[i] == 'B' && flag[2] && place[2] < i && !flag[3]){
            place[3] = i;
            flag[3] = true;
        }else if(s[i] == 'R' && flag[3] && place[3] < i && !flag[4]){
            place[4] = i;
            flag[4] = true;
        }else if(s[i] == 'A'){
            if(s[i+1] == 'A'){
                cout << "NO" << endl;
                return;
            }
        }else{
            cout << "NO" << endl;
            return;
        }
    }
    if(flag[0] && flag[1] && flag[2] && flag[3] && flag[4]){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
}

int main(){
    solve();
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long 
using namespace std;
const ll N=100005;
ll dp[N][3];
ll act[N][3];
ll n;
int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>act[i][0]>>act[i][1]>>act[i][2];
	}
	dp[0][0]=act[0][0];
	dp[0][1]=act[0][1];
	dp[0][2]=act[0][2];
	for(int i=1;i<n;i++)
	{
		dp[i][0]=act[i][0]+max(dp[i-1][1],dp[i-1][2]);
		dp[i][1]=act[i][1]+max(dp[i-1][0],dp[i-1][2]);
		dp[i][2]=act[i][2]+max(dp[i-1][0],dp[i-1][1]);
	}
	cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]))<<endl;
	
	return 0;
	
}

Measured memory_bytes: 4992
#include<iostream>
using namespace std;
int main()
{
  int n,m;
  cin>>n>>m;
  int k[m],p[m];
  int ans=0,s[10][10];
  for(int i=0;i<m;i++){
    cin>>k[i];
    for(int j=0;j<k[i];j++){
      cin>>s[i][j];
    }
  }
  for(int i=0;i<m;i++){
    cin>>p[i];
  }
  
  for(int bit=0;bit<(1<<n);bit++){
    int sum=0;
    for(int i=0;i<m;i++){
      int num=0;
      for(int j=0;j<k[i];j++){
        if(bit&(1<<s[i][j]-1))num++;
      }
      if(num%2==p[i])sum++;
    }
    if(sum==m)ans++;
  }
  cout<<ans<<endl;
  return 0;
}
        

Measured memory_bytes: 256
MOD = 10**9 + 7
fact = [0] * 1100000
factinv = [0] * 1100000
fact[0] = 1
for i in range(1,1100000):
    fact[i] = fact[i-1] * i% MOD
factinv[-1] = pow(fact[-1], MOD-2, MOD)
for i in range(1100000 - 1, 0, -1):
    factinv[i-1] = factinv[i] * i % MOD

def nCk(n,k):
    return fact[n] * factinv[n-k] * factinv[k] % MOD

def nPk(n,k):
    return fact[n] * factinv[n-k] % MOD

ans = 0
n, m = map(int,input().split())
for i in range(n+1):
    temp = nCk(n,i)
    temp = (nCk(n,i) * nPk(m,i) * nPk(m-i, n-i)**2)% MOD
    if i&1:
        temp *= -1
    ans += temp
    ans %= MOD
print(ans)

Measured memory_bytes: 112896
#include <stdio.h>
int main(){

  int i,joi=0,ioi=0;
  char word[10000],same[4]={};

  while(scanf("%s",word) != EOF){
    
    ioi=joi=0;

    for(i = 0; word[i] != '\0'; i++){
      
      if(word[i] == 'J' && word[i+1] == 'O' && word[i+2] == 'I')  joi++;
      if(word[i] == 'I' && word[i+1] == 'O' && word[i+2] == 'I')  ioi++;
      
    }
    
    printf("%d\n%d\n",joi,ioi);
    
  }
  
  return 0;

}

Measured memory_bytes: 552
loop do
sum = {:a=>0,:b=>0}
    n = gets.to_i
    if n == 0
        break
    end
    n.times do
        a,b = gets.split(' ').map(&:to_i)
        if a==b
            sum[:a] += a
            sum[:b] += a
            next
        end
        if a>b
            sum[:a] += a+b
        else
            sum[:b] += a+b
        end
    end
    print "#{sum[:a]} #{sum[:b]}\n"
end

Measured memory_bytes: 8732
/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner sc = new Scanner(System.in);
		String a = sc.next();
		char ip = a.charAt(0);
		if(Character.isUpperCase(ip))
			System.out.println("A");
		else
			System.out.println("a");
		sc.close();
	}
}


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
/****************************************************************************************************************************************************/

#define PB push_back
#define F first
#define S second
#define MP make_pair
#define endl '\n'
#define mem(a,b) memset(a, b, sizeof(a) )
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define MOD 1000000007
/********************************************************************************************************************************************************/


const double PI = acos(-1);
const double eps = 1e-9;
const int inf = 2000000000;
const ll infLL = 9000000000000000000;
/*********************************************************************************************************************************************************/
const ll mx=1e5+3;
ll t,n,w[102],v[102];
ll dp[102][mx];
ll ks(ll i,ll we)
{
    if(i>n)
        return 0;
    if(dp[i][we]!=-1)
        return dp[i][we];
    ll c=0,c1=0;
    if(we+w[i]<=t)
        c=v[i]+ks(i+1,we+w[i]);
    c1=ks(i+1,we);
    return dp[i][we]=max(c,c1);
}

int main()
{
    optimize();
    for(int i=0; i<102; i++)
    {
        for(int j=0;j<mx;j++)
        dp[i][j]=-1;
    }
    cin>>n>>t;
    for(int i=1; i<=n; i++)
        cin>>w[i]>>v[i];
    cout<<ks(1,0)<<endl;

    return 0;
}






Measured memory_bytes: 83348
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::f64::consts::*;

#[allow(unused)]
const INF: usize = std::usize::MAX / 4;
#[allow(unused)]
const M: usize = 1000000007;

fn rec(n: usize, cache: &mut HashMap<usize, usize>) -> usize {
    if let Some(&f) = cache.get(&n) {
        f
    } else {
        let mut m = n;
        let mut one_count = 0;
        while m > 0 {
            if m % 2 == 1 {
                one_count += 1;
            }
            m /= 2;
        }
        let f = rec(n % one_count, cache);
        cache.insert(n, f + 1);
        cache[&n]
    }
}

fn main() {
    input! {
        n: usize,
        mut x: Chars,
    }
    x.reverse();
    let one_count = x.iter().filter(|&&c| c == '1').count();

    let mut s = vec![1; n];
    let mut t = vec![1; n];
    for i in 1..n {
        s[i] = s[i - 1] * 2 % (one_count + 1);
        if one_count > 1 {
            t[i] = t[i - 1] * 2 % (one_count - 1);
        }
    }

    let mut sum_p = 0;
    let mut sum_m = 0;
    for i in 0..n {
        if x[i] == '1' {
            sum_p = (sum_p + s[i]) % (one_count + 1);
            if one_count > 1 {
                sum_m = (sum_m + t[i]) % (one_count - 1);
            }
        }
    }

    let mut result = vec![];
    let mut cache = HashMap::new();
    cache.insert(0, 0);
    for i in 0..n {
        let f = if x[i] == '0' {
            let xi = (sum_p + s[i]) % (one_count + 1);
            rec(xi, &mut cache) + 1
        } else {
            if one_count > 1 {
                let xi = (sum_m + one_count - 1 - t[i]) % (one_count - 1);
                rec(xi, &mut cache) + 1
            } else {
                0
            }
        };
        result.push(f);
    }
    result.reverse();
    for &f in &result {
        println!("{}", f);
    }
}


Measured memory_bytes: 8180
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;

int main(){
	int n;
	while(cin>>n,n){
		vector<int> v[21];
		map<int,int> cnt;
		vector<string> name(n);
		vector< pair<int, string> > data;
		REP(i,n){
			int m,t;;
			cin>>name[i]>>m;
			while(m--){
				cin>>t;
				v[i].push_back(t);
				cnt[t]++;
			}
		}
		REP(i,n){
			int score = 0;
			REP(j,v[i].size())score += (n+1)-cnt[v[i][j]];
			data.push_back(make_pair(score, name[i]));
		}
		sort(data.begin(), data.end());
		cout<<data[0].first<<" "<<data[0].second<<endl;
	}
	return 0;
}

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

int main() {
  int N, M;
  cin >> N >> M;
  
  vector<int> A(N);
  int a,b;
  for (int i = 0; i < M; i++){
    cin >> a >> b;
    A.at(a-1) += 1;
    A.at(b-1) += 1;
  }
  
  for (int i = 0; i < N; i++){
    cout << A.at(i) << endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int>pii;
typedef vector<int>vi;

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define fi first
#define se second
#define de(x) cout<<#x<<"="<<x<<"\n"
#define dd(x) cout<<#x<<"="<<x<<" "
#define pb(x) push_back(x)
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define lowbit(a) ((a)&-(a))
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
const int N=2e6+5;
pii f[N];
int n;
int a[N];
int main()
{
	scanf("%d",&n);
	rep(i , 0 , 1<<n){
		scanf("%d",&a[i]);
		f[i].fi = a[i],f[i].se = -1;
	}
	rep(j , 0 , n)
		rep(i , 0 , 1<<n){
			if((i>>j)&1){
				int sta = i ^ (1<<j);
				if(f[i].fi < f[sta].fi){
					f[i].se = f[i].fi;
					f[i].fi = f[sta].fi;
					if(f[i].se < f[sta].se)
						f[i].se = f[sta].se; 
				}
				else if(f[i].se < f[sta].fi)
					f[i].se = f[sta].fi;
			}
		}
	int ans = 0;
	rep(i , 1 , 1<<n){
		ans = max(ans, f[i].fi + f[i].se);
		printf("%d\n",ans);
	}
	return 0;
}




Measured memory_bytes: 6896