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

#define MOD 1000000007
#define rep(i, n) for(ll i=0; i < (n); i++)
#define rrep(i, n) for(ll i=(n)-1; i >=0; i--)
#define ALL(v) v.begin(),v.end()
#define rALL(v) v.rbegin(),v.rend()
#define FOR(i, j, k) for(ll i=j;i<k;i++)
#define debug_print(var) cerr << #var << "=" << var <<endl;
#define DUMP(i, v)for(ll i=0;i<v.size();i++)cerr<<v[i]<<" "

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<ll, ll> P;
typedef long double ld;
struct edge{ll x, c;};

ll mod(ll a, ll mod){
  ll res = a%mod;
  if(res<0)res=res + mod;
  return res;
}

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

ll modinv(ll a, ll mod){
  return modpow(a, mod-2, mod);
}

ll gcd(ll a, ll b){
  ll r = a%b;
  if(r==0) return b;
  else return gcd(b, a%b);
}

bool is_prime(ll n){
  ll i = 2;
  if(n==1)return false;
  if(n==2)return true;
  bool res = true;
  while(i*i <n){
    if(n%i==0){
      res = false;
    }
    i = i+1;
  }

  //if(i==1)res = false;
  if(n%i==0)res=false;
  return res;
}

struct UnionFind{
  ll N;
  llvec p;
  llvec cnt;
  UnionFind(ll n){
    N = n;
    p=llvec(N);
    cnt=llvec(N, 0);
    rep(i, N){
      p[i] = i;
      cnt[i] = 1;
    }
  }

  void con(ll a, ll b){
    P at = root(a);
    P bt = root(b);
    if(at.second!=bt.second){
      if(at.first>bt.first){
        swap(at, bt);
        swap(a, b);
      }
      p[at.second] = bt.second;
      cnt[bt.second]+=cnt[at.second];
      p[a]=bt.second;
    }
  }

  P root(ll a){
    ll atmp = a;
    ll c=0;
    while(atmp!=p[atmp]){
      atmp = p[atmp];
      c++;
    }
    p[a] = atmp;
    return {c, atmp};
  }

  bool is_con(ll a, ll b){
    P at=root(a);
    P bt=root(b);
    return at.second == bt.second;
  }
  
};

struct dijkstra{
  ll N;
  llvec d;
  vector<vector<edge>> e;
  dijkstra(ll n){
    N = n;
    //d = llvec(N, 1e18);
    e = vector<vector<edge>>(N);
  }

  void add_edge(ll from, ll to, ll cost){
    e[from].push_back({to, cost});
  }

  void run(ll start){
    priority_queue<P, vector<P>, greater<P>> que;
    que.push({0, start});
    d = llvec(N, 1e18);
    d[start]=0;
    while(!que.empty()){
      P q = que.top();que.pop();
      ll dc = q.first;
      ll x = q.second;
      if(dc>d[x]){
        continue;
      }else{
        for(auto ip: e[x]){
          if(d[ip.x]<=d[x]+ip.c){
            continue;
          }else{
            d[ip.x]= d[x]+ip.c;
            que.push({d[ip.x], ip.x});
          }
        }
      }
    }
  }  
};


/**************************************
** A main function starts from here  **
***************************************/
int main(){
  llvec a(3);
  rep(i, 3)cin >> a[i];
  sort(ALL(a));
  ll ans = 1e10;
  do{
    ans = min(ans, abs(a[1]-a[0]) + abs(a[1]-a[2]));
  }while(next_permutation(ALL(a)));
  cout << ans;
  return 0;
}


Measured memory_bytes: 3632
import math

A_senti, B_senti, H_ji, M_fun = map(int, input().split())

rad_A = 360 * (H_ji + M_fun / 60) / 12
rad_B = 360 * (M_fun) / 60

rad = math.radians(min(abs(rad_B - rad_A), 360 - abs(rad_B - rad_A)))

square_c = A_senti ** 2 + B_senti ** 2 - 2 * A_senti * B_senti * math.cos(rad)
ans = math.sqrt(square_c)

print(ans)

Measured memory_bytes: 9448
package main

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

func solution(n, k int, nums []int) float64 {
	s := make([]float64, n+1)
	s[0] = 0.0
	var sum float64
	for i := 1; i < n+1; i++ {
		sum += (1.0 + float64(nums[i-1])) / 2.0
		s[i] = sum
	}
	var ans float64 = -1 << 63
	for i := 0; i <= n-k; i++ {
		ans = max(ans, s[i+k]-s[i])
	}
	return ans
}

func max(x, y float64) float64 {
	if x > y {
		return x
	}
	return y
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())
	sc.Scan()
	k, _ := strconv.Atoi(sc.Text())

	nums := make([]int, n)
	for i := 0; i < n; i++ {
		sc.Scan()
		nums[i], _ = strconv.Atoi(sc.Text())
	}

	fmt.Println(solution(n, k, nums))
}


Measured memory_bytes: 4608
n = int(input())
S = input()
W = [0]*(n+1)
B = [0]*(n+1)
for i in range(n):
    if S[i] == '.':
        W[i] = 1
    else:
        B[i] = 1
for i in range(1,n+1):
    W[i] += W[i-1]
    B[i] += B[i-1]
W = [0] + W
B = [0] + B
res = n
for i in range(n+1):
    res = min(W[-1]-W[i]+B[i],res)
print(res)


Measured memory_bytes: 20644
N = int(input())
d = [0]*N
for i in range(N):
    d[i] = int(input())
d.sort(reverse=True)
bef = d[0]
ans = 1
for j in range(1, N):
    if bef > d[j]:
        ans += 1
        bef = d[j]
print(ans)


Measured memory_bytes: 3060
//***Little by little one travels far***
 
#include<bits/stdc++.h>
using namespace std;
 
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define ll long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i,n) for(i=0;i<n;i++)
#define forn(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define for1(i, n) for (ll i = 1; i <= (ll)(n); ++i)
#define ford(i, n) for (ll i = (ll)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (ll i = (ll)(a); i <= (ll)(b); ++i)
#define fora(it,x) for(auto it:x)
#define PI 3.14159265
#define sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define endl "\n"
 
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef long double ld;
 
template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

int main()
{
  ll n,c=0;
  cin>>n;

  string s;
  cin>>s;

  forn(i,n-2){
    if((s[i]=='A')&&(s[i+1]=='B')&&(s[i+2]=='C')) c++;
  }

  cout<<c;
}

Measured memory_bytes: 256
using System;

namespace Cs_Tutorial
{
    class Program
    {
        public static void A_Add_Sub_Mul()
        {
            // スペース区切りの整数の入力
            string[] input = Console.ReadLine().Split(' ');
            int a = int.Parse(input[0]);
            int b = int.Parse(input[1]);

            // それぞれの値
            int add = a + b;
            int sub = a - b;
            int mul = a * b;

            // 比較
            int max = 0;

            if (add >= sub && add >= mul)
            {
                max = add;
            } else if (sub >= add && sub >= mul)
            {
                max = sub;
            } else
            {
                max = mul;
            }

            // 出力
            Console.WriteLine(max);
        }

        static void Main(string[] args)
        {
            A_Add_Sub_Mul();
        }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define bit(k) (1LL<<(k))
#define SUM(v) accumulate(all(v), 0LL)

typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
struct fast_ios{ fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; }fast_ios_;

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; }

#define TOSTRING(x) string(#x)
template <typename T> istream &operator>>(istream &is, vector<T> &vec) { for (T &x : vec) is >> x; return is; }
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { os  << "["; for(auto _: v) os << _ << ", "; os << "]"; return os; };
template <typename T> ostream &operator<<(ostream &os, set<T> &st) { os << "("; for(auto _: st) { os << _ << ", "; } os << ")";return os;}
template <typename T, typename U> ostream &operator<<(ostream &os, const pair< T, U >& p){os << "{" <<p.first << ", " << p.second << "}";return os; }
template <typename T, typename U> ostream &operator<<(ostream &os, const map<T, U> &mp){ os << "["; for(auto _: mp){ os << _ << ", "; } os << "]" << endl; return os; }

#define DUMPOUT cerr
void dump_func(){ DUMPOUT << endl; }
template <class Head, class... Tail> void dump_func(Head &&head, Tail &&... tail) { DUMPOUT << head; if (sizeof...(Tail) > 0) { DUMPOUT << ", "; } dump_func(std::move(tail)...); }

#ifdef DEBUG
#define dbg(...) dump_func(__VA_ARGS__)
#define dump(...) DUMPOUT << string(#__VA_ARGS__) << ": "; dump_func(__VA_ARGS__)
#else
#define dbg(...)
#define dump(...)
#endif

const int INF = (ll)1e9;
const ll INFLL = (ll)1e18+1;
const ll MOD = 1000000007;
// const ll MOD = 998244353;
const long double PI = acos(-1.0);

/*
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const string dir = "DRUL";
*/


int main() {
    ll N, M;
    cin >> N >> M;
    auto check = [&](ll X) -> bool{
        ll s = N;
        ll c = M;
        // sがX個必要 -> cnt = max(0LL, X - s)個必要
        // cからcnt * 2個取る
        // cが2X個以上あるか
        ll cnt = max(0LL, X - s);
        c -= 2 * cnt;
        return 2 * X <= c;
    };
    ll ok = 0;
    ll ng = INFLL;
    while(ng - ok > 1){
        ll mid = (ok + ng) >> 1;
        if(check(mid))ok = mid;
        else ng = mid;
    }
    cout << ok << endl;
}


Measured memory_bytes: 3632
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main{
	public static void main(String args[]){
		try{
				//InputStreamReader??§??????????????????????????????????????????
				InputStreamReader isr =new InputStreamReader(System.in);
				//????????????????????????????????????????????°(????????????????????????????????¨??????????????????????????¢???????????????????£????)
				BufferedReader br =new BufferedReader(isr);

			while(true){
				//1??????????????????????????¨??????????????????
				String buf = br.readLine();
				//?¬¬????????°???????????????????????????????¬¬????????°????????????????????????????????§???????????????????????§???????????????
				StringTokenizer st = new StringTokenizer(buf," ");

				//1????????????????????¨??£???int??????????????????
				int m = Integer.parseInt(st.nextToken());
				int f = Integer.parseInt(st.nextToken());
				int r = Integer.parseInt(st.nextToken());
				int sum = (m + f);
				String result ="";


				//??¨????????????-1?????£????????????
				if(m == -1 && f == -1 && r == -1){
					break;
				//??????????¨??????????????¨????????????????????¬????????????´???????????? F
				}else if(m == -1 || f == -1){
					result += "F";
				//80 ??\???????????°????????? A
				}else if(sum >= 80){
					result += "A";
				//65 ??\??? 80 ??????????????°????????? B
				}else if(sum >= 65 && sum < 80){
					result += "B";
				//50 ??\??? 65 ??????????????°????????? C
				}else if(sum >= 50 && sum < 65){
					result += "C";
				//30 ??\??? 50 ??????????????°????????? D
				}else if(sum >= 30 && sum < 50){
					//???????????????????¨?????????°??? 50 ??\???????????°????????? C
					if(r >= 50){
						result += "C";
					}else{
						result += "D";
					}
				//30 ??????????????°????????? F
				}else if(sum < 30){
					result += "F";
				}
				System.out.println(result);
			}
		}catch(NumberFormatException e){
			System.out.print(e);
		} catch (IOException e) {
			System.out.print(e);
		}
	}
}

Measured memory_bytes: 24392
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#define lli long long int
#define uli unsigned long long int
#define inf 999999999999999999
#define rep(i,n,m) for(lli i=(lli)(n);i<(lli)(m);++i)
#define reep(i,n,m) for(int i=(int)(n);i<=(int)(m);++i)
#define per(i,m,n) for(lli i=(int)(m)-1;i>=(int)(n);--i)
#define st(n) sort(n.begin(), n.end())
#define rev(n) reverse(n.begin(),n.end())
#define ou(S) cout << S << endl
using namespace std;
int main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  if(max(a,c)-min(a,c)<=d||max(a,b)-min(a,b)<=d&&max(b,c)-min(b,c)<=d)ou("Yes");
  else ou("No");
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std;
 
signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
 
    string s;
    cin >> s;
    if(s.length() > 2) {
		int l = -1 , r = -1;
		for(int i = 0; i < s.length()-2; i++) {
			map<char , int> map;
			for(int j = 0; j < 3; j++) map[s[i+j]]++;
			int found = -1;
			for(auto p:map) {
				if(p.second >= 2) {l = i+1 , r = i+3 , found = 1;}
			}
			if(found == 1) break;
		}
		cout << l << " " << r << "\n";
	}
	else if(s[0] == s[1]) cout << "1 2" << "\n";
	else cout << "-1 -1" << "\n";
 
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int max_n = 1e6;
int t[5][5];
ll h,a,b,c,d,e;
int ans = 1;
bool memo[15][15] = {0};
int main(){
  ll m,n;
  cin >> n >> m;
  ll ans=0;
  if(n==1&&m==1)ans=1;
  else if(n==1 || m==1) ans = m*n-2;
  else ans = m*n - (2*(n+m)-4);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import Data.Vector.Unboxed((!),fromList)
import Data.List
import qualified Data.ByteString.Char8 as BS
import Data.Maybe
getIntList = map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine
binarySearch :: (Int -> Bool) -> Int -> Int -> Int
binarySearch pred ok ng
  | abs (ok-ng) <= 1 = ok
  | pred mid = binarySearch pred mid ng
  | otherwise = binarySearch pred ok mid
    where mid = (ok+ng) `div` 2

main = do
    n <- readLn :: IO Int
    l <- fromList . sort <$> getIntList
    let list = [max 0 (right-left+1) |
           i <- [0 .. n - 3],
           let a = l ! i,
           j <- [i + 1 .. n - 2],
           let b = l ! j,
           -- condition :: l!k < a+b,abs (a-b) < l!k , j < k
           let left = binarySearch (\k -> abs (a-b) < l ! k) (n-1) j,
           let right = binarySearch (\k -> l ! k < a+b) 0 n
           ]
    print $ sum list


Measured memory_bytes: 5444
//h17-3
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define LL_MIN -9223372036854775808
#define LL_MAX 9223372036854775807
#define segment_size 65536
#define ROOP() while (true)

int main(){
    int y1,m1,d1,y2,m2,d2;
    cin >> y1 >> m1 >> d1 >> y2 >> m2 >> d2;

    if(y1*10000+m1*100+d1 > y2*10000+m2*100+d2){
        swap(y1,y2);
        swap(m1,m2);
        swap(d1,d2);
    }

    int ans = y2 - y1;
    if(m1*100+d1 < m2*100+d2) ans++;
    cout << ans << endl;

    return 0;
}


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

int main()
{
	int n; cin >> n;
	int d[n] = {0}; for (int i = 0; i < n; i++) { cin >> d[i]; }
	
	int ans = 0;

	for (int i = 0; i <= n - 2; i++) {
		for (int j = i + 1; j <= n - 1; j++) {
			ans += d[i] * d[j];
		}	
	}
	
	cout << ans << endl;

	return 0;
}

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

int main() {
    int m, n, in, sum(0);
    vector <int> v;
    cin >> n >> m;
    while (n--) {
        cin >> in;
        v.push_back(in);
        sum += in;
    }
    float minQ = (float) sum / (float)(4 * m);
    int count(0);
    for (int i = 0; i < v.size(); i++) {
        if (v[i] < minQ) continue;
        else count++;
    }
    if (count >= m) cout << "Yes\n";
    else cout << "No\n";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

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; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }




int N;
int a, b;
int main() {
  while (cin >> N) {
	int Max = 0;
	int MaxVal = 0;
	for (int i = 0; i < N; ++i) {
	  cin >> a >> b;
	  if (chmax(Max, a)) MaxVal = b;
	}
	cout << Max + MaxVal << endl;
  }
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		char[] chars = s.nextLine().toCharArray();
		for (int i = 0; i < chars.length; ++i) {
			if (Character.isUpperCase(chars[i])) {
				chars[i] = Character.toLowerCase(chars[i]);
			} else {
				chars[i] = Character.toUpperCase(chars[i]);
			}
		}
		System.out.println(String.valueOf(chars));
	}
}

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

int main() {
    ll n;
    cin >> n;
    ll a[200010];

    rep(i, n) cin >> a[i];

    ll sum = 0;
    for (ll i=1; i<n; i++) {
        if (a[i-1] > a[i]) {
            ll p = a[i-1] - a[i];
            a[i] += p;
            sum += p;
        }
    }

    cout << sum << endl;

	return 0;
}


Measured memory_bytes: 5132
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>

using namespace std;

void solve(int s){
    int in;
    
    for(int i=0;i<9;i++){
        scanf("%d",&in);
        s-=in;
    }
    
    printf("%d\n",s);
    
    return;
}


int main(){
    int s;
    
    while(1){
        scanf("%d",&s);
        if(s==0) break;
        solve(s);
    }
    
    return 0;
}

Measured memory_bytes: 1188
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>

using namespace std;

int dx[] = {3,2,6,7,0,1,5,4};
int dy[] = {4,0,3,7,5,1,2,6};
int dz[] = {1,2,3,0,5,6,7,4};

vector<int> changeX(vector<int> vi){
	vector<int> res(8);
	for(int i=0;i<8;i++) res[i] = vi[dx[i]];
	return res;
}

vector<int> changeY(vector<int> vi){
	vector<int> res(8);
	for(int i=0;i<8;i++) res[i] = vi[dy[i]];
	return res;
}

vector<int> changeZ(vector<int> vi){
	vector<int> res(8);
	for(int i=0;i<8;i++) res[i] = vi[dz[i]];
	return res;
}

int main(){
	while(true){
		map< string, int > mp;
		int size = 0;
		vector<int> vs;
		for(int i=0;i<8;i++){
			string s;
			if(!(cin >> s)) return 0;
			if(!mp.count(s)) mp[s] = size++;
			vs.push_back(mp[s]);
		}
		sort(vs.begin(), vs.end());
		set< vector<int> > S;
		int ans = 0;
		do{
			if(S.find(vs)==S.end()){
				ans++;
				vector<int> vi = vs;
				for(int i=0;i<4;i++){
					for(int j=0;j<4;j++){
						for(int k=0;k<4;k++){
							S.insert(vi);
							vi=changeZ(vi);
						}
						vi = changeY(vi);
					}
					vi=changeX(vi);
				}
			}
		}while(next_permutation(vs.begin(),vs.end()));
		cout << ans << endl;
	}
}

Measured memory_bytes: 0
#include <iostream>

using namespace std;

int main() {

	int height[10];

	for (int i = 0; i < 10; i++) {
		cin >> height[i];
	}

	for (int i = 10 - 1; i >= 0; i--) {
		for (int j = 0; j < i; j++) {
			if (height[j] > height[j + 1]) {
				int dummy = height[j];
				height[j] = height[j + 1];
				height[j + 1] = dummy;
			}
		}
	}

	for (int i = 9; i >= 7; i--) {
		cout << height[i] << endl;
	}

	return 0;

}

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

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define MOD 1000000007
#define el endl
#define INF 1e8
typedef long long ll;
typedef long double ld;
// 'a' = 97 'z' = 122 => 'a' = 0 'z' = 25

bool compare_by_b(pair<string, int> a, pair<string, int> b) {
    if(a.second != b.second){
        return a.second > b.second;
    }else{
        return a.first > b.first;
    }
}

int main() {
    int n;
    cin >> n;
    vector<pair<string, int>> v;
    vector<string> s(n);
    rep(i, n) cin >> s[i];
    sort(s.begin(), s.end());
    int cnt = 1;
    rep(i, n-1){
        if(s[i] != s[i+1]){
            v.emplace_back(make_pair(s[i], cnt));
            cnt = 1;
        }else{
            cnt++;
        }
    }
    v.emplace_back(make_pair(s.back(), cnt));
    
    sort(v.begin(), v.end(), compare_by_b);
    int max = v[0].second;
    int i = 0;
    vector<string> ans;
    while(v[i].second == max){
        ans.emplace_back(v[i].first);
        i++;
    }
    sort(ans.begin(), ans.end());
    rep(i, ans.size()){
        cout << ans[i] << endl;
    }
}




Measured memory_bytes: 21360
#include <iostream>
#include<string>
using namespace std;
int main(void){
    string s;
    for(int i=0;i<3;i++){
        cin>>s;
        s[0]=s[0]+'A'-'a';
        cout<<s[0];
    }
    cout<<endl;
    return 0;
    // Your code here!
    
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
using namespace std;
int main() {
	int n;
	cin >> n;
	int a[n], b[n];
	for (int i = 0;i < n;i++) cin >> a[i], b[i] = a[i];
	sort(b, b + n);
	int ml = b[n / 2 - 1], mr = b[n / 2];
	for (int i = 0;i < n;i++) {
		if (a[i] <= ml) cout << mr << " ";
		else cout << ml << " ";
	}
	cout << endl;
}


Measured memory_bytes: 3712
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define SORT(x) sort((x).begin(),(x).end())
#define MEMSET(x,y) memset((x),(y),sizeof(x))
#define P pair<int,int>

typedef long long ll;
using namespace std;

int main() {
  int n;
  cin >> n;
  int ans = 0;
  vector<int> nu(101,0);
  rep(i,n+1) {
    string s = to_string(i);
    char t = s.at(s.size()-1);
    char b = s.at(0);
    if(b == '0') continue;
    int koko = (t - '0') * 10 + (b - '0');
    nu.at(koko)++;
  }
  rep(i,n+1) {
    string s = to_string(i);
    char b = s.at(s.size()-1);
    char t = s.at(0);
    if(t == '0') continue;
    ans += nu.at((t - '0') * 10 + (b - '0'));
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
int n,m,i,j,x;
std::vector<int>v[999];
int main(){
	scanf("%d",&n);
	m=(1+sqrt(1+8*n))/2;if(m*(m-1)/2!=n)return puts("No"),0;
	for(i=1;i<m;++i)for(j=i+1;j<=m;++j)++x,v[i].push_back(x),v[j].push_back(x);
	printf("Yes\n%d\n",m);
	for(i=1;i<=m;++i)for(int x:v[printf("%d ",m-1),i])printf("%d%c",x,x==v[i].back()?'\n':' ');
	return 0;
}

Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);i++)
//#define int long long  
int main(){
	int n,m;
	cin >> n >> m;
	cout << (n-1)*(m-1) << endl;
	return 0;
}

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

void main(void)
{
  char input[101] = {'\0'};
  int i = 0, len = 0;
  int flag = 0;		// 0 means yes
  
  scanf("%s", &input);
  len = strlen(input);
  
  for(i=0; i<len; i+=2)
  {
    if (input[i] == 'L')
    {
      printf("No");
      return;
    }
  }
  for(i=1; i<len; i+=2)
  {
    if (input[i] == 'R')
    {
      printf("No");
      return;
    }
  }
  
  printf("Yes");
}


Measured memory_bytes: 128
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 200000


struct Info{
	bool operator<(const struct Info &arg) const{
		return cost < arg.cost;
	}
	ll from,to,cost;
};

Info info[NUM];
int N;
ll boss[NUM],height[NUM],member_num[NUM];

int get_boss(int id){
	if(boss[id] == id)return id;
	else{
		return boss[id] = get_boss(boss[id]);
	}
}

int is_same(int x,int y){
	return get_boss(x) == get_boss(y);
}

void unite(int x,int y){
	int boss_x = get_boss(x);
	int boss_y = get_boss(y);

	if(boss_x == boss_y)return;

	if(height[x] > height[y]){

		boss[boss_y] = boss_x;
		member_num[boss_x] += member_num[boss_y];

	}else if(height[x] < height[y]){

		boss[boss_x] = boss_y;
		member_num[boss_y] += member_num[boss_x];

	}else{ //height[x] == height[y]

		boss[boss_y] = boss_x;
		member_num[boss_x] += member_num[boss_y];
		height[x]++;
	}
}

int main(){

	scanf("%d",&N);

	for(int i = 0; i < N-1; i++){
		scanf("%lld %lld %lld",&info[i].from,&info[i].to,&info[i].cost);
	}

	sort(info,info+N-1);

	for(int i = 0; i < N; i++){
		boss[i] = i;
		height[i] = 0;
		member_num[i] = 1;
	}

	ll ans = 0;

	for(int i = 0; i < N-1; i++){
		ans += member_num[get_boss(info[i].from)]*member_num[get_boss(info[i].to)]*info[i].cost;
		unite(info[i].from,info[i].to);
	}

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

	return 0;
}

Measured memory_bytes: 12632
#include <bits/stdc++.h>
#define LL long long
#define ULL unsigned long long
#define UI unsigned int
#define mem(i, j) memset(i, j, sizeof(i))
#define rep(i, j, k) for(int i = j; i <= k; i++)
#define dep(i, j, k) for(int i = k; i >= j; i--)
#define pb push_back
#define make make_pair
#define INF 0x3f3f3f3f
#define inf LLONG_MAX
#define PI acos(-1)
#define fir first
#define sec second
#define lb(x) ((x) & (-(x)))
#define dbg(x) cout<<#x<<" = "<<x<<endl;
using namespace std;

const int N = 1e6 + 5;

string a, b;

void solve() {

    cin >> a;

    cin >> b;

    int ans = b.size();

    rep(i, 0, a.size() - b.size()) {

        int need = 0;

        rep(j, i, i + b.size() - 1) {

            if(a[j] != b[j - i]) need++;

        }

        ans = min(ans, need);

    }


    cout << ans << endl;

}


int main() {

//    int _; scanf("%d", &_);
//    while(_--) solve();

    solve();

    return 0;
}


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

public class Main {
   /*maximum number of input*/
   public static final int MAX = 999999;
   
   public static void main(String[] args) {
      //create an array of prime numbers
      ArrayList<Integer> prime = createPrimeArr();
      Scanner sc = new Scanner(System.in);
      
      while(sc.hasNext()) {
         int input = Integer.parseInt(sc.nextLine());
         System.out.println(getIndex(prime, input) + 1);
      }
      
   }
   
   //creates an ArrayList holding all the prime numbers from 2 to MAX
   public static ArrayList<Integer> createPrimeArr() {
      ArrayList<Integer> prime = new ArrayList<>();
      //add 2 to the list
      prime.add(2);
      
      //the int "n" is the number to be checked if prime or not
      for(int n = 3; n <= MAX; n += 2) {
         int size = prime.size();
         //the int "i" is the index of divider in the array of prime
         for(int i = 0; i < size; i ++) {
            if(Math.pow(prime.get(i),2) > n) {
               prime.add(n);
               break;
            } else if(n % prime.get(i) == 0) {
               break;
            }
         }
      }
      return prime;
   }
   
   
   //wrapper method for getIndex
   public static int getIndex(ArrayList<Integer> list, int target) {
      return getIndex(0,list.size() - 1, list, target);
   }
   
   //use binary search to find the index of the closest element to the target in a list
   public static int getIndex(int start, int end, ArrayList<Integer> list, int target) {
      int middle = (start + end) / 2;
      if(start > end) {
         //if the target is not found, "end" indicates the target
         //for the binary search in this case
         return end;
      }else if(list.get(middle) == target) {
         return middle;
      } else if (target < list.get(middle)) {
         return getIndex(start, middle - 1, list, target);
      } else {// if(target > list.get(middle))
         return getIndex(middle + 1, end, list, target);
      }
   }
   
}


Measured memory_bytes: 29400
use proconio::input;
fn main() {
    input!{
        x: i64,
        k: i64,
        d: i64,
    };
    let mut ax = x.abs();
    let mut count = x.abs() / d;
    if k <= count {
        count = k;
    }
    ax = ax - count * d;
    if count < k && (k - count) % 2 == 1 {
        ax = (ax - d).abs();
    }
    println!("{}", ax);
}

Measured memory_bytes: 2164
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
mod = 10 ** 9 + 7

class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i

def compress(A):
    """ 座標圧縮 """
    zipped, unzipped = {}, {}
    for i, a in enumerate(sorted(set(A))):
        zipped[a] = i
        unzipped[i] = a
    return zipped, unzipped

N = INT()
a = LIST()
x_to_i = {x: i for i, x in enumerate(sorted(set(a)))}
a = [x_to_i[x]+1 for x in a]
ans = 0
bit = Bit(N)

for j in range(N):
    ans += j-bit.sum(a[j])
    bit.add(a[j], 1)
print(ans)



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

int main( int argc, char *argv[] )
{
int i;
int N;
int A;
int B;

	ios::sync_with_stdio( false );
	cin.tie( 0 );

	cin >> N;
	cin >> A;
	cin >> B;
	i = N * A;
	if( i <= B )
		cout << i << endl;
	else
		cout << B << endl;

	return 0;
}




Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
	string s;
	cin >> s;
	
	int idx_a, idx_z;
	for(int i=0; i<s.length(); i++){
		if(s.at(i) == 'A'){
			idx_a = i;
			break;
		}
	}
	for(int j=s.length()-1; j>=0; j--){
		if(s.at(j) == 'Z'){
			idx_z = j;
			break;
		}
	}

	cout << idx_z - idx_a + 1 << endl;

	return 0;
}

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

int main() {
    int N,L;
    int sum =0;
    cin >> N>>L;
    vector<int>data(N);
    for(int i=1; i<=N;i++){
        int aji = L + i -1;
        sum += aji;
    }
    if (L>0) cout <<sum-L<<endl;
    else if(L<=0 && L +N-1>0) cout << sum<<endl;
    else cout << sum -L-N+1 <<endl;
}

Measured memory_bytes: 256
N = int(input())
P = list(map(float, input().split()))

dp = [[0] * (N+1) for _ in range(N+1)]
dp[0][1] = P[0]
dp[0][0] = 1-P[0]
for i in range(1,N):
    for j in range(i+2):
        dp[i][j] = dp[i-1][j] * (1-P[i]) + dp[i-1][j-1] * P[i]
print(sum(dp[N-1][N//2+1:]))

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

if n in [1,2,3,4,5,6,7,8,9,10,12,14,15,16,18,20,21,24,25,27,28,30,32,35,36,40,42,45,48,49,54,56,63,64,72,81]:
  print('Yes')
else:
  print('No')


Measured memory_bytes: 3064
n = int(input())
S = []
for i in range(n):
  S.append(int(input()))
S.sort()
if sum(S) % 10 != 0:
  print(sum(S))
else:
  for i in range(n):
    total = sum(S) - S[i]
    if total % 10 == 0:
      continue
    else:
      print(total)
      break
  else:
    print(0)

Measured memory_bytes: 38384
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const int INF = 1000000005;
const int MAX = 10005;

vector<pair<int, int>> to[MAX];
bool seen[MAX];
int d[MAX], n;

void dijkstra(int u) {
  d[u] = 0;
  priority_queue<pair<int, int>> pq;
  pq.push(make_pair(0, 0));
  pair<int, int> p;
  while (!pq.empty()) {
    p = pq.top();
    pq.pop();
    seen[p.second] = true;

    for (pair<int, int> e: to[p.second]) {
      if (seen[e.second]) continue;
      if (d[p.second] + e.first < d[e.second]) {
        d[e.second] = d[p.second] + e.first;
        pq.push(make_pair(-d[e.second], e.second));
      }
    }
  }
}

int main() {
  cin >> n;
  int u, k, v, c;
  rep(i, n) {
    cin >> u >> k;
    rep(j, k) {
      cin >> v >> c;
      to[u].push_back(make_pair(c, v));
    }
  }

  rep(i, n) {
    seen[i] = false;
    d[i] = INF;
  }

  dijkstra(0);

  rep(i, n) cout << i << " " << d[i] << endl;

  
  return 0;
}


Measured memory_bytes: 8000
#pragma GCC optimize("Ofast","inline","-ffast-math")
#pragma GCC target("avx,sse2,sse3,sse4,mmx")
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
//#define int long long
using namespace __gnu_pbds;
using namespace std;

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

signed main()
{
	ios::sync_with_stdio(false);
	int a,b,c,d,e;
	cin>>a>>b>>c>>d>>e;
	if(a==0) cout<<1;
	else if(b==0) cout<<2;
	else if(c==0) cout<<3;
	else if(d==0) cout<<4;
	else cout<<5;
	cout<<endl;	
	return 0;
}

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

bool isPrime(int n)
{
    int i;
    if(n <= 1)    return false;
    //if(n == 2)  return true;
    for(i = 2; i * i <= n; i += 1)
        if(n % i == 0)
            return false;
    return true;
}
int main()
{
    int n, cnt = 0, inp;
    cin >> n;
    int arr[n];

    for(int i = 0; i < n; i++)
    {
        cin >> inp;
        if(isPrime(inp))
            cnt++;
    }
    cout << cnt << endl;
}



Measured memory_bytes: 3092
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main(){
    ll n;
    cin >> n;
    ll happy[110000][3];
    for(int i=1;i<=n;i++){
        cin >> happy[i][0] >> happy[i][1] >> happy[i][2];
    }

    ll dp[11000][3];
    for(int i=1;i<=n;i++){
        for(int place=0;place<3;place++){
            for(int placeY=0;placeY<3;placeY++){
                if(place == placeY) continue;
                dp[i][place] = max(dp[i][place],
                                   dp[i-1][placeY]+happy[i][place]);
            }
        }
    }
    ll ans = 0;
    for(int place=0;place<3;place++){
        ans = max(dp[n][place], ans);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 6244
#include <stdio.h>
#include <string.h>
 
int main() {
  char S[2000000];
  char T[2000000];
  scanf("%s %s", &S, &T);
  int count = 0;
  for(int i = 0; i < strlen(S); i++){
    if(S[i] != T[i]){
      count++;
    }
  }
  printf("%d", count);
}

Measured memory_bytes: 2124
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef map<int, int> mi;
typedef set<int> si;
#define VV(T) vector<vector< T > >
#define dump(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl

#define rep(i, n) REP(i, 0, n)                              // 0, 1, ..., n-1
#define REP(i, x, n) for(int i = x; i < n; i++)             // x, x + 1, ..., n-1
#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(v) (v).begin() , (v).end()
#define RALL(v) (v).rbegin(), (v).rend()

#define pb push_back
#define pu push
#define mp make_pair
#define fi first
#define sc second

#define COUT(x) cout << (x) << endl
#define VECCIN(x) for(auto&youso_: (x) )cin>>youso_
#define VECCOUT(x) for(auto&youso_: (x) )cout<<youso_<<" ";cout<<endl

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(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int a, b, c; cin >> a >> b >> c;
    if(a > b) swap(a, b);
    if(a <= c && c <= b){
        COUT("Yes");
    } else {
        COUT("No");
    }
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
	int a,b,c,x,y;
	y = 0;
	scanf("%d %d %d",&a,&b,&c);
	for( x = a ; x <= b ; x++ ){
		
		
		
		if(c%x == 0){
			y++;
		}if(a>10000||b>10000||c>10000||a>b){
			break;
		}
	}
	
		
	printf("%d\n",y);
	return 0;
}

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

#define MAX_N 999999

int main(){

    int i, j, n;

    // ?´???°?????°??????.
    char check_list[MAX_N];
    for (i=2; i<= MAX_N; ++i){
        if (check_list[i] == '1') continue;

        check_list[i] = '2'; // ?´???°

        for (j=2; j<MAX_N; ++j){
            if (i*j > MAX_N)break;
            check_list[i*j] = '1';
        }
    }

    int num = 0;
    int save[MAX_N] = {};
    for (i=1; i<= MAX_N; ++i){
        if (check_list[i] == '2') ++num;
        save[i] = num;
    }

    while ( (fscanf(stdin, "%d", &n)) != EOF){
        if (n <= 0){
            printf("0\n");
            continue;
        }
        printf("%d\n", save[n]);
    }

    return 0;
}

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

int main()
{
    cin.tie(0)->sync_with_stdio(0);
    cin.exceptions(cin.failbit);
    int n, h;
    cin >> n >> h;
    vector<int> a(n);
    vector<int> b(n);
    for (int i = 0; i < n; i++)
    {
        cin >> a[i] >> b[i];
    }

    sort(a.begin(), a.end());
    int maxa = a[n - 1];
    sort(b.begin(), b.end());
    int current = n - 1, ans = 0;
    while (h > 0)
    {
        if (current < 0)
        {
            ans += h / maxa + (h % maxa != 0);
            h = 0;
            break;
        }
        if (b[current] >= maxa)
        {
            h -= b[current];
            current -= 1;
        }
        else
        {
            h -= maxa;
        }
        ans++;
    }
    cout << ans << endl;
}


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

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO ?????????????????????????????????????????????
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		int seconds = 0;
		for(int i = 0; i < 4; i++){
			seconds += Integer.parseInt(br.readLine());
		}
		
		System.out.println(seconds/60);
		System.out.println(seconds%60);
	}

}

Measured memory_bytes: 24008
package main
 
import (
	"bufio"
	"fmt"
	"log"
	"os"
	"strconv"
)
 
func run(){
	n := next()
	
	if("Sunny" == n){
		Println("Cloudy")
	}else if("Cloudy" == n) {
		Println("Rainy")
	}else {
		Println("Sunny")
	}
	
}
 
 
// --- template ---
// Thanks https://gist.github.com/halllllll/853ab587fd82ee3ffe6f7fb7fb499695
 
var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)
 
// Caution: You will get unexpected result if a single token is larger than this size.
const BufferSize = 64 * 1024 * 1024
 
func Print(a ...interface{}) (n int, err error) {
	return fmt.Fprint(out, a...)
}

func readIntArray(n int) ([]int) {
	v := make([]int, 0)
	for i := 0; i < n; i++ {
		v = append(v, nextInt())
	}
	return v
}
 
func Printf(format string, a ...interface{}) (n int, err error) {
	return fmt.Fprintf(out, format, a...)
}
 
func Println(a ...interface{}) (n int, err error) {
	return fmt.Fprintln(out, a...)
}
 
func next() string {
	sc.Scan()
	return sc.Text()
}
 
func nextInt() int {
	a, err := strconv.Atoi(next())
	if err != nil {
		log.Fatal(err)
	}
	return a
}
 
func nextFloat() float64 {
	a, err := strconv.ParseFloat(next(), 64)
	if err != nil {
		log.Fatal(err)
	}
	return a
}
 
func main() {
	sc.Buffer(make([]byte, 0, BufferSize), BufferSize)
	sc.Split(bufio.ScanWords)
	run()
	out.Flush()
}

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

#define faster ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define fill(a,v)  memset(a, v, sizeof (a))
#define FOR(i,a,n) for (int i=a;i<n;i++)
#define FORD(i,a,n) for (int i=n-1;i>=a;i--)
#define mp make_pair
#define pb push_back
#define ff first
#define ss second

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

const int MOD = 1e9 + 7;
const int INF = 1e9 + 5;
const ll LINF = LLONG_MAX;
ll powmod(ll a,ll b) {ll res=1;a%=MOD; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%MOD;a=a*a%MOD;}return res;}

ll knapsack(vector<ll> &w, vector<ll> &v, ll N, ll W){
	vector<vector<ll> > dp(N+1, vector<ll>(W+1));

	for(int i = 0; i <= N; ++i)	dp[i][0] = 0;
	for(int i = 0; i <= W; ++i)	dp[0][i] = 0;

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

	return dp[N][W];
}

int main()
{
	faster;

	ll N, W;

	cin >> N >> W;
	vector<ll> w(N), v(N);
	for(int i = 0; i < N; ++i)	cin >> w[i] >> v[i];
	
	cout << knapsack(w, v, N, W);

	return 0;
}

// READ
// THINK
// CODE
// DEBUG
// AC


Measured memory_bytes: 80256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
LL a[1000010];
int main()
{
    LL n, k;
    scanf("%lld%lld", &n, &k);
    for (int i = 1; i <= n; i++)
    {
        scanf("%lld", &a[i]);
    }
    sort(a + 1, a + 1 + n);
    k = k - 1;
    LL l = -1e18, r = 1e18;
    LL ans = -1;
    while (l <= r)
    {
        LL m = (l + r) / 2;
        LL num = 0;
        for (int i = 1; i <= n; i++)
        {
            long double mm = m;
            if (a[i] > 0)
            {
                LL x = m / a[i] - 1;
                if (m % a[i])
                {
                    x = ceil(mm / a[i]) - 1;
                }
                int st = upper_bound(a + 1 + i, a + 1 + n, x) - a - 1;
                num += st - i;
            }
            else if (a[i] < 0)
            {
                LL x = m / a[i];
                if (m % a[i])
                    x = floor(mm * 1.0 / a[i]);
                int st = upper_bound(a + 1 + i, a + 1 + n, x) - a;
                num += n - st + 1;
            }
            else
            {
                if (m > 0)
                    num += n - i;
            }
        }
        // cout << m << " " << num << endl;
        if (num <= k)
        {
            ans = m, l = m + 1;
        }
        else
            r = m - 1;
    }

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

Measured memory_bytes: 1792
# -*- coding: utf-8 -*-
n,a,b = map(int,input().split())

ans = 0
for i in range(1, n + 1):
    tmp = i
    tmp2 = list(str(tmp))
    sum = 0
    for j in range(len(tmp2)):
        sum += int(tmp2[j])
    if a <= sum <= b:
        ans += i
print(ans)


Measured memory_bytes: 2940
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()



int main() {
  int n, k;
  cin >> n >> k;
  ll ans = k;
  rep(i, n-1) {
    ans *= k-1;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"os"
)

func main() {
	var n int

	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	fmt.Fscan(fp, &n)

	aList := make([]int, n)
	dp := make([]int64, n*n)

	for i := 0; i < n; i++ {
		fmt.Fscan(fp, &aList[i])
	}

	fmt.Println(chokudai(0, n-1, aList, dp, n))

}

func chokudai(l int, r int, aList []int, dp []int64, n int) int64 {
	if l >= r {
		dp[l*n+r] = int64(aList[l])
		return dp[l*n+r]
	}
	if dp[l*n+r] != 0 {
		return dp[l*n+r]
	}
	getL := int64(aList[l]) - chokudai(l+1, r, aList, dp, n)
	getR := int64(aList[r]) - chokudai(l, r-1, aList, dp, n)
	if getL > getR {
		dp[l*n+r] = getL
	} else {
		dp[l*n+r] = getR
	}
	return dp[l*n+r]
}

Measured memory_bytes: 73216
#include<stdio.h>
int main(){
  int n,m,i,j;
  double p=0,a;
  scanf("%d %d",&n,&m);
  for(i=0;i<n;i++){
    a=1.0/n;
    for(j=i+1;j<m;j*=2)a/=2.0;
    p+=a;
  }
  printf("%.10lf\n",p);
  return 0;
}


Measured memory_bytes: 128
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


class Matrix():
    def __init__(self, A):
        self.A = A
        self.row = len(A)
        self.col = len(A[0])

    def __iter__(self):
        return self.A.__iter__()

    def __getitem__(self, i):
        return self.A.__getitem__(i)

    def __add__(self, B):
        aa = self.A
        bb = B.A
        return Matrix([[aa[i][j] + bb[i][j] for j in range(self.col)] for i in range(self.row)])

    def __sub__(self, B):
        aa = self.A
        bb = B.A
        return Matrix([[aa[i][j] - bb[i][j] for j in range(self.col)] for i in range(self.row)])

    def __mul__(self, B):
        bb = [[B.A[j][i] for j in range(B.row)] for i in range(B.col)]
        return Matrix([[sum([ak * bk for ak,bk in zip(ai,bj)]) % mod for bj in bb] for ai in self.A])

    def __truediv__(self, x):
        pass

    def pow(self, n):
        A = self
        r = Matrix([[0 if j != i else 1 for j in range(self.row)] for i in range(self.row)])
        while n > 0:
            if n % 2 == 1:
                r = r * A
            A = A * A
            n //= 2
        return r

    def lu(self):
        # squarenのみ
        size = self.row
        T = copy.deepcopy(self.A)
        L = [[0]*size for _ in range(size)]
        U = [[0]*size for _ in range(size)]
        for i in range(size):
            for j in range(i,size):
                L[j][i] = T[j][i]
            for j in range(i,size):
                U[i][j] = T[i][j] / T[i][i]
            for j in range(i+1,size):
                for k in range(i+1,size):
                    T[j][k] -= L[j][i] * U[i][k]

        return Matrix(L),Matrix(U)

    def __str__(self):
        return self.A.__str__()


def main():
    n,k = LI()
    a = [LI() for _ in range(n)]
    A = Matrix(a)
    P = A.pow(k)

    return sum(map(sum,P.A)) % mod


print(main())


Measured memory_bytes: 5900
#include<stdio.h>
void trace(int A[],int N){
  int i;
 
  for(i=0;i<N;i++){
    if(i>0)printf(" ");
    printf("%d",A[i]);
  }
  printf("\n");
}

void swap(int *x,int *y)
{
  int a;
  a=*x;
  *x=*y;
  *y=a;
}

int main(){
  int A[100];
  int i,j,n,N,minj;
  scanf("%d",&n);
  for(i=0;i<n;i++)scanf("%d",&A[i]);
 
  for(i=0,N=0;i<=n-1;i++){
    minj=i;
    for(j=i;j<=n-1;j++){
      if(A[j]<A[minj]) minj=j;
      
    }
      swap(&A[i],&A[minj]);
      if(i!=minj) N++;
  }
  trace(A,n);
  printf("%d\n",N);
  return 0;
}

Measured memory_bytes: 604