akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {

    //
    public static void main(String[] args) throws Exception {
        try (BufferedInputStream in = new BufferedInputStream(System.in);
             PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out))) {

            Scanner sc = new Scanner(in);

            int n = sc.nextInt();
            int cnt = 1;
            int max = sc.nextInt();
            for (int i = 1; i < n; i++) {
                int cur = sc.nextInt();
                if (cur >= max) {
                    cnt++;
                    max = cur;
                }
            }

            out.println(cnt);
        }
    }
}


Measured memory_bytes: 21844
#include <iostream>
#include <string>
#include <cctype>
using namespace std;

string tar[] = { "this", "that" };

int gcd(int a, int b)
{
	if (b == 0) return a;
	return gcd(b, a%b);
}

int main()
{
	string in;
	int N;
	cin >> N;
	getline(cin, in);
	while (N--)
	{
		getline(cin, in);
		string ans;
		bool f = false;
		for (int a=1;; a++)
		{
			if (gcd(a, 26) != 1) continue;
			for (int b=0; b<26; b++)
			{
				ans = in;
				for (int i=0; i<in.size(); i++)
					if (islower(ans[i]))
						ans[i] = (char) ((int) 'a' + (a * ((int) ans[i]) + b) % 26);
	

				if (ans.find(tar[0], 0) != string::npos || ans.find(tar[1], 0) != string::npos)
				{
					f = true;
					break;
				}
			}
			if (f)
				break;
		}

		cout << ans << endl;

	}
}

Measured memory_bytes: 0
N,M,C = map(int,input().split())
B = list(map(int,input().split()))
R = 0
for _ in range(N):
    S = 0
    I = list(map(int,input().split()))
    for x in range(M):
        S += I[x] * B[x]
    if S + C > 0:
        R += 1
print(R)
        

Measured memory_bytes: 3060
n=int(input())
s=input()
alphabet=[chr(i) for i in range(97,97+26)]
ans=0

for i in range(1,n):
    s1=s[:i]
    s2=s[i:]
    cnt=0
    for j in range(len(alphabet)):
        if s1.count(alphabet[j])>=1 and s2.count(alphabet[j])>=1:
            cnt+=1
    if cnt>ans:
        ans=cnt
print(ans)

Measured memory_bytes: 9088
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;


int main(void){
  int n,a,i,l,k[30]={};
  vector<int> p;
  
  cin >> n;
  
  for (a=2;a<=n;a++){
    for (i=0;i<p.size();i++){
      if (a%p[i]==0) break;
    }
    if (i==p.size()) p.push_back(a);
  }
  
  for (a=2;a<=n;a++){
    l=a;
    while (l>1){
      for (i=0;i<p.size();i++){
        while (l%p[i]==0){
          k[i]++;
          l/=p[i];
        }
      }
    }
  }
  
  int y2,y4,y14,y24,y74;
  y2=y4=y14=y24=y74=0;
  for (i=0;i<p.size();i++){
    if (k[i]>=74) y74++;
    if (k[i]>=24) y24++;
    if (k[i]>=14) y14++;
    if (k[i]>=4) y4++;
    if (k[i]>=2) y2++;
  }
  
  int ans=0;
  ans+=y74;
  ans+=y24*(y2-1);
  ans+=y14*(y4-1);
  ans+=y4*(y4-1)/2*(y2-2);
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
          int cnt = 0;
          // 解答はココに書く
          var num = cin.ReadLine;
          //１文字ずつ見て、1が立っていたらカウントを＋１する
          foreach(char n in num){
          	if(n == '1'){
            	cnt++;
            }
          }
          WriteLine(cnt);
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); }}
        public int ReadInt { get { return int.Parse(Read); }}
        public long ReadLong { get { return long.Parse(Read); }}
        public double ReadDouble { get { return double.Parse(Read); }}
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret;}
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret;}
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret;}
    }
}


Measured memory_bytes: 13268
#include<iostream>
#include<cstdio>
using namespace std;
int n,cnt[2][100005],mx[2][100005],xm[2][100005],a[100005],ans=1e9;
int main(){
	ios::sync_with_stdio(false);
	int i;
	cin>>n;
	for(i=1;i<=n;i++){
		cin>>a[i];
		++cnt[i&1][a[i]];
	}
	for(i=1;i<=100000;i++)
		mx[1][i]=max(mx[1][i-1],cnt[1][i]);
	for(i=100000;i;i--)
		xm[1][i]=max(xm[1][i+1],cnt[1][i]);
	for(i=1;i<=100000;i++)
		ans=min(ans,n-cnt[0][i]-max(mx[1][i-1],xm[1][i+1]));
	cout<<ans;
	return 0;
}

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

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

//     int count = 0;
//     for (int a = A; a >= 0; a--){
//         int n = N - 500 * a;
//         if (n < 0) {
//             continue;
//         } else {
//             for (int b = B; b >= 0; b--){
//                 n = N - 500 * a - 100 * b;
//                 if (n < 0 || n % 50 != 0 || n / 50 > C) {
//                     continue;
//                 } else {
//                     count++;
//                 }
//             }
//         }
//     }

//     cout << count << endl;

// }

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

    int count = 0;
    for (int a = 0; a <= A; a++) {
        for (int b = 0; b <= B; b++) {
            for (int c = 0; c <= C; c++){
                if (N == 500 * a + 100 * b + 50 * c) {
                    count++;
                }
            }
        }        
    }

    cout << count << endl;


}

Measured memory_bytes: 256
<?php
fscanf(STDIN, "%s", $o);
fscanf(STDIN, "%s", $e);
//$pw = [];
$o_len = strlen($o);
$e_len = strlen($e);
$pw_len = $o_len + $e_len;
$pw = str_pad('', $pw_len);
$oc = 0;
for($i = 0; $i < $o_len; $i++) {
    $pw[$i + $oc] = $o[$i];
    $oc++;
}
$ec = 1;
for($i = 0; $i < $e_len; $i++) {
    $pw[$i + $ec] = $e[$i];
    $ec++;
}
echo $pw. "\n";

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

