akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<stack>
using namespace std;

stack<int> array1,array2;
int Balls[10];

bool DFS(int number,stack<int> s1,stack<int> s2){
  if(number > 9) return true;
  if(s1.top() < Balls[number]){
    s1.push(Balls[number]);
    if(DFS(number+1,s1,s2)){
      return true;
    }
    s1.pop();
  }
  if(s2.top() < Balls[number]){
    s2.push(Balls[number]);
    if(DFS(number+1,s1,s2)){
      return true;
    }
    s2.pop();
  }
  return false;
}

int main(){

    int N;

    cin >> N;

    for(int i=0;i<N;i++){
      for(int i=0;i<10;i++){
        cin >> Balls[i];
      }
      array1.push(0);
      array2.push(0);

      if(DFS(0,array1,array2)){
        cout << "YES" << endl;
      }
      else{
        cout << "NO" << endl;
      }
      while (!array1.empty()) {
        array1.pop();
      }
      while (!array2.empty()) {
        array2.pop();
      }
    }
    return 0;
}

Measured memory_bytes: 2992
s=input()
t=input()

count = []

for i in range(len(s)-len(t)+1):
    c=0
    for j in range(i,i+len(t)):
        if s[j] == t[j-i]:
            c+=1
    count.append(c)

# print(count)
print(len(t)-max(count))


Measured memory_bytes: 9064
import java.util.*;
import java.lang.*;
import java.io.*;
public class Main
 {
	public static void main (String[] args)
	 {
            Scanner sc=new Scanner(System.in);
            int n=sc.nextInt(),h=sc.nextInt(),w=sc.nextInt();
            long count=0;
            while(n-->0) {
            	int n1=sc.nextInt(),n2=sc.nextInt();
            	if(n1<h || n2<w)
            		count+=0;
            	else
            		count++;
            }
            System.out.println(count);
	 }
}

Measured memory_bytes: 25448
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >

using namespace std;

typedef long long lint;

void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    int N;
    cin >> N;
    vector<int> D(N);
    for (int& d : D)
        cin >> d;

    lint M0 = 0;
    for (int i = 0;i < N; i++)
        if (i % 2 == 0)
            M0 += D[i];
        else M0 -= D[i];

    cout << M0;
    for (int i = 1;i < N; i++) {
        M0 = 2 * D[i - 1] - M0;
        cout << " " << M0;
    }
    cout << endl;
    return 0;
};


Measured memory_bytes: 1792
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
using ll = long long;

const long double PI = acos(-1.0);
const int MOD = 1e9 + 7;

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

    
    int ans = 1;
    ll res = 7;
    ll f = 7 % k;

    int cnt = 0;
    while(res % k != 0) {
        res = (10 * res + 7) % k;
        ans++;
        cnt++;
        if(res == f || cnt >= 10e7) {
            ans = -1;
            break;
        }
    }

    cout << ans << endl;
    
    

    return 0;
}

Measured memory_bytes: 3632
fn read<T: std::str::FromStr>(
    stdin_lock: &mut std::io::StdinLock,
    buf: &mut Vec<u8>,
    delimiter: u8,
) -> T {
    buf.clear();
    let l = std::io::BufRead::read_until(stdin_lock, delimiter, buf).unwrap();
    buf.truncate(l - 1); // remove delimiter
    let s = unsafe { std::str::from_utf8_unchecked(&buf) };
    s.parse().unwrap_or_else(|_| panic!("read"))
}

fn main() {
    let stdin = std::io::stdin();
    let mut stdin_lock = stdin.lock();
    let mut buf: Vec<u8> = Vec::new();
    let n: i32 = read(&mut stdin_lock, &mut buf, b'\n');

    let mut ans = false;
    for a in 1..9 + 1 {
        for b in 1..9 + 1 {
            if a * b == n {
                ans = true;
            }
        }
    }
    println!("{}", if ans { "Yes" } else { "No" });
}


Measured memory_bytes: 4352
#include<iostream>
#include<string>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#include<functional>
#include<iomanip>
#include<queue>
#include<cassert>
#include<tuple>
#include<set>
#include<map>
#include<list>
#include<bitset>
#include<utility>
#include<numeric>

#define pb push_back
#define mp make_pair
#define all(a)  (a).begin(),(a).end()
#define dwn(a)  (a).begin(),(a).end(), greater<int>()
#define rep(i, m) for (int i = 0; i < m; i++)
#define REP(i, n, m) for (int i = n; i < m; i++)
#define V vector<int>
#define VV vector<V>
#define VVV vector<VV>

using namespace std;

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

const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
const int INF = (int)1e9;
const ll inf = (ll)1e18;
const ll MOD{ (ll)1e9 + 7 };
const long double EPS = 1e-10;

int main() {
	int n;
	cin >> n;
	vector<ll> a(n);
	rep(i, n) cin >> a[i];
	sort(a.begin(), a.end());
	vector<ll> b(n);
	for (int i = 0; i < n; i++) {
		if (i % 2 == 0) {
			if (i == 0) {
				b[i] = 1;
			}
			else if (i == n - 1) {
				b[i] = 1;
			}
			else {
				b[i] = 2;
			}
		}
		else {
			if (i == 0) {
				b[i] = -1;
			}
			else if (i == n - 1) {
				b[i] = -1;
			}
			else {
				b[i] = -2;
			}
		}
	}
	ll ans1 = 0, ans2 = 0;
	sort(b.begin(), b.end());
	rep(i, n) {
		ans1 += a[i] * b[i];
	}
	rep(i, n) b[i] *= -1;
	reverse(b.begin(), b.end());
	rep(i, n) {
		ans2 += a[i] * b[i];
	}
	cout << max(ans1, ans2) << endl;
	return 0;
}

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

ans = 0

if N <= 9:
    ans = N
elif 10 <= N and N <= 99:
    ans = 9
elif 100 <= N and N <= 999:
    ans = 9 + ( N - 100 + 1 )
elif 1000 <= N and N <= 9999:
    ans = 9 + 900
elif 10000 <= N and N <= 99999:
    ans = 9 + 900 + (N - 10000 + 1)
elif N == 100000:
    ans = 9 + 900 + 90000
    
print(ans)

Measured memory_bytes: 3060
#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;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int MX = 1e5 + 5, INF = 5LL << 57, MOD = 1e9 + 7;

int N, M;
string S;
vi va, vb;
string s, t;

void input() {
  cin >> s;
  cin >> t;
  ;
  ;
}

int dp[3555][3555];
void solve() {
  rep(i, 1, s.size()) {
    ;
    ;
    rep(j, 1, t.size()) {
      ;
      if (s[i - 1] == t[j - 1]) {
        dp[i][j] = dp[i - 1][j - 1] + 1;
        ;
      } else {
        ;
        dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
      };
    }
  }

  debug(dp[s.size()][t.size()]);

  int i, j;
  i = s.size();
  j = t.size();
  int len = dp[i][j];
  char ans[len + 1];
  while (len > 0) {
    if (s[i - 1] == t[j - 1]) {
      ans[len] = s[i - 1];
      i--;
      j--;
      len--;
    } else if (dp[i][j] == dp[i - 1][j]) {
      i--;
    } else {
      j--;
    }
  }
  rep(k, 1, dp[s.size()][t.size()]) { cout << ans[k]; }
  cout << endl;

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

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

int main(){
    ios::sync_with_stdio(false);
	cin.tie(0);
    
    int n;
    cin>>n;
    long long a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    long long dp[n+5][n+5]={};
    for(int i=n-1;i>=0;i--)for(int j=i;j<n;j++){
        if(i==j) dp[i][j]=a[i];
        else{
            dp[i][j]=max(dp[i][j],max(a[i]+min(dp[i+1][j-1],dp[i+2][j]),a[j]+min(dp[i+1][j-1],dp[i][j-2])));
        }
    }
    long long ans=dp[0][n-1];
    if(ans==a[0]+dp[2][n-1]) ans-=dp[1][n-1];
    else if(ans==a[0]+dp[1][n-2]) ans-=dp[1][n-1];
    else if(ans==a[n-1]+dp[1][n-2] || ans==a[n-1]+dp[0][n-3]) ans-=dp[0][n-2];
    cout<<ans<<endl;
}

Measured memory_bytes: 70784
#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define INF 1e9 + 5
using namespace std;

int solve()
{
    int n;
    cin >> n;

    vector<int> a(n);

    for (int i = 0; i < n; i++)
        cin >> a[i];

    vector<int> dp(n, INT_MAX);
    dp[0] = 0;

    for (int i = 0; i < n; i++)
    {
        for (int j : {i + 1, i + 2})
            dp[j] = min(dp[j], dp[i] + abs(a[i] - a[j]));
    }
    return dp[n - 1];
}

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

    /*  int t;
    cin >> t;

    while (t--)*/
    cout << solve();

    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
using namespace std;
typedef long long ll;

int main() {
    ll N;
    cin >> N;
    ll ans = N-1;
    for (ll i = 2; i*i <= N; i++) {
        if (N%i) continue;
        ans = min(ans, i+N/i-2);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int main()
{
	int n,sum=0;
	scanf("%d",&n);
	int b[105];
	for(int i=0;i<n-1;i++)scanf("%d",&b[i]);
	if(n==2)
	{
		printf("%d",b[0]*2);return 0;
	}
	if(n>=3)
	{
		sum+=b[0];sum+=b[n-2];
		for(int i=1;i<n-1;i++)
		{
			if(b[i]>=b[i-1])sum+=b[i-1];
			if(b[i]<b[i-1])sum+=b[i];
		}
		
	}
	printf("%d",sum);
	return 0;
} 

Measured memory_bytes: 128
import java.util.Scanner;

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

        int x = sc.nextInt(), a = sc.nextInt(), b = sc.nextInt();

        if(a >= b){
            System.out.println("delicious");
        } else if(a-b+x>=0){
            System.out.println("safe");
        } else {
            System.out.println("dangerous");
        }
    }
}


Measured memory_bytes: 21844
ans_dict = {}
s = str(input())
list_s = list(s)
list_al = list("abcdefghijklmnopqrstuvwxyz")
for i in range(26):
    ans_dict[list_al[i]] = [-1]

for i in range(len(s)):
    ans_dict[list_s[i]].append(i)

for i in range(26):
    ans_dict[list_al[i]].append(len(list_s))
for key, value in ans_dict.items():
    ans_dict[key] = max([(value[i] - value[i-1]) for i in range(1,len(value))]) - 1

print(min(ans_dict.values()))


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std; inline void fileio(const char* in, const char* out) { freopen(in, "r", stdin); freopen(out, "w", stdout); } 
#define TD typedef
#define forx(i,n) for(int i = 0; i < (n); ++i)
TD long long ll; TD long double ld; TD pair<int,int> pii; TD pair<ll, ll> pll; TD vector<int> VI; TD vector<bool> VB; TD vector<ll> VL;
const char nl = '\n'; const int INF = 0x3f3f3f3f; const ll LINF = 0x3f3f3f3f3f3f3f3fll; const ld EPS = 1e-9, PI = acos(-1);
#define ff first
#define ss second

int main() {
  atexit([](){ cerr << "Time: " << (ld)clock() / CLOCKS_PER_SEC << nl; });
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  // Emily <3
  int n;
  cin >> n;
  int cnt = 0;
  forx(i, n) {
    char c;
    cin >> c;
    if (c == 'R') {
      cnt++;
    } else {
      cnt--;
    }
  }

  cout << (cnt>0 ? "Yes" : "No") << nl;
  
  return 0;
}



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

//LIFE IS NOT A PROBLEM TO BE SOLVED

#define rep(i,a,b) for( int i = (int) a; i < (int) b; i++ )
#define F first
#define S second
#define pb push_back

using namespace std;

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


int main(){
	
	int n; cin >> n;
	int a[n];
	rep(i, 0, n) cin >> a[i];
	int tt = 0;
	sort(a, a+n);
	rep(i, 0, n-1){
		tt+=a[i];
	}
	tt+=(a[n-1]/2);
	cout << tt << '\n';
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <queue>
#include <cstdio>
#include <iomanip>
using namespace std;
typedef long long ll;

int gcd(int a,int b){
    int t;
    while(b>0){
        t=b;
        b=a%b;
        a=t;
    }
    return a;
}

int lcm(int a,int b){
    return a*b/gcd(a,b);
}

int main(){
    ll n,a,b,c,d,e,k,l,m,o=0,p,q,r,x,y,z,max1=0,ans=0;
    string s,t,u;
    cin>>n>>k;
    ll h[n];
    for(ll i=0;i<n;i++){
        cin>>h[i]; 
        if(h[i]>=k)o++;
    }
    cout<<o<<endl;
}






Measured memory_bytes: 1024
#include<stdio.h>
#include<string.h>
char a[10000],b[10000];
int x[10000],y[10000],z[10000];
int main()
{
    int j,i,g;
    while(~scanf("%d%d",&i,&j))
    {
        g=i*i;
        printf("%d",g-j);


    }
}


Measured memory_bytes: 128
N = int(input())
D = [list(map(int, input().split())) for _ in range(N)]
cnt = 0
ans = 'No'
for i in range(N):
    if D[i][0] == D[i][1]:
        cnt += 1
    else:
        cnt = 0
    
    if cnt >= 3:
        ans = 'Yes'
        break

print(ans)

Measured memory_bytes: 9180
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    int a[n];
    for(int i = 0; i < n; i++) cin >> a[i];
    for(int i = 0; i < n; i++){
        for(int j = i + 1; j < n; j++){
            int sa = (int)abs(a[i] - a[j]);
            if(!(sa % (n - 1))){
                cout << a[i] << " " << a[j] << endl;
                return 0;
            }
        }
    }
}


Measured memory_bytes: 3092
import sys
sys.setrecursionlimit(10**9)

n, m = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(m)]

root = [-1] * n

def find(x):
    if root[x] < 0:
        return x
    else:
        return find(root[x])

def unity(x, y):
    gx = find(x)
    gy = find(y)

    if gx == gy:
        return

    if root[gx] > root[gy]:
        gx, gy = gy, gx

    root[gx] += root[gy]
    root[gy] = gx

for a, b in AB:
    a -= 1
    b -= 1
    unity(a, b)

print(-min(root))

Measured memory_bytes: 49884
#include<bits/stdc++.h>
using namespace std;
char s[4003];
//RGB
int back[4003];
int tmp=0,last=0;
int pos[4003];
char zimu[]={'a','R','R','G','G','B','B'},zimu2[]={'a','G','B','R','B','R','G'},zimu3[]={'a','B','G','B','R','G','R'};
//GRB
//RBG
//GBR
//BGR
//BRG
int main(){
	int n;
	scanf("%d",&n);
	scanf("%s",s+1);
	int cnt;
	long long ans=0;
	for(int k=1;k<=6;k++){
		cnt=tmp=last=0;
		memset(back,0,sizeof(back));
		memset(pos,0,sizeof(pos));
		for(int i=n;i>=1;i--){
			if(s[i]==zimu3[k]){
				tmp++;
			}
			if(s[i]==zimu2[k]){
				pos[++cnt]=i;
				back[i]=back[last]+tmp;
				tmp=0;
				last=i;
			}
		}
		for(int i=1;i<=n;i++){
			if(s[i]==zimu[k]){
				for(int j=1;j<=cnt;j++){
					if(pos[j]>i){//printf("ha\n");
						ans+=back[pos[j]];
						if(pos[j]+(pos[j]-i)<=n&&s[pos[j]+(pos[j]-i)]==zimu3[k])ans--;
					}
				}
			}
		}
	}

	printf("%lld\n",ans);
}

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

using ll = long long;
#define REP(i,n) for(int (i) = 0;(i) < (n);(i)++)

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

#define base 200020


bool safe = true;
ll ans = 1e17;

vector<pair<ll,char>> up[2 * base],down[2 * base];
vector<pair<ll,char>> ver[base],ax[base];

int main(void){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;cin >> n;
  vector<pair<pair<ll,ll>,char>> a(n);
  REP(i,n){
    ll x,y;cin >> x >> y;
    char u;cin >> u;
    a[i] = make_pair(make_pair(x,y),u);

    ll b1 = y - x + base;
    up[b1].emplace_back(x,u);

    ll b2 = y + x;
    down[b2].emplace_back(x,u);

    ax[x].emplace_back(y,u);
    ver[y].emplace_back(x,u);
  }
  
  for(int i = 0;i < base;i++){
    if(ax[i].size()){
      sort(ax[i].begin(),ax[i].end());
      bool _up = false;
      ll tmp_u = -1;
      for(auto e : ax[i]){
        if(e.second == 'U'){
          _up = true;
          tmp_u = e.first;
        }else if(e.second == 'D'){
          if(_up){
            chmin(ans,abs(10*e.first - 10*tmp_u)/2);
          }
        }
      }
    }
    if(ver[i].size()){
      sort(ver[i].begin(),ver[i].end());
      bool right = false;
      ll tmp_r = -1;
      for(auto e : ver[i]){
        if(e.second == 'R'){
          right = true;
          tmp_r = e.first;
        }else if(e.second == 'L'){
          if(right){
            chmin(ans,abs(10*e.first - 10*tmp_r)/2);
          }
        }
      }
    }
  }

  for(int i = 0;i < 2*base;i++){
    if(up[i].size()){
      sort(up[i].begin(),up[i].end());
      bool right = false;
      bool _up = false;
      ll tmp_r = 0;
      ll tmp_u = 0;
      for(pair<ll,char> e : up[i]){
        char d = e.second;
        if(d == 'U'){
          tmp_u = e.first;
          _up = true;
        }else if(d == 'D'){
          if(right){
            chmin(ans,10*abs(e.first - tmp_r));
          }
        }else if(d == 'R'){
          right = true;
          tmp_r = e.first;
        }else{
          if(_up){
            chmin(ans,10*abs(e.first - tmp_u));
          }
        }
      }
    }
    if(down[i].size()){
      sort(down[i].begin(),down[i].end());
      bool right = false;
      bool _down = false;
      ll tmp_r = 0;
      ll tmp_d = 0;
      for(auto e : down[i]){
      //  cout << e.first << ' ' << e.second << '\n';
        char d = e.second;
        if(d == 'U'){
          if(right){
      //      cout << "DU" << '\n';
            chmin(ans,10*abs(e.first - tmp_r));
          }
        }else if(d == 'D'){
          _down = true;
          tmp_d = e.first;
        }else if(d == 'R'){
          right = true;
          tmp_r = e.first;
        }else{
          if(_down){
       //     cout << "DL" << '\n';
            chmin(ans,10*abs(e.first - tmp_d));
          }
        }
      }
    }
  }
  if(ans == 1e17){
    cout << "SAFE" << '\n';
  }else{
    cout << ans << '\n';
  }
}


Measured memory_bytes: 57744
import io, os
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
import sys

# sys.stdout.write(str(n)+"\n")

n = int(input())

digit = n % 10
if digit in set({2, 4, 5, 7, 9}):
	print("hon")
elif digit in set({0, 1, 6, 8}):
	print("pon")
else:
	print("bon")

Measured memory_bytes: 61900
#include <iostream>
#include <fstream>
#include <cmath>  
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <numeric>
#include <functional>
#include <string> 
#include <vector>
#include <bitset>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>

using namespace std;
using ll = long long;

#define REP(i,n) for(long long i = 0; i < (n); i++)
#define FOR(i, m, n) for(long long i = (m);i < (n); ++i)
#define ALL(obj) (obj).begin(),(obj).end()

template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;

const ll MOD = (ll)1e9 + 7;
const ll MOD2 = 998244353;
const ll LLINF = (ll)1e18;
const ll INTINF = (ll)1e9;
const long double PI = 3.1415926535897932384626433;

template <class T> void corner(bool flg, T hoge) { if (flg) { cout << hoge << endl; exit(0); } }
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) { o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o; }
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) { o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o; }
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) { o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o; }
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) { o << "{" << obj.first << ", " << obj.second << "}"; return o; }
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) { o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o; }
void print(void) { cout << endl; }
template <class Head> void print(Head&& head) { cout << head; print(); }
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) { cout << head << " "; print(forward<Tail>(tail)...); }
template <class T> void chmax(T& a, const T b) { a = max<T>(a, b); }
template <class T> void chmin(T& a, const T b) { a = min<T>(a, b); }
void YN(bool flg) { cout << ((flg) ? "YES" : "NO") << endl; }
void Yn(bool flg) { cout << ((flg) ? "Yes" : "No") << endl; }
void yn(bool flg) { cout << ((flg) ? "yes" : "no") << endl; }

int main() {
	ll N, K; cin >> N >> K;
	V<ll> A(N); REP(i, N) cin >> A[i];
	V<ll> bit(60, 0);
	REP(i, N) REP(j, 60) if (A[i] & (1LL << j)) bit[j]++;
		
	ll ans = 0;
	REP(j, N) ans += (K^A[j]);

	for (ll i = 59; 0 <= i; --i) {
		if (!(K&(1LL << i))) continue;
		ll X = K;
		X ^= (1LL << i);
		for(ll j = i - 1; 0 <= j; --j){
			if (X & (1LL << j)) X ^= (1LL << j);
			if (bit[j] < N - bit[j]) X ^= (1LL << j);
		}
		ll sum = 0;
		REP(j, N) sum += (X^A[j]);
		chmax(ans, sum);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const int inf = 1e9;
const ll INF = 1e18;
const double pi = 3.14159265358979323846;
#define rep(i,n) for(ll i=0;i<n;i++)

int main(){
	int n;cin>>n;
	int a,cnt2=0,cnt4=0;
	rep(i,n){
		cin>>a;
		if(a%4==0) cnt4++;
		else if(a%2==0) cnt2++;
	}
	//cout<<cnt4<<" "<<cnt2<<"\n";
	if(n%2==0){
		if(cnt4+cnt2/2>=n/2) cout<<"Yes"<<"\n";
		else cout<<"No"<<"\n";
	}
	else{
		if(cnt4>=n/2) cout<<"Yes"<<"\n";
		else if(cnt4+(cnt2+1)/2>=(n+1)/2) cout<<"Yes"<<"\n";
		else cout<<"No"<<"\n";
	}
}

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

int main(){
	int N,W;
	int v[101],w[101];

	cin >> N >> W;
	for(int i=0; i<N; ++i) cin >> v[i] >> w[i];
	
	int dp[101][10001]={};
	
	for(int i=0; i<N; ++i){
		for(int j=0; j<=W; ++j){
			if(j-w[i]>=0)
				dp[i+1][j] = max( dp[i+1][j-w[i]]+v[i], dp[i][j] );
			else dp[i+1][j] = dp[i][j];
		}
	}

	printf("%d\n", dp[N][W]);
}


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

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

  int n;
  cin >> n;
  set<vector<int>> st;
  for(int i = 0; i < n; ++i) {
    vector<int> p(3);
    cin >> p[0] >> p[1] >> p[2];
    sort(p.begin(), p.end());
    st.insert(p);
  }
  cout << n - st.size() << endl;
}


Measured memory_bytes: 3300
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) throws FileNotFoundException {

//    Scanner cin = new Scanner(new FileReader("input.txt"));
    Scanner cin = new Scanner(System.in);

    String item = "keyence";
    String in = cin.next();

    int pos = in.indexOf(item);
    int pos2 = in.lastIndexOf(item);
    if (pos==0||pos2==in.length()-item.length()) {
      System.out.println("YES");
      return;
    }

    for (int i=0;i<item.length();i++) {
      String a = item.substring(0,i+1);
      String b = item.substring(i+1,item.length());
      //System.out.println(a);
      //System.out.println(b);
      int posA = in.indexOf(a);
      int posB = in.lastIndexOf(b);

      if (posA==0&&posB==in.length()-b.length()){
        System.out.println("YES");
        return;
      }
      else {
        continue;
      }

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

  }

}

Measured memory_bytes: 23764
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <tuple>

using namespace std;

using lint = long long;
using ldouble = long double;
template <class T>
using greater_priority_queue = priority_queue<T, vector<T>, greater<T>>;

const int INF = 1 << 30;

bool solve() {
    int N, M, L;
    cin >> N >> M >> L;
    if (N == 0) return false;

    auto encode = [&](int v, int l) {
        return v + l * N;
    };

    vector<vector<pair<int, int>>> graph(N * (L + 1));
    for (int i = 0; i < M; ++i) {
        int u, v, d, e;
        cin >> u >> v >> d >> e;
        --u, --v;

        for (int l = 0; l + d <= L; ++l) {
            graph[encode(u, l + d)].emplace_back(encode(v, l), 0);
            graph[encode(v, l + d)].emplace_back(encode(u, l), 0);
        }

        for (int l = 0; l <= L; ++l) {
            graph[encode(u, l)].emplace_back(encode(v, l), e);
            graph[encode(v, l)].emplace_back(encode(u, l), e);
        }
    }

    greater_priority_queue<pair<int, int>> que;
    que.emplace(0, encode(0, L));

    vector<int> dist(N * (L + 1), INF);
    dist[encode(0, L)] = 0;

    while (!que.empty()) {
        int d, v;
        tie(d, v) = que.top();
        que.pop();

        if (d > dist[v]) continue;

        for (auto p : graph[v]) {
            int sv, sd;
            tie(sv, sd) = p;
            if (dist[sv] <= dist[v] + sd) continue;
            dist[sv] = dist[v] + sd;
            que.emplace(dist[sv], sv);
        }
    }

    int ans = INF;
    for (int l = 0; l <= L; ++l) {
        ans = min(ans, dist[encode(N - 1, l)]);
    }
    cout << ans << endl;
    return true;
}

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



Measured memory_bytes: 8652
import sys
from collections import deque
import copy
def main():
    N, M = map(int, input().split())
    s = [[] for i in range(M)]
    for i in range(M):
        lines = [int(k) for k in input().split()]
        for j in range(len(lines)):
            if j == 0:
                continue
            s[i].append(lines[j] - 1)
    p = [int(i) for i in input().split()]
    ans = 0
    for i in range(1 << N):
        switchs = [0] * N
        flag = True
        for j in range(N):
            if (i >> j) & 1:
                switchs[j] = 1
        for k in range(M):
            count = 0
            for t in range(len(s[k])):
                if switchs[s[k][t]] == 1:
                    count += 1
            if count % 2 != p[k]:
                flag = False
                break
        if flag:
            ans += 1
    print(ans)


if __name__ == '__main__':
    main()


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

int main(){
  int N;
  cin >> N;
  vector<int> ans(26);
  for(int i=0; i<26; i++) ans.at(i)=50;
  for(int i=0; i<N; i++){
    string S;
    cin >> S;
    vector<int> cnt(26);
    for(int i=0; i<S.size(); i++){
      cnt.at(S.at(i)-97)++;
    }
    for(int i=0; i<26; i++){
      ans.at(i)=min(ans.at(i),cnt.at(i));
    }
  }
  string W;
  for(int i=0; i<26; i++){
    for(int j=0; j<ans.at(i); j++) W += (char)(i+97);
  }
  cout << W << endl;
}

Measured memory_bytes: 256
/*
-------関数一覧--------
arr1dto2d(Array) 一次元配列を二次元配列にします
pf(N)因数分解した結果をオブジェクトで返します
gcd(a,b)最大公約数を返します
lcm(a,b)最小公倍数を返します
up(a,b)a-bを返します。ソート用です
down(a,b)a+bを返します。ソート用です
*/
function Main(input) {
  //write here!
  input = input.split("");
  if(input.length==3) console.log(input.reverse().join(""));
  else console.log(input.join(""));
}Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());
function arr1dto2d (arr){
	for(var i=0;i<arr.length;i++){
    arr[i]=arr[i].split(" ").map(Number);
    }
  return arr;
}
function pf(n) {
    var result = {};
    
    if (n === 1) {
        return {"1":1}
    }

    var init = 2;

    while (n !== 1) {
        var i = init;
        while (i < Number.MAX_SAFE_INTEGER) {
            if (n % i === 0) {
                n /= i;
                if (!(result[i] > 0)) {
                    result[i] = 0;
                }
                result[i]++;
                break;
            }
            i++;
        }
        init = i;
    }
    return result;
}
function gcd(a, b) {
    if (b === 0){
        return a
    }
    return gcd(b, a % b)
}
function lcm(a,b) {
    var g = (n, m) => m ? g(m, n % m) : n
    return a * b / g(a, b)
}
function up(a, b) {
  return a - b;
}
function down(a, b) {
  return a + b;
}

Measured memory_bytes: 7372
import math
n, a, b = map(int,input().split(' '))

h = [ 0 for i in range(n)]

def enough(x):
    cnt=0
    for hi in h:
        if hi>b*x:
            cnt+= math.ceil((hi-b*x)/(a-b))
    return cnt <= x

for i in range(n):
    h[i]=int(input())

x_max = max(h)
x_min = 0
while(x_max - x_min > 1):
    x_mid = (x_max + x_min)//2
    if(enough(x_mid)):
        x_max = x_mid
    else:
        x_min = x_mid

print(x_max)

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

int main() {
  int N;
  cin >> N;
  long long ans = 0;
  int MaxH = 0;
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    MaxH = max(MaxH, a);
    ans += MaxH - a;
  }
  
  cout << ans;
}

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

using namespace std;
using ll = long long;
#define int ll
using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define PB push_back

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const int MOD = 1000000007;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }
template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')';
  return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'[';
  REP(i, a.size()) {out<<a[i];if(i!=a.size()-1)out<<',';}
  out<<']';
  return out;
}

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

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

  const double EPS = 1e-8;

  while(true) {
    int n;
    cin >> n;
    if(!n) break;
    vector<double> x(n), y(n), z(n), vx(n), vy(n), vz(n), r(n), vr(n);
    REP(i, n) cin >> x[i] >> y[i] >> z[i] >> vx[i] >> vy[i] >> vz[i] >> r[i] >> vr[i];

    vector<pair<double,PII>> event;
    REP(i, n) {
      event.PB({r[i]/vr[i], {i, -1}});
      FOR(j, i+1, n) {
        double A = (vx[i]-vx[j])*(vx[i]-vx[j]) + (vy[i]-vy[j])*(vy[i]-vy[j]) + (vz[i]-vz[j])*(vz[i]-vz[j]) - (vr[i]+vr[j])*(vr[i]+vr[j]);
        double B = ((vx[i]-vx[j])*(x[i]-x[j]) + (vy[i]-vy[j])*(y[i]-y[j]) +(vz[i]-vz[j])*(z[i]-z[j]) + (r[i]+r[j])*(vr[i]+vr[j]));
        double C = (x[i]-x[j])*(x[i]-x[j]) + (y[i]-y[j])*(y[i]-y[j]) + (z[i]-z[j])*(z[i]-z[j]) - (r[i]+r[j])*(r[i]+r[j]);

        // Ax^2 + Bx + C = 0
        double D = B*B-A*C;
        if(D < EPS) continue;
        double ans1 = (-B-sqrt(B*B-A*C))/A;
        double ans2 = (-B+sqrt(B*B-A*C))/A;

        if(ans1 < EPS && ans2 < EPS) continue;
        if(ans1 < EPS) event.PB({ans2, {i, j}});
        else event.PB({ans1, {i, j}});
      }
    }

    sort(ALL(event));
    VI exist(n, 1);
    vector<double> ret(n, -1);
    REP(i, event.size()) {
      if(event[i].second.second == -1 && exist[event[i].second.first] == 1) {
        ret[event[i].second.first] = event[i].first;
        exist[event[i].second.first] = 0;
      } else if(exist[event[i].second.first] == 1 && exist[event[i].second.second] == 1) {
        ret[event[i].second.first] = ret[event[i].second.second] = event[i].first;
        exist[event[i].second.first] = exist[event[i].second.second] = 0;
      }
    }

    REP(i, n) cout << fixed << setprecision(12) << ret[i] << endl;
  }

  return 0;
}



Measured memory_bytes: 4308
import sys
from collections import *
import heapq
import math
import bisect
from itertools import permutations,accumulate,combinations,product
from fractions import gcd
def input():
    return sys.stdin.readline()[:-1]
mod=pow(10,9)+7

n,h=map(int,input().split())
ab=[list(map(int,input().split())) for i in range(n)]
alst=[]
blst=[]
for i in range(n):
    a,b=ab[i]
    alst.append(a)
    blst.append(b)
maxa=max(alst)
alst.sort()
blst.sort(reverse=True)
cnt=0
for i in range(n):
    if maxa<blst[i]:
        cnt+=1
        h-=blst[i]
    else:
        break
    if h<=0:
        print(cnt)
        exit()
# print(cnt)
print(math.ceil(h/maxa)+cnt)

Measured memory_bytes: 31472
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <istream>
#include <sstream>
#include <cctype>
#include <iomanip>
//cout << fixed << setprecision(20) << *** << endl;
#define rep(i,N) for(int i=0;i<(int)N;++i)
typedef long long ll;
using namespace std;
int main()
{
	ll A,B,C,D,N,MIN;
	cin>>A>>B>>C>>D>>N;
	A=A*4;
	B=B*2;
	MIN=min(A,B);
	MIN=min(MIN,C);
	if(D>=MIN*2){
		cout<<MIN*N<<endl;
	}
	else{
		if(N%2==0){
			cout<<D*(N/2)<<endl;
		}
		else{
			cout<<D*(N/2)+MIN<<endl;
		}
	}
}

Measured memory_bytes: 256
import math
K,A,B = map(int, input().split())
cookie = 0

if abs(A-B) <= 1:
    print(K + 1)
elif A > B:
    print(K + 1)

else:
    cookie = B
    K = K-A-1

    if K%2==0:
        cookie += (B-A)* math.floor(K/2)
        print(cookie)
    else:
        cookie += (B-A)*math.floor((K-1)/2)
        print(cookie + 1)


Measured memory_bytes: 3060
import math

N=int(input())
List = list(map(int, input().split()))
mid = List[0]
for i in range(1,N):
  mid = mid * List[i] // math.gcd(mid, List[i])
res = 0
for i in range(N):
  res += (mid-1) % List[i]
print(res)

Measured memory_bytes: 9360
n,k = map(int,input().split())
r,s,p = map(int,input().split())
t = input()

def ten(a):
  if a=="r":
    return p
  elif a=="s":
    return r
  else:
    return s

l = [0 for _ in range(n)]  
for i in range(k):
  l[i] += ten(t[i])
for i in range(k,n):
  if t[i]==t[i-k]:
    if l[i-k]==0:
      l[i] += ten(t[i])
  else:
    l[i] += ten(t[i])
print(sum(l))

Measured memory_bytes: 7156
package main

import "fmt"

func main() {
	var s string
	fmt.Scan(&s)

	var zero int
	var one int
	for i := 0; i < len(s); i++ {
		if s[i:i+1] == "0" {
			zero++
		} else {
			one++
		}
	}
	if zero > one {
		fmt.Println(one * 2)
	} else {
		fmt.Println(zero * 2)
	}
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
char a [100][101] , b [102][102];
int main(){
int H , W ; cin >> H >> W ;
  for ( int i = 0; i < H ; i ++)
    for(int j=0;j<W;j++)
      cin>>a [ i ][j];

  for ( int i = 0; i < H + 2; i ++)
    for ( int j = 0; j < W + 2; j ++)
      b[i][j] = '#';
  for ( int i = 0; i < H ; i ++)
    for ( int j = 0; j < W ; j ++)
      b [ i + 1][ j + 1] = a [ i ][ j ];
  for ( int i = 0; i < H + 2; i ++) {
    for ( int j = 0; j < W + 2; j ++)
      cout << b [ i ][ j ];
    cout << endl ;
  }
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,a[100002];
long long f[100002];
int main(){
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    f[1]=0;
    f[2]=abs(a[2]-a[1]);
    for(int i=3;i<=n;i++){
        f[i]=min(f[i-2]+abs(a[i]-a[i-2]),f[i-1]+abs(a[i]-a[i-1]));
    }
    cout<<f[n];
}

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

using namespace std;

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

    int cnt=0;
    for(int i=0;i<s.length()/2;i++){
        if(s[i]!=s[s.length()-1-i]) cnt++;
    }

    cout << cnt << endl;
}

Measured memory_bytes: 384
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

typedef long double ld;
typedef long long ll;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define pb push_back
#define mp make_pair
#define sz(x) ((int) (x).size())
#define TASK "text"

const int inf = (int) 1.01e9;
const ld eps = 1e-9;
const ld pi = acos((ld) -1);

mt19937 mrand(random_device{} ()); 

int rnd(int x) {
  return mrand() % x;
}

void precalc() {
}

const int maxn = (int) 1e3 + 5, mod = (int) 1e9 + 7;
int n, a, b, c, d;

int read() {
  if (scanf("%d%d%d%d%d", &n, &a, &b, &c, &d) < 5) {
    return false;
  }
  return true;
}

void add(int &a, int b) {
  a += b;
  if (a >= mod) {
    a -= mod;
  }
}

int mul(int a, int b) {
  return (long long) a * b % mod;
}

pair<int, int> gcd(int a, int b) {
  if (!b) {
    return make_pair(1, 0);
  }
  pair<int, int> p = gcd(b, a % b);
  return make_pair(p.second, p.first - (a / b) * p.second);
}

int inv(int x) {
  int res = gcd(x, mod).first;
  if (res < 0) {
    res += mod;
  }
  return res;
}

int f[maxn];
int finv[maxn][maxn];
int dp[maxn][maxn];

void solve() {
  f[0] = 1;
  for (int i = 1; i <= n; i++) {
    f[i] = mul(f[i - 1], i);
  }
  for (int i = 0; i <= n; i++) {
    finv[i][0] = 1;
    finv[i][1] = inv(f[i]);
    for (int j = 2; j <= n; j++) {
      finv[i][j] = mul(finv[i][j - 1], finv[i][1]);
    }
  }
  memset(dp, 0, sizeof(dp));
  dp[n][n] = 1;
  for (int i = n; i > 0; i--) {
    for (int j = 0; j <= n; j++) {
      if (!dp[i][j]) {
        continue;
      }
      add(dp[i - 1][j], dp[i][j]);
      if (a <= i && i <= b) {
        for (int k = c; k <= d; k++) {
          if (k * i <= j) {
            add(dp[i - 1][j - k * i], mul(dp[i][j], mul(mul(f[j], finv[j - k * i][1]), mul(finv[i][k], finv[k][1]))));
          }
        }
      }
    }
  }
  printf("%d\n", dp[0][0]);
}

int main() {
  precalc();
#ifdef LOCAL
  assert(freopen(TASK ".in", "r", stdin));
  assert(freopen(TASK ".out", "w", stdout));
#endif
  while (true) {
    if (!read()) {
      break;
    }
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}


Measured memory_bytes: 8192
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
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;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
const ll mod=1e9+7;
const int inf=1<<30;

struct unionfind{
  vector<int> par;
  vector<int> rank;
  unionfind(int n=1){
    init(n);
  }
  void init(int n=1){
      par.resize(n); rank.resize(n);
      for(int i=0;i<n;++i) par[i]=i,rank[i]=0;
  }
  int root(int x){
    if(par[x]==x){
      return x;
    }
    else{
      int r=root(par[x]);
      return par[x]=r;
    }
  }
  bool issame(int x,int y){
    return root(x)==root(y);
  }
  bool merge(int x,int y){
    x=root(x); y=root(y);
    if(x==y) return false;
    if(rank[x]<rank[y]) swap(x,y);
    if(rank[x]==rank[y]) ++rank[x];
    par[y]=x;
    return true;
  }
};

int main(){
  int n; cin >> n;
  int max=1e5+10;
  unionfind uf(2*max);
  vector<int> x(n);
  vector<int> y(n);
  rep(i,n){
    cin >> x[i] >> y[i];
    uf.merge(x[i],max+y[i]);
  }
  map<int,ll> mpx;
  map<int,ll> mpy;
  rep(i,max){
    mpx[uf.root(i)]++;
  }
  for(int i=max;i<2*max;i++){
    mpy[uf.root(i)]++;
  }
  ll ans=0;
  for(auto c:mpx){
    ans+=c.second*mpy[c.first];
  }
  ans-=n;
  cout << ans << endl;
}

Measured memory_bytes: 21248
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define COUT(x) cout<<(x)<<endl
#define dump(x)  cout << #x << " = " << (x) << endl;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
using M = map<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int, vector<int>, greater<int>>;

const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a; }

int main() {
  ll N,K;
  cin >> N >> K;

  vector<mint> dp(K+1, 0);
  for (int i = K; i >= 1; --i) {
    dp[i] = mint(K/i).pow(N);
    for(int p = i * 2; p <= K; p += i) {
      dp[i] -= dp[p];
    }
  }

  mint ans = 0;
  REP(i,K+1) ans += dp[i] * i;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3936
import java.util.Scanner;
public class Main{

	public static void main(String[] args) {
		Scanner input =new Scanner(System.in);
		int d=input.nextInt();
		int t=input.nextInt();
		int s=input.nextInt();
		float a= (float)d/s;
		if(a<=t)
			System.out.println("Yes");
		else
			System.out.println("No");
		

	}

}


Measured memory_bytes: 35668
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <climits>
#include <cmath>
#include <utility>
#include <string>
#include <cstring>
#include <functional>

using namespace std;

// const int maxn = 100002;

int n;
vector<pair<int, int> > d;

int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	cin >> n;
	for (int i = 0; i < n; ++i) {
		int a, b;
		cin >> a >> b;
		d.push_back(make_pair(b, a));
	}

	sort(d.begin(), d.end());

	long long sum = 0;
	for (int i = 0; i < n; ++i) {
		sum += d[i].second;
		if (sum > d[i].first) {
			cout << "No" << endl;
			return 0;
		}
	}

	cout << "Yes" << endl;

	return 0;
}

Measured memory_bytes: 2420
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>

using namespace std;

int main() {
	int a[3];
	scanf("%d %d %d", &a[0], &a[1], &a[2]);
	int max = *max_element(begin(a), end(a));
	int min = *min_element(begin(a), end(a));
	int mid;
	if (&max == &a[0]) {
		if (&min == &a[1]) {
			mid = a[2];
		} else mid = a[1];
	} else if(&max == &a[1]) {
		if (&min == &a[2]) {
			mid = a[0];
		} else mid = a[2];
	} else {
		if (&min == &a[1]) {
			mid = a[2];
		} else mid = a[1];
	}
	cout << abs(min - mid) + abs(max - mid) << endl;
}


Measured memory_bytes: 256
/**
  *    author: Behradm
  *    Created: %Y%.%M%.%D% %h%:%m%:%s%
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	n = n % 10;
	if (n == 2 || n == 4 || n == 5 || n == 7 || n == 9)
		cout << "hon";
	else if (n == 0 || n == 1 || n == 6 || n == 8)
		cout << "pon";
	else
		cout << "bon";
	return 0;
}



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

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = Integer.parseInt(scanner.next());
        int l = Integer.parseInt(scanner.next());

        String[] ans = new String[n];
        for (int i=0; i< n; i++) {
            ans[i] = scanner.next();
        }

        Arrays.sort(ans);

        for (String a: ans)
            System.out.print(a);

    }
}


Measured memory_bytes: 21332
def knapsack(N,W,weight,value):

  inf=float("inf")
  dp=[[-inf for i in range(W+1)] for j in range(N+1)]
  for i in range(W+1): dp[0][i]=0


  for i in range(N):
    for w in range(W+1):
      if weight[i]<=w:
        dp[i+1][w]=max(dp[i][w-weight[i]]+value[i], dp[i][w])
      else:
        dp[i+1][w]=dp[i][w]
    #print(dp[N][W])
  return dp[N][W]

if __name__ == '__main__':
    N,W = map(int, input().split())
    weight = []
    value = []
    for i in range(N):
        va,we = map(int, input().split())
        weight.append(we)
        value.append(va)
    print(knapsack(N,W,weight,value))


Measured memory_bytes: 42508
import math
from decimal import Decimal

N = int(input())

res = ""

alp = "0abcdefghijklmnopqrstuvwxyz"

while N > 0:
    # print(N)
    if N > 26:
        
        NN = N//26
        # print("NN: ", NN)
        # print(N - NN*26)
        m = N - NN*26
        N = N//26
        # print("m is ", m)
        if m==0:
            m=26
            N = N-1
        # print(alp[m], "!")
        res = alp[m] + res
    else:
        # print(alp[N])
        # print(alp[N], "!")
        res = alp[N] + res
        N = 0

print(res)

Measured memory_bytes: 9880
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <string>
#include <list>
using namespace std;
int main() {
	string a;
	cin >> a;
	if (a == "ABC") {
		cout << "ARC" << endl;
	}
	else {
		cout << "ABC" << endl;
	}
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;

int main() {
  ll l, r;
  cin >> l >> r;

  set<int> mods;
  for (ll i = l; i <= r; i++) {
    int mod = i % 2019;
    mods.insert(mod);
    if (mods.size() >= 2019) break;
  }

  vector<int> m;
  for (auto itr = mods.begin(); itr != mods.end(); itr++) {
    m.push_back(*itr);
  }

  int ans = 2020;
  for (int i = 0; i < m.size(); i++) {
    for (int j = i + 1; j < m.size(); j++) {
      ans = min(ans, (m[i] * m[j]) % 2019);
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 3672
#include <iostream>
using namespace std;
typedef long long int LLI;
int main()
{
  	string s;
  	cin >> s;
  	bool check = false;
  	int arr['z'-'a'+1]{};
  	for(int i = 0; i < s.size(); i++)
    {
      arr[s[i] - 'a']++;
      if( arr[ s[i] - 'a'] > 1 )
        check = true;
    }
  	if( check == false )
      cout << "yes";
  	else
      cout << "no";
	return 0;
}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 81;
bool dp[MAXN][MAXN][MAXN * MAXN * 2];
int a[MAXN][MAXN], b[MAXN][MAXN];
int main()
{
    int n, m; scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++) 
            scanf("%d", &a[i][j]);
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++) 
            scanf("%d", &b[i][j]);
    dp[0][1][6400] = dp[1][0][6400] = 1;
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++)
        {
            int d = a[i][j] - b[i][j];
            for (int k = 0; k <= 80 * 160; k++)
            {
                bool f = dp[i - 1][j][k] | dp[i][j - 1][k];
                if (k + d >= 0) dp[i][j][k + d] |= f;
                if (k - d >= 0) dp[i][j][k - d] |= f;
            }
        }
    int ans = 1e9;
    for (int k = 0; k <= 80 * 160; k++) if (dp[n][m][k])
        ans = min(ans, abs(k - 6400));
    printf("%d\n", ans);
    return 0;
}

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

int main () {
	
	int x=0, i=0;
	vector <int> vi;

	for (i=0; i<5; i++) {
		cin >> x;
		vi.push_back(x);
	}

	sort(vi.begin(), vi.end());

	long long int res=INT_MAX-100, time=0;
	int c=0;

	time = 0;
	for (i=0; i<5; i++) {
		time += vi[i];
		if (i!=4) while (time%10 != 0) time++;
	}
	res = min(time, res);

	while (next_permutation(vi.begin(), vi.end())) {

		time = 0;
		for (i=0; i<5; i++) {
			time += vi[i];
			if (i!=4) while (time%10 != 0) time++;
		}

		res = min(time, res);
		c++;
	}
	
	cout << res << endl;

	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

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

      int n = Integer.parseInt(br.readLine());
      int[] seqS = new int[n];
      String[] line = br.readLine().split(" ");
      for (int i=0; i<n; i++)
        seqS[i] = Integer.parseInt(line[i]);

      int q = Integer.parseInt(br.readLine());
      line = br.readLine().split(" ");
      
      int cnt=0;
      for (String ref : line) {
        if( isExistSeachByBinary(seqS, Integer.parseInt(ref)) )
          cnt++;
      }

      System.out.println(cnt);
    }
  }

  static boolean isExistSeachByBinary(int[] tar, int ref) {
    int left = 0;
    int right= tar.length;
    int mid;
    while( left < right ) {
      mid  = (left + right) / 2;
      if( tar[mid] == ref ) return true;
      else if( tar[mid] > ref ) right = mid;
      else left = mid + 1;
    }

    return false;
  }
}


Measured memory_bytes: 51648
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define REP(i,n) for (ll i = 0; i < (n); ++i)


void solve(long long N, std::string S){
    ll ans = 0;
    for(ll i = 0; i + 2 < N; ++i){
        if(S.substr(i, 3) == "ABC"){
            ans++;
        }
    }
    cout << ans << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools
int main(){
    long long N;
    scanf("%lld",&N);
    std::string S;
    std::cin >> S;
    solve(N, S);
    return 0;
}


Measured memory_bytes: 256