struct RSQ{
 UL N;
 vector<UL> V;
 void init(UL n){
  N=1; while(N<n)N<<=1;
  V.resize(N*2-1);
 }
 void add(UL p, UL v){
  UL i = p+N-1;
  V[i]+=v;
  while(i){
   i=(i-1)>>1;
   V[i]+=v;
  }
 }
 UL query(UL l, UL r, UL a=~0u, UL b=~0u, UL i=~0u){
  if(i==~0u){ a=i=0; b=N; }
  if(r<=a || b<=l) return 0;
  if(l<=a && b<=r) return V[i];
  UL q1=query(l,r,a,(a+b)>>1,(i<<1)+1);
  UL q2=query(l,r,(a+b)>>1,b,(i<<1)+2);
  return q1+q2;
 }
};

UL N,Q;
UL P[100000];
vector<UL> E[100000];
UL Z[100000];

RSQ G;
UL hlP[100000]={};
UL hlH[100000];
UL hlL[100000]={};
UL hlp = 0;

UL ZDFS(UL p){
 for(UL e:E[p]) Z[p]+=ZDFS(e);
 return ++Z[p];
}

void hlDFS(UL p){
 hlL[hlH[p]]++;
 if(hlH[p] != p) hlP[p]=hlP[P[p]]+1;
 if(E[p].size()!=0) {
  UL c=E[p].front();
  for(UL e:E[p]){
   if(Z[e]>Z[c]) c=e;
   hlH[e]=e;
  }
  hlH[c]=hlH[p];
 }
 for(UL e:E[p]) hlDFS(e);
 if(hlH[p]==p){
  hlP[p]=hlp;
  hlp+=hlL[p];
 }
}

int main() {
 scanf("%u", &N);
 rep(i,N){
  UL c; scanf("%u", &c);
  while(c--){ UL v; scanf("%u",&v); P[v]=i; E[i].push_back(v); }
 }
 P[0]=~0u;
 hlH[0]=0;
 ZDFS(0);
 hlDFS(0);
 rep(p,N) if(hlH[p]!=p) hlP[p]+=hlP[hlH[p]];
 
 G.init(N);
 
 scanf("%u", &Q);
 rep(q,Q){
  UL c; scanf("%u", &c);
  if(c==0){
   UL v,w; scanf("%u%u", &v,&w);
   G.add(hlP[v],w);
  }
  else if(c==1){
   UL u; scanf("%u", &u);
   UL ans=0;
   while(u != ~0u){
    ans+= G.query(hlP[hlH[u]],hlP[u]+1);
    u=P[hlH[u]];
   }
   printf("%u\n",ans);
  }
 }
 
 return 0;
}


Measured memory_bytes: 15640
N = int(input())
A = list(map(int,input().split()))
mo = 1000

A = [10000] + A + [0]
now = A[0]
for i in range(N+1):
    if A[i+1] >= A[i]:
        mo += 0
    else:
        plus = (mo // now) * (A[i]-now)
        mo += plus
        now = A[i+1]
        
print(mo)

Measured memory_bytes: 9208
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <list>
#include <deque>
#include <set>
#include <map>
#include <queue>

using namespace std;


int main() {
	int K; cin >> K;
	int N = 1;
	for (int i = 0; i < K; i++) { N *= 2; }

	int* S = new int[N];
	for (int i = 0; i < N; i++) { cin >> S[i]; }

	map<int, int, greater<int>> mp;
	for (int i = 0; i < N; i++) {
		auto itr = mp.find(S[i]);
		if (itr == mp.end()) {
			mp.insert(make_pair(S[i], 1));
		}
		else {
			itr->second++;
		}
	}

	vector<int> v1, v2;
	
	for (auto itr = mp.begin(); itr != mp.end(); itr++) {
		if (itr == mp.begin()) {
			v1.push_back(1);
		}
		else { v1.push_back(0); }

		v2.push_back(itr->second);
	}

	N = v1.size();

	for (int k = 0; k < K; k++) {
		int carry = 0;
		for (int i = 0; i < N; i++) {
			int buf = v1[i];
			if (v1[i] + carry >= v2[i]) {
				carry -= v2[i] - v1[i];
				v1[i] = v2[i];
			}
			else {
				v1[i] += carry;
				carry = 0;
			}
			carry += buf;
		}
	}

	for (int i = 0; i < N; i++) {
		if (v1[i] != v2[i]) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;

	return 0;
}


Measured memory_bytes: 15852
#include <bits/stdc++.h>
#include <array>
#define FOR(i,a,b) for(int i=(a);i<=(b);++i) 
#define RFOR(i,a,b) for(int i=(a);i>=(b);--i) 
#define REP(i,n) for(int i=0;i<(n);++i)
#define RREP(i,n) for(int i=(n);i>0;--i)
#define CI cin>> 
#define CO cout<<
#define EN <<endl 
#define all(x) (x).begin(),(x).end() 
using namespace std;
template <typename T> istream & operator >> (istream & is, vector<T> & vec) { for (T& x : vec) is >> x; 	return is; }
using ll = long long;
using VI = vector<int>;
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;}

int main() {
	ll n; CI n;
	vector<ll> a(5); CI a;
	sort(all(a));

	ll ans = ceil(n / (long double)a[0]) + 4;
	CO ans EN;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG 
#define rep(i, n) for (int i = 0; i < n; i++)
#define reps(i, s, n) for (int i = s; i < n; i++)
#define all(v) v.begin(), v.end() // sort(all(array))
#define INF 1000000000
#define mod 1000000007
using namespace std;
using ll = long long;
using vi = vector<int>; //vi array(要素数, 初期値)
using pll = pair<ll, ll>;
using pii = pair<int, int>;
using vc = vector<char>;
using vs = vector<string>;
using vb = vector<bool>;
using vvi = vector<vi>; //vvi table(行数, vi(列数, 初期値))
using vvc = vector<vc>;
using vvs = vector<vs>;
using vvb = vector<vb>;

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

    if (x >= 30) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3608
#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <utility>
#include <complex>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <tuple>
#include <bitset>
#include <limits>
#include <algorithm>
#include <array>
#include <random>
#include <complex>
#include <regex>
#include <iomanip>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define fcout cout << fixed << setprecision(10)
#define rep(i,n)    for(int i=0; i<(int)n; i++)
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define all(x) x.begin(), x.end()
#define F first
#define S second
const ll inf = 1e18;
const ll mod = 1e9 + 7;

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

// mod. m での a の逆元 a^(-1) を計算する。
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

ll modpow(ll a, ll n){
    ll res = 1;
    while(n>0){
        if(n&1){
            res = res * a % mod;
        }
        a = a * a % mod;
        n >>=1;
    }
    return res;
}


int main(){
    int n;
    cin >> n;
    vint a(n);
    vint b(n);
    rep(i,n){
        cin >> a[i] >> b[i];
    }
    sort(all(a));
    sort(all(b));
    double med_a, med_b;
    ll ans;
    if(n&1){
        med_a = a[(n-1)/2];
        med_b = b[(n-1)/2];
        ans = med_b - med_a + 1;

    }else{
        med_a = (double)(a[n/2] + a[n/2-1]) / 2;
        med_b = (double)(b[n/2] + b[n/2-1]) / 2;
        ans = med_b*2 - med_a*2 + 1;
    }
    cout << ans << endl;
}



Measured memory_bytes: 4848
from itertools import combinations
n = int(input())
L = list(map(int, input().split()))

ans = 0
for subset in combinations(L, 3):
    subset = sorted(subset)
    if len(set(subset)) != 3:
        continue
    a, b, c = subset
    if c < a+b:
        ans += 1
print(ans)


Measured memory_bytes: 9168
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vstr=vector<string>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define _GLIBCXX_DEBUG
int main()
{
    int n,d;
    cin>>n>>d;
    if(n%(2*d+1))cout<<n/(2*d+1)+1<<endl;
    else cout<<n/(2*d+1)<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.lang.Math;

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

    int remainder = input%3600;
    int hour = input/3600;
    int minute = remainder/60;
    int seconds = remainder % 60;

    System.out.println(Math.round(hour)+ ":" + Math.round(minute) + ":" + Math.round(seconds));
  }
}



Measured memory_bytes: 26172
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rep1(i, n) for(int i=1; i<=n; i++)
#define rrep(i, n) for(int i=n-1; i>=0; i--)
#define rrep1(i, n) for(int i=n; i>=1; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
const double EPS = 1e-10;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

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

    int n = s.size();
    vector<ll> a(n+1), b(n+1);
    rep(i, n+1) a[i] = 0, b[i] = 0;
    a[0] = 0; b[n] = 0;
    for (int i = 0; i < n; i++) {
        if (s[i] == '<') a[i+1] = a[i] + 1;
        else a[i+1] = 0;
    }
    for (int i = n-1; i >= 0; i--) {
        if (s[i] == '>') b[i] = b[i+1] + 1;
        else b[i] = 0;
    }

    ll ans = 0;
    rep(i, n+1) ans += max(a[i], b[i]);
    cout << ans << endl;
}


Measured memory_bytes: 8708
/**
*    author:  boutarou
*    created: 21.06.2020 21:08:55
**/

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < int(n); i++)
#define fcout cout << fixed << setprecision(15)
using lint = long long;
using P = pair<int, int>;

template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

const double PI = 3.1415926535897932;

lint n;
lint q;
lint a[100005];
lint cnt[100008];
lint ans = 0;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin >> n;
    rep(i, n) {
        cin >> a[i];
        cnt[a[i]]++;
        ans += a[i];
    }
    cin >> q;
    rep(i, q) {
        lint b, c;
        cin >> b >> c;
        cnt[c] += cnt[b];
        ans += cnt[b] * c;
        ans -= cnt[b] * b;
        cnt[b] = 0;
        cout << ans << endl;
    }
    
    return 0;
}

Measured memory_bytes: 5132
#include <iostream>
#include <cstdio>
#define N 305
using namespace std;

int n, m, mx = 1e9, ans = 1e9, c[N], a[N][N];
bool v[N];
int main()
{
	int i, j;
	cin >> n >> m;
	for (i = 0; i < n; i++) {
		for (j = 0; j < m; j++) scanf("%d", &a[i][j]);
	}
	do {
		ans = min(ans, mx);
		mx = 0;
		for (i = 0; i < n; i++) {
			for (j = 0; j < m; j++) if (!v[a[i][j]]) break;
			c[a[i][j]]++;
		}
		for (i = 1; i <= m; i++) mx = max(mx, c[i]);
		for (i = 1; i <= m; c[i++] = 0) if (c[i] == mx) v[i] = 1;

	} while (mx);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<queue>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

int P[10], Q[10], R[10];
int main()
{
	int N;
	cin >> N;
	int p = 0, q = 0;
	for (int i = 0; i < N; i++) {
		R[i] = i + 1;
		cin >> P[i];
		p *= 10;
		p += P[i];
	}
	for (int i = 0; i < N; i++) {
		cin >> Q[i];
		q *= 10;
		q += Q[i];
	}
	int point1 = 0, point2 = 0;
	int cnt = 0;
	do {
		int r = 0;
		cnt++;
		for (int i = 0; i < N; i++) {
			r *= 10;
			r += R[i];
		}
		if (r == q) point1 = cnt;
		if (r == p) point2 = cnt;
	} while (next_permutation(R, R + N));
	cout << abs(point1 - point2) << 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;
typedef vector<pii> vpii;
#define INF 1000000000

int V[120];
int n, W;
ll Wt[120];
ll dp[100050];

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

  cin>>n>>W;
  for(int i=0; i<n; i++){
    int a, b;
    cin>>a>>b;
    Wt[i] = a;
    V[i] = b;
  }

  for(int i=0; i<100050; i++)dp[i] = INT_MAX;
  dp[0] = 0;

  int Sv = 0;
  for(int p=0; p<n; p++)
    Sv+=V[p];

  for(int p=0; p<n; p++){
    for(int v=Sv; v>=0; v--){
      if(v-V[p]>=0)dp[v] = min(dp[v], Wt[p] + dp[v-V[p]]);
    }
  }


  int ans = 0;
  for(int v=0; v<=Sv; v++){
    if(dp[v]<=W)ans = max(ans, v);
  }

  cout<<ans<<"\n";


  return 0;
}


Measured memory_bytes: 4436
#include <bits/stdc++.h>
using namespace std;
int main(){
    vector<int> a;
    int d,b,c;
    cin >> d >> b >> c;
    a.push_back(d);
    a.push_back(b);
    a.push_back(c);
    std::sort(a.begin(), a.end());
    cout << a[2] * 10 + a[1] + a[0] << endl;
}

Measured memory_bytes: 256
N, M = [int(x) for x in input().split()]
lst = []

for _ in range(N):
  lst.append([int(x) for x in input().split()])

lst.sort()

cost = 0
i = 0

while i < len(lst):
  l = lst[i]
  if l[1] < M:
    M -= l[1]
    cost += l[0] * l[1]
    i += 1
    continue
  else:
    cost += l[0] * M
    break

print(cost)

Measured memory_bytes: 21612
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const long long INF = 1LL<<60;

int main() {
  long long N,W;
  cin >>N>>W;
  long long w[110],v[110];
  
  for(int i=0;i<N;i++) cin >>w[i]>>v[i];
  
  long long dp[110][101000]={0};
  for(int i=0;i<N;i++){
    for(int w_sum=0;w_sum<=W; w_sum++){
    if(w_sum-w[i]>=0){
      chmax(dp[i+1][w_sum],dp[i][w_sum-w[i]]+v[i]);
    }
     chmax(dp[i+1][w_sum],dp[i][w_sum]);
    }
  }
  cout << dp[N][W] << endl;
}

Measured memory_bytes: 87168
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define vll vector<ll>
#define endl "\n"
#define fa(i,n) for(i=0;i<n;i++) 
#define fb(j,n) for(j=1;j<=n;j++)  
using namespace std;
int main()
{
 long long int n,s,mx,k=1,i,j,a[100006],b[100006],mn,x;
 cin >> j; 
  cin >> i;
  k=i*j;
cout << k;
}


Measured memory_bytes: 3620
import bisect

n=int(input())
*L,=map(int,input().split())

L.sort()
s=0
for i in range(n-1):
      for j in range(i+1,n):
            index=bisect.bisect_left(L,L[i]+L[j])
            s+=index-(j+1)
print(s)
            

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

int main() {
	string str, com, p;
	int q, a, b;

	cin >> str >> q;
	for (int t = 0; t < q; t++) {
		cin >> com >> a >> b;
		if (com == "print") {
			cout << str.substr(a, b - a + 1) << endl;
		}
		else if (com == "reverse") {
			string tmp = str.substr(a, b - a + 1);
			int n = tmp.size();
			for (int i = 0; i < n; i++)str[i + a] = tmp[n - i - 1];
		}
		else if (com == "replace") {
			cin >> p;
			str = str.replace(a, b - a + 1, p);
		}
	}
	return 0;
}

Measured memory_bytes: 3132
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long 
signed main() 
{
    
    IOS;    
    int l,r,d;
    cin>>l>>r>>d;
    int ans=0;
    for(int i=l;i<=r;i++)if(i%d==0)ans++;
        cout<<ans;
    
    return 0; 
} 

Measured memory_bytes: 3608
N = int(input())
li = []
flag = True
for i in range(N):
    word = input()
    if i != 0:
        if pre_word[len(pre_word)-1] != word[0] or word in li:
            flag = False
            break
    li.append(word)
    pre_word = word
if flag:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 8996
n, m, c = map(int, input().split())
b = list(map(int, input().split()))
ans = 0
for i in range(n):
    a = list(map(int, input().split()))
    s = 0
    for j in range(m):
        s += a[j] * b[j]
    if s + c > 0:
        ans += 1
print(ans)

Measured memory_bytes: 3060
/*
title:

url:
*/

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <functional>
#include <queue>
#include <limits>
#include <string>
#include <utility>
#include <cstring>

using namespace std;

#define REP(i, n) for (int i = 0; i < (n); i++)
#define INF 1000000007

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

//あるものの中身だけを知りたい場合には、累積和を使えば走査せずに済む

int main()
{
    int N, M, Q;
    cin >> N >> M >> Q;
    int data[N + 1][N + 1];
    memset(data, 0, sizeof(data));
    REP(i, M)
    {
        int L, R;
        scanf("%d %d", &L, &R);
        data[L][R]++;
    }
    int acc[N + 1][N + 1];
    memset(acc, 0, sizeof(acc));
    //累積和をつくるときのindexに注意。
    //index=0のとき、0とし、index＝1にはじめの要素を対応させる
    for (int i = 1; i <= N; i++)
    {
        for (int j = 1; j <= N; j++)
        {
            acc[i][j] = acc[i - 1][j] + data[i][j];
        }
    }
    int p[Q], q[Q];
    for (int i = 0; i < Q; i++)
    {
        scanf("%d %d", &p[i], &q[i]);
    }
    for (int i = 0; i < Q; i++)
    {
        int ans = 0;
        for (int j = p[i]; j <= q[i]; j++)
        {
            ans += (acc[q[i]][j] - acc[p[i] - 1][j]);
        }
        cout << ans << endl;
    }
    return 0;
}

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

typedef long long ll;
const ll MOD = 1000000007;

using namespace std;

vector<vector<int> > t(100001);
vector<vector<int> > dp(100001, vector<int>(2, -1));

int n;

// current node, c=1 means only white is allowed
int ans(int node, int c, int p = -1) {
    //debug
    // cout << node << " " << c << " called" << endl;
    // base case;
    if ((int)t[node].size() == 0 || ((int)t[node].size() == 1 && t[node][0] == p)) {
        if (c == 0)
            return 2;
        else
            return 1;
    } else if (dp[node][c] != -1) {
        return dp[node][c];
    }
    // paint current white
    ll t1 = 0;
    for (auto child : t[node]) {
        if (child != p) {
            if (t1 == 0) {
                t1 = ans(child, 0, node);
            } else {
                t1 = ((ll)t1 * (ll)ans(child, 0, node)) % MOD;
            }
        }
    }
    // paint current black if you can
    ll t2 = 0;
    if (c == 0) {
        for (auto child : t[node]) {
            if (child != p) {
                if (t2 == 0) {
                    t2 = ans(child, 1, node);
                } else {
                    t2 = ((ll)t2 * (ll)ans(child, 1, node)) % MOD;
                }
            }
        }
    }

    dp[node][c] = (t1 + t2) % MOD;
    // cout << node << " " << c << " returned " << dp[node][c] << endl;
    return dp[node][c];
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n;
    for (int i = 0; i < n - 1; i++) {
        int u, v;
        cin >> u >> v;
        u--, v--;
        t[v].push_back(u);
        t[u].push_back(v);
    }
    cout << ans(0, 0);
}

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

int main() {
	string s;
	cin >> s;
	bool a = false;
	for(int i=0;i<3;i++)
	{
	    if(s[i] == '7')
	    {
	        a = true;
	        break;
	    }
	}
	if(a)
	{
	    cout << "Yes\n";
	}
	else
	{
	    cout << "No\n";
	}
	return 0;
}


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

using namespace std;

#define ll long long

int main()
{
	ll N;
	cin >> N;
	vector < ll > A(N);
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}

	ll current, ans;
	ans = 0;
	current = A[0];
	for (int i = 1; i < N; i++) {
		if (current > A[i]) {
			ans += current - A[i];
		}
		current = max(current, A[i]);
	}

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


Measured memory_bytes: 4840
#include <stdio.h>
#include <stdint.h>
#include <inttypes.h>


int main (int argc, char const *argv[])
{
    int64_t A, B, T;

    scanf("%"PRId64"%"PRId64"%"PRId64, &A, &B, &T);
    
    printf("%"PRId64"\n", T / A * B);
}


Measured memory_bytes: 128
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE BinaryLiterals #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE NumDecimals #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}

import Control.Applicative
import Control.Arrow
import Control.Monad
import Control.Monad.ST

import Data.Char
import Data.List
import Data.Maybe

import qualified Data.ByteString.Char8 as B

import Data.Array.ST.Safe
import Data.STRef

import Debug.Trace
import Text.Printf

readInt = readLn :: IO Int
readInteger = readLn :: IO Integer
readInts = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine
readIntegers = map ( fst . fromJust . B.readInteger ) . B.words <$> B.getLine

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

modifyArray a i f = writeArray a i =<< f <$> readArray a i

main = readInt >>= putStrLn . f . ( `mod` 10 )

f 2 = "hon"
f 4 = "hon"
f 5 = "hon"
f 7 = "hon"
f 9 = "hon"

f 0 = "pon"
f 1 = "pon"
f 6 = "pon"
f 8 = "pon"

f 3 = "bon"

Measured memory_bytes: 3872
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        int K = scan.nextInt();
        boolean[] d = new boolean[10];
        for(int i = 0; i < K; i++) {
            d[scan.nextInt()] = true;
        }
        int current = 10000;
        int answer = 100000;
        while (N <= current) {
            String t = Integer.toString(current);
            char[] digits = t.toCharArray();
            boolean ok = true;
            for (int i = 0; i < digits.length; i++) {
                if (d[digits[i]-'0']) {
                    ok = false;
                    break;
                }
            }
            if (ok) {
                answer = Math.min(answer, current);
            }
            current -= 1;
        }
        if (answer != 100000) {
            System.out.println(answer);
            return;
        }
        current = 10000;
        while(true) {
            String t = Integer.toString(current);
            char[] digits = t.toCharArray();
            boolean ok = true;
            for (int i = 0; i < digits.length; i++) {
                if (d[digits[i]-'0']) {
                    ok = false;
                    break;
                }
            }
            if (ok) {
                answer = Math.min(answer, current);
                break;
            }
            current += 1;
        }
        System.out.println(answer);
    }
}


Measured memory_bytes: 25940
n,m=map(int,input().split())
a=[[int(i) for i in input().split()] for i in range(m)]

number=[99]*n
if m==0 and n==1:
    print(0)
    exit()
if m==0 and n==2:
    print(10)
    exit()
if m==0 and n==3:
    print(100)
    exit()
flag=True
for x,y in a:
    if number[x-1]!=99:
        if number[x-1]!=y:
            flag=False
    number[x-1]=y
if flag==False:
    print(-1)
    exit()
if n==1 and number[0]==0:
    print(0)
    exit()
if number[0]==0:
    print(-1)
    exit()
for i in range(n):
    if number[i]==99:
        number[i]=0
if number[0]==0:
    number[0]=1
for i in number:
    print(i,end="")

Measured memory_bytes: 3064
#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <string>
#include <limits>
#include <algorithm>
#include <map>

using ll = long long;
using ull = unsigned long long;

using namespace std;
int main()
{
  ll k;
  string s;
  cin >> s;
  cin >> k;

  string res = "1";
  for (auto i = 0; i < min((size_t)k, s.size()); i++) {
    if (s[i] != '1') {
      res = s[i];
      break;
    }
  }

  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
arr = [chr(i) for i in range(97, 97+26)]

n = int(input())

s = []
for i in range(n):
    s.append(input())

buf = [0 for i in range(26)]
for i in range(26):
    hoge = 100000000
    for j in range(n):
        fuga = s[j].count(arr[i])
        if fuga < hoge:
            hoge = fuga

    buf[i] = hoge

ans = ""
for i in range(26):
    ans += arr[i]*buf[i]

print(ans)

Measured memory_bytes: 3064
import sys
input = sys.stdin.readline
n = int(input())
a = [[i-1 for i in map(int,input().split())][::-1] for j in range(n)]
def check(i):
  if a[i] == []:
    return
  elif a[a[i][-1]][-1] == i:
    q.add((min(a[i][-1],i),max(a[i][-1],i)))
q = set()
for i in range(n):
  check(i)
d = 0
while q:
  d += 1
  pq = set()
  pq,q = q,pq
  for i in pq:
    del a[i[0]][-1],a[i[1]][-1]
    check(i[0])
    check(i[1])
for i in a:
  if i != []:
    print(-1)
    exit()
print(d)

Measured memory_bytes: 34732
#include <stdio.h>

int main(void)
{
    int N;
    char S[101];
    int tmp[30];
    int i, j, k, l;
    int max = 0, cnt;

    scanf("%d%s", &N, S);
    for (i = 1; i < N-2; i++) {
        cnt = 0;
        for (j = 0; j < i; j++) {
            for (k = i; k < N; k++) {
                if (S[j] == S[k]) {
                        if (cnt == 0) {
                            tmp[0] = j;
                            cnt++;
                        }
                        else {
                            for (l = 0; l < cnt; l++) {
                                if (S[tmp[l]] == S[j]) break;
                            }
                            if (l == cnt) {
                                tmp[l] = j;
                                cnt++;
                            }
                        }
                }
            }
        }
        if (max < cnt) max = cnt;
    }
    printf("%d\n", max);

    return 0;
}


Measured memory_bytes: 128
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <cstdint>
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <bitset>

using namespace std;

using ll =  long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;

constexpr ll MOD = 1000000007;
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

int main() {
    std::ios::sync_with_stdio(false); cin.tie(nullptr);
    int n;
    cin >> n;
    vector<Pii> a(n); // {Pi, idx}
    for(int i=0;i<n;++i) {
        cin >> a[i].first;
        a[i].second = i;
    }
    sort(a.rbegin(), a.rend());

    int p, idx;
    set<int> used, used2;
    ll ans = 0;
    vector<vector<int>> lowers(2, vector<int>(n+1, -1)), uppers(2, vector<int>(n+1, n));
    for(int i=0;i<n;++i) {
        tie(p, idx) = a[i];
        if(i == 0) {
            used.insert(idx);
            used2.insert(-idx);
            continue;
        }

        auto itr = used.lower_bound(idx);
        if(itr != used.end()) {
            uppers[0][p] = *itr;
            itr = used.upper_bound(*itr);
            if(itr != used.end()) {
                uppers[1][p] = *itr;
            }
        }
        itr = used2.lower_bound(-idx);
        if(itr != used2.end()) {
            lowers[0][p] = -*itr;
            itr = used2.upper_bound(*itr);
            if(itr != used2.end()) {
                lowers[1][p] = -*itr;
            }
        }
        // cerr << p << ", " << idx << ": " << lowers[1][p] << " " << lowers[0][p] << " " << uppers[0][p] << " " << uppers[1][p] << endl;

        ans += ll(lowers[0][p]-lowers[1][p]) * (uppers[0][p] - idx) * p;
        ans += ll(uppers[1][p]-uppers[0][p]) * (idx - lowers[0][p]) * p;

        used.insert(idx);
        used2.insert(-idx);

    }
    cout << ans << endl;
}


Measured memory_bytes: 12024
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <math.h>
#include <stdlib.h>
#include <string.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef priority_queue<int, vector<int>, greater<int> > minpq;

int main() {
    while (true){
        int n;
        cin >> n;
        if (n == 0) break;
        ll ans = 0;
        vector<ll>a(n);
        for(int i=0; i<n;i++){
            cin>>a.at(i);
        }
        for(int i=0;i<n;i++){
            ans+=a.at(i);
        }
        ll cnt=0;
        for(int i=0;i<n;i++){
            if (a.at(i)*n<=ans){
                cnt++;
            }
        }
        cout << cnt << '\n';
    }
    return 0;
}


Measured memory_bytes: 3164
#include <stdio.h>
#include <math.h>

int main(void)
{
	int a,b;
	scanf("%d %d",&a,&b);
	
	if(b==100)a=a*1000+b;
	else if(100>b&&b>9)a=a*100+b;
	else a=a*10+b;
	b=sqrt(a);
	if(a==b*b)printf("Yes\n");
	else printf("No\n");
	
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
                     
#define int             long long
#define ld              long double
#define mp              make_pair
#define ff              first
#define ss              second
#define pb              push_back
#define fo(i,n)         for(i=0;i<n;i++)
#define fo1(i,n)        for(i=1;i<=n;i++)
#define FO(i,k,n)       for(i=k;k<=n?i<=n:i>=n;k<=n?i++:i--)
#define all(c)          c.begin(),c.end()
#define rall(c)         c.rbegin(),c.rend()
#define si              set<int>
#define vi              vector<int>
#define mii             map<int,int>
#define pii             pair<int,int>
#define usi             unordered_set<int>
#define umii            unordered_map<int,int>
#define pqmx            priority_queue<int>
#define pqmn            priority_queue<int,vi,greater<int> >
#define sp(x)           cout<<setprecision(x)<<fixed;
#define setbits(x)      __builtin_popcountll(x)
#define zerobits(x)     __builtin_ctzll(x)
#define in(a,n)         vi a(n);fo(i,n)cin>>a[i];
#define in1(a,n)        vi a(n+1);fo1(i,n)cin>>a[i];
#define w(t)            int t;cin>>t;while(t--)
#define gcd             __gcd
#define lcm(x,y)        x*(y/gcd(x,y))
#define endl            '\n'
#define PI              3.14159265358979323846
#define inf             1e18
#define mod             1000000007
void __p(int x) {cout<<x;}
void __p(int32_t x){cout<<x;}
void __p(float x){cout<<x;}
void __p(double x){cout<<x;}
void __p(ld x) {cout<<x;}
void __p(char x){cout <<'\''<<x<<'\'';}
void __p(const char *x){cout <<'\"' <<x<<'\"';}
void __p(const string &x) {cout<<'\"'<<x<<'\"';}
void __p(bool x) {cout<<(x?"true":"false");}
template<typename T,typename V>     void __p(const pair<T,V> &x) {cout<<'{';__p(x.first);cout<<',';__p(x.second);cout<<'}';}
template<typename T>                void __p(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __p(i); cout << "}";}void _p() {cout << "]\n";}
template <typename T,typename... V> void _p(T t, V... v) {__p(t);if(sizeof...(v))cout<<", ";_p(v...);}
int po(int x,int p,int m = inf) {int ans=1;x%=m;while(p>0){if(p&1)ans=(ans*x)%m;p=p>>1;x=(x*x)%m;}return ans;}
int inv(int x,int m=mod){return po(x,m-2,m)%m;}
#ifndef ONLINE_JUDGE
#define dbg(x...) cout<<"["<<#x<<"]=[";_p(x)
#else 
#define dbg(x...)
#endif
//=========================================================




const int N=1e6+6;
int n,m,k,x,y,z,a,b,c,d,i,j,l,r;








void sol()
{   
    cin>>x>>y>>z;
    
    
    
    
    cout<<z<<" "<<x<<" "<<y<<endl;
}





int32_t main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    //sp(10);
    // w(t)
    sol();
    return 0;
}

Measured memory_bytes: 3544
# b - 0 or 1 swap
n = int(input())
p = list(map(int,input().split()))
q = sorted(p)
count = 0
for i in range(n):
    if q[i] != p[i]:
        count += 1
if count == 0 or count == 2:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <climits>
using namespace std;
#define MOD 1000000007

unsigned long long fact_num[200010];
unsigned long long fact_den[200010];

unsigned long long combination(int a, int b) {
    return (((fact_num[a+b]*fact_den[a])%MOD)*fact_den[b])%MOD;
}

// 繰り返し二乗法
unsigned long long bipow(unsigned long long n, int m) {
    if (m == 0) return 1;
    if (m % 2 == 0) {
        n = (n * n) % MOD;
        return bipow(n, m / 2) % MOD;
    } else
        return (n * bipow(n, m - 1)) % MOD;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int H, W, A, B;
    cin >> H >> W >> A >> B;

    unsigned long long powmod[200010];
    for(int i=0; i<200010; i++)
        powmod[i] = bipow(i, MOD-2);

    fact_num[0] = fact_den[0] = 1;
    for(int i=1; i<200010; i++){
        fact_num[i] = (fact_num[i-1] * i) % MOD;
        fact_den[i] = (fact_den[i-1] * powmod[i]) % MOD;
    }

    unsigned long long ans = 0;
    for(int i=0; i<H-A; i++){
        ans += (combination(B-1, i) * combination(W-B-1, H-i-1)) % MOD;
        ans %= MOD;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 4992
#include<stdio.h>
int main()
{
    int n;
    double x;
    scanf("%d",&n);
    if (n%2==0)
        {x=n/2;
    printf("%0.10lf",x/n);
        }
     else if (n%2!=0)
     {


         x=(n/2)+1;
    printf("%0.10lf",x/n);
}
return 0;
}


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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;


int main() {
    int N,K;
    cin >> N >> K;
    string S;
    cin >> S;

    if(S[K-1] == 'A'){
        S[K-1] = 'a';
    }
    if(S[K-1] == 'B'){
        S[K-1] = 'b';
    }
    if(S[K-1] == 'C'){
        S[K-1] = 'c';
    }

    cout << S << endl;
    return 0;
}

Measured memory_bytes: 3572
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};

/* Macros reg. ends here */

const ll INF = 1LL << 50;

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  ll n, k;
  cin >> n >> k;

  vll csum(n + 1, 0);
  rep(i, n) {
    ll a;
    cin >> a;
    csum[i + 1] = csum[i] + a;
  }

  vll bs;
  repLRE(i, 0, n - 1) {
    repLRE(j, i + 1, n) { bs.push_back(csum[j] - csum[i]); }
  }

  ll const blmax = 50;

  ll ans = 0;
  rrepLRE(i, blmax, 0) {
    ll cnt = 0;
    rep(j, (ll)bs.size()) {
      ll v = ans | (1LL << i);
      if ((bs[j] & v) >= v) cnt++;
    }
    if (k <= cnt) ans += (1LL << i);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 6256
N,M,X = map(int,input().split())
Book = []
for i in range(N):
  Book.append(list(map(int,input().split())))
Cost = 10**15
for i in range(2**N):
  cost = 0
  A = [0 for i in range(M)]
  num = []
  j = 0
  while i > 0:
    if i%2 == 1:
      num.append(j)
    i = i//2
    j += 1
  for k in num:
    A = [x+y for (x,y) in zip(A,Book[k][1:])]
    cost += Book[k][0]
  if min(A) >= X:
    if cost < Cost:
      Cost = cost
if Cost == 10**15:
  print(-1)
else:
  print(Cost)

Measured memory_bytes: 9232
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <memory.h>
#include <vector>

using namespace std;
typedef long long LL;
const int maxn = 100005;
const int mod = 2333347;

int head[mod],nex[mod],tot,pos[maxn];LL num[mod];
int pre1[mod],pre2[mod],g[mod],ord[mod];bool vis[mod];
int insert(LL o)
{
	if (!o) return 0;
	int u=o%mod;
	for (int j=head[u];j;j=nex[j])
		if (num[j]==o) return j;
	int x=++tot;num[x]=o;
	nex[x]=head[u];head[u]=x;
	return x;
}

LL q[maxn],ans[maxn],dp[mod];int n,m,Q;
int findpos(LL o) {
	int lb=0,rb=m+1;
	while (rb-lb>1) {
		int mid=lb+rb>>1;
		q[mid]<o?lb=mid:rb=mid;
	}
	return lb;
}
int solve(LL n) {
	int id=insert(n);
	if (vis[id]) return id;
	int t=findpos(n);g[id]=t;vis[id]=true;
	if (t) {
		pre1[id]=pos[t];pre2[id]=solve(n%q[t]);
	}
	return id;
}
bool comp(int x,int y) {
	return num[x]<num[y];
}
int main()
{
	#ifdef Amberframe
		freopen("agc003e.in","r",stdin);
		freopen("agc003e.out","w",stdout);
	#endif
	scanf("%d %d",&n,&Q);q[m=1]=n;vis[0]=1;
	for (int i=1;i<=Q;i++) {
		LL x;scanf("%lld",&x);
		while (m&&q[m]>=x) --m;
		q[++m]=x;
	}
	cerr<<q[1]<<endl;
	for (int i=1;i<=m;i++) pos[i]=solve(q[i]);
	for (int i=1;i<=tot;i++) ord[i]=i;
	sort(ord+1,ord+tot+1,comp);dp[ord[tot]]=1;
	
	for (int i=tot;i>=1;i--) {
		int id=ord[i];
		if (num[id]<=q[1]) ans[num[id]]+=dp[id];
		else {
			int t=g[id];LL o=num[id];
			if (pre1[id]) dp[pre1[id]]+=(o/q[t])*dp[id];
			if (pre2[id]) dp[pre2[id]]+=dp[id];
		}
	}
	
	for (int i=n;i>=1;i--)
		ans[i]+=ans[i+1];
	for (int i=1;i<=n;i++)
		printf("%lld\n",ans[i]);
	return 0;
}

Measured memory_bytes: 39680
package main

import (
	"sort"
	"fmt"
	"bufio"
	"os"
	"strconv"
)

//•*¨*•.¸¸♪I/O•*¨*•.¸¸♪

var (
	sc = bufio.NewScanner(os.Stdin)
	wr = bufio.NewWriter(os.Stdout)
)

func scanInt() int {
	sc.Scan()
	a,_ := strconv.Atoi(sc.Text())
	return a
}

func scanInt64() int64 {
	sc.Scan()
	a,_ := strconv.ParseInt(sc.Text(),10,64)
	return a
}

func scanFloat64() float64 {
	sc.Scan()
	a,_ := strconv.Atoi(sc.Text())
	return float64(a)
}

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ { res[i] = scanInt() }
	return res
}

func scanText() string {
	sc.Scan()
	return sc.Text()
}

func printInts(a ...int) {
	for i, e := range a {
		fmt.Fprint(wr, e)
		if i != len(a)-1 { fmt.Fprint(wr, " ") }
	}
	fmt.Fprintln(wr)
	wr.Flush()
}

//•*¨*•.¸¸♪Main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)

func main() {
	sc.Split(bufio.ScanWords)
	// sc.Buffer(make([]byte, 10000), 100000000)

	n := scanInt()
	a := scanInts(n)
	b := scanInts(n)
	c := scanInts(n)

	sort.Ints(a)
	sort.Ints(b)
	sort.Ints(c)
	// fmt.Println(a)
	// fmt.Println(b)
	// fmt.Println(c)

	ans := 0
	memo := make([]int, n)

	for i := 0; i < n; i++ {
		memo[i] = n-bs(b[i],c)
	}

	sum := make([]int, n)
	sum[n-1] = memo[n-1]
	for i := 1; i < n; i++ {
		sum[n-1-i] = memo[n-1-i] + sum[n-1-i+1]
	}

	for i := 0; i < n; i++ {
		val := bs(a[i], b)
		// fmt.Println(i,val)
		if val==n {
			continue
		}
		ans += sum[val]
	}


	fmt.Println(ans)
	// fmt.Println(memo)
	// fmt.Println(sum)
}

func bs(x int, arr []int) int {
	l,r := -1, len(arr)
	for l+1 < r {
		mid := (l+r)/2
		if arr[mid] > x {
			r = mid
		} else {
			l = mid
		}
	}
	return r
}


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

int main(){
    int n;

    while(cin >> n, n != 0){
        unsigned long long int cnt = 0;
        while(n >= 5){
            cnt+= n / 5;
            n /= 5;
        }
        cout << cnt << endl;
    }
    return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <deque>
#include <set>
#include <iomanip>
#include <utility>
typedef long long ll;
typedef long double ld;
using namespace std;

int A[200010], vis[200010]={}, city[200010];

int main() {
	int N;
	ll K;
	cin >> N >> K;
	for(int i=1; i<=N; ++i) cin >> A[i];
	city[0]=1;
	vis[1]=0;
	for(int i=2; i<=N; ++i) vis[i]=-1;
	int p=0;
	while(true){
		++p;
		city[p]=A[city[p-1]];
		if(vis[city[p]]>=0) break;
		vis[city[p]]=p;
	}
	int r=vis[city[p]];
	if(K<p){
		cout << city[K] << endl;
		return 0;
	}
	K -= r;
	K %= p-r;
	cout << city[r+K] << endl;
	return 0;
}

Measured memory_bytes: 5964
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define rrep(i, a, n) for (int i = (int)(a); i >= (int)(n); --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) \
  rep(f, 0, (x.size() - 1)) cerr << x[f] << (f == (x.size() - 1) ? "\n" : " ")
#define debug2(x, y)                       \
  cerr << "(" << #x << "," << #y << ") = " \
       << "(" << x << "," << y << ")\n"
#define all(x) x.begin(), x.end()
#define each(a, x) for (auto& a : (x))
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define int long long
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
const int MX = 1e5 + 5, INF = 5LL << 57, MOD = 1e9 + 7;

string S;
vi va, vb;
int K;

void input() {
  ;
  ;
  cin>>S;
  cin>>K;

}
int dp[102][4][2];

int rec(int d=0, int k=0,bool tight=true){
  if (k>K){
    return 0;
  }
  if (d == S.size()){
    return  k==K;
  }
  int x = S[d]-'0';
  int r = (tight ? x : 9);
  int &res = dp[d][k][tight];
  if (~res) return res;
  res = 0;
  rep(i,0,r){

    res += rec(d+1, k + (i!=0), tight&&(i==r));
  }
  return res;
}
void solve() {
  int ans;
  memset(dp,-1,sizeof(dp));
  ans = rec(0,0,true);
  cout<<ans<<endl;

  ;
  ;
}
signed main() {
  input();
  solve();
  return 0;
}

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

bool flag[3][3];

int main(void){
    int n,grid[3][3];
    for(int i = 0;i < 3;i++)for(int j = 0;j < 3;j++)scanf("%d",&grid[i][j]);
    scanf("%d",&n);
    int b[n];
    for(int i = 0;i < n;i++)scanf("%d",&b[i]);
    for(int i = 0;i < n;i++){
        for(int x = 0;x < 3;x++)for(int y = 0;y < 3;y++)if(grid[y][x] == b[i])flag[y][x] = true;
    }
    for(int c = 0;c < 3;c++)if(flag[c][0] && flag[c][1] && flag[c][2]){
        puts("Yes");
        return 0;
    }
    for(int c = 0;c < 3;c++)if(flag[0][c] && flag[1][c] && flag[2][c]){
        puts("Yes");
        return 0;
    }
    if((flag[0][0] && flag[1][1] && flag[2][2]) || (flag[0][2] && flag[1][1] && flag[2][0])){
        puts("Yes");
        return 0;
    }
    puts("No");
    return 0;
}

Measured memory_bytes: 128