akhauriyash/Code-Regression huggingface dataset:
#define _CRT_SECURE_NO_WARNINGS
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// #define int ll
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
#define all(c) begin(c), end(c)
#define range(i,a,b) for(ll i=a; i<ll(b); i++)
#define rep(i,b) range(i,0,b)
#define rangei(i,a,b) for(ll a=a;i<=ll(b);i++)
#define repi(i,b) rangei(i,1,b)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
template<class T> ostream & operator << (ostream &os, vector<T> const &);
template<int n, class...T>
typename enable_if<(n>=sizeof...(T))>::type
_ot(ostream &, tuple<T...> const &){}
template<int n, class...T>
typename enable_if<(n< sizeof...(T))>::type
_ot(ostream &os, tuple<T...> const &t){
    os << (n==0?"":" ") << get<n>(t); _ot<n+1>(os, t);
}
template<class...T>
ostream & operator << (ostream &os, tuple<T...> const &t){
    _ot<0>(os, t); return os;
}
template<class T, class U>
ostream & operator<<(ostream &os, pair<T,U> const &p){
    return os << "(" << p.first << ", " << p.second << ") ";
}
template<class T>
ostream & operator<<(ostream &os, vector<T> const &v){
    rep(i,v.size()) os << v[i] << (i+1==(int)v.size()?"":" "); return os;
}
#ifdef DEBUG
#define dump(...) (cerr << #__VA_ARGS__ << " = " << mt(__VA_ARGS__) \
                   << " [" << __LINE__ << "]" << endl)
#else
#define dump(...)
#endif
void fastios(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#define endl '\n'
}
template<class T>
size_t uniq(vector<T> &v){
    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()), v.end());
    return v.size();
}
template<class T>
size_t uniq(T *l, size_t n){
    sort(l,l+n);
    return unique(l,l+n) - l;
}
#define mems(arr,val) memset(arr,val,sizeof(arr));
int const mod = 1000000007;
int const inf = numeric_limits<int>::max()/8;

template <class T>
struct FenwickTree {
    int n;
    vector<T> x;
    FenwickTree(int n_ = 0) : n(n_), x(n_+1){
        fill(x.begin(), x.end(), 0);
    }
    T sum(int r){
        T S = 0;
        for (; r >= 0; r = (r&(r+1))-1) S += x[r];
        return S;
    }
    T sum(int l, int r){
        if(l >= r) return 0;
        else return l==0 ? sum(r-1) : sum(r-1) - sum(l-1);
    }
    void add(int k, T a){
        for (; k < n; k |= k+1) x[k] += a;
    }
    void set(int k, T a){
        int x = sum(k, k+1);
        add(k, a-x);
    }
    vi to_a(int l = -1, int r = -1){
        if(l == -1) l = 0;
        if(r == -1) r = n;
        vi res(r-l);
        range(i,l,r) res[i-l] = sum(i,i+1);
        return res;
    }
};

int main(){
    int n,q;
    cin >> n >> q;
    FenwickTree<ll> t(n);
    rep(i,q){
        int c,x,y;
        cin >> c >> x >> y;
        x--;
        if(c == 0) t.add(x,y);
        else cout << t.sum(x,y) << endl;
    }
}

Measured memory_bytes: 1788
#include<iostream>
#include<math.h>
#include<algorithm>
#include<stdint.h>
#include<vector>
#include<deque>
#include<stack>
#include<string>
#include<cstring>
#include<time.h>
#include<array>
#include<iomanip>
#include<list>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<random>
#include<bitset>
#include <queue>
#include <map>


using namespace std;
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using ldouble = long double;


//BDD,ZDD,kdtree, bdtree,bicalc, bolonoy, doloney,chinesemod,segmenttree,daikusutora, saidairyuu, 2bugurahu, heirokenshutu, topologicalsort, kyourenketuseibun


#define PRI(s) cout << s << endl
#define PRIY PRI("Yes")
#define PRIN PRI("No")


int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (a + b + c <= 21) PRI("win");
	else PRI("bust");
	return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O0")
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define Rep(i,a,n) for (ll i = (a); i < (n); ++i)
const ll mod = 1e9+7;
const ll INF = 1e18;
#define All(a) (a).begin(),(a).end()
#define Pi acos(-1)
using Graph = vector<vector<ll>>;
using V = vector<ll>;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << setprecision(15) << fixed;
  chrono::system_clock::time_point start,end;
  start = chrono::system_clock::now();

  string s;
  ll n;
  cin >> n >> s;
  ll ans = 0;
  rep(i,n-2) {
    string t = s.substr(i,3);
    if (t == "ABC") ++ans;
  }
  cout << ans << '\n';

  end = chrono::system_clock::now();
  auto elapsed = chrono::duration_cast< chrono::milliseconds >(end - start).count();
  cerr << elapsed << "ms" << '\n';
}

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

int main() {
    int n;
    cin >> n;
    int d[n];
    for (int i = 0; i < n; i++) cin >> d[i];
    vector<bool> v(100005);
    for (int i = 0; i < n; i++) {
        int num = 0;
        for (int j = 0; j < 4; j++) {
            if (i + j >= n) continue;
            num = num * 10 + d[i + j];
            v[num] = true;
        }
    }
    for (int i = 0; i < 100005; i++) {
        if (v[i] == false) {
            cout << i << endl;
            return 0;
        }
    }
    return 0;
}


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

int main(){
    int a[4];
    for(int i=0;i<4;i++){
        char c; cin>>c;
        a[i]=c-'0';
    }
    for(int i=0;i<(1<<3);i++){
        int ans=a[0];
        for(int j=1;j<=3;j++){
            if(i&(1<<(3-j)))ans+=a[j];
            else ans-=a[j];
        }
        if(ans==7){
            cout<<a[0];
            for(int j=1;j<=3;j++){
                if(i&(1<<(3-j)))cout<<"+";
                else cout<<"-";
                cout<<a[j];
            }
            cout<<"=7"<<endl;
            return 0;
        }
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <cmath>   
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 

using namespace std;

int main()
{
	int A,B;
	cin >> A >> B;
	if (A < 6) { cout << 0 << endl; }
	else if (A > 12) { cout << B << endl; }
	else { cout << B / 2 << endl; }

	return 0;
}


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


int main(void){
 int N,p;
 int sum=0;
 vector<int> A;
 cin>>N;
 
 for(int i=0; i<N; i++){
  cin>>p;
  A.push_back(p);
 }
 sort(A.begin(),A.end());

 for(int i=0; i<N; i++){
  if(i==N-1)sum+=(A[i]/2);
  else sum+=A[i];
 }
 std::cout<<sum<<std::endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ft first
#define sc second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
static const ll INF=1e18;
static const ll MAX=1e5+7;
static const ll MOD=1e9+7;
ll max(ll a, ll b) {return a>b?a:b;}
ll min(ll a, ll b) {return a<b?a:b;}

class Edge {
public:
  ll t, w;
  Edge(ll t, ll w): t(t), w(w) {}
};

ll N;
vector<Edge> g[MAX];
ll clr[MAX];

void dfs(ll u, ll c) {
  clr[u]=c;
  
  ll i, v;
  for(i=0; i<g[u].size(); i++) {
    Edge e=g[u][i];
    
    if(clr[e.t]!=-1) continue;
    
    if(e.w%2==0) dfs(e.t, c);
    else dfs(e.t, 1-c);
  }
  
  
}


int main(void) {
  ll i;
  cin >> N;
  for(i=0; i<N-1; i++) {
    ll u, v, w;
    cin >> u >> v >> w;
    u--; v--;
    g[u].pb(Edge(v, w));
    g[v].pb(Edge(u, w));
  }
  
  for(i=0; i<N; i++) clr[i]=-1;
  
  dfs(0, 0);
  
  for(i=0; i<N; i++) pt(clr[i]);
  
}











Measured memory_bytes: 10240
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for(int i = (a); i >= (b); i--)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define RREP(i, n) for(int i = n; i >= n; i--)

#define ABS(a) ((a < 0) ? ((-1)*(a)) : (a))

#define endl "\n"
#define pb push_back
#define rtn return
#define elif else if

#define MOD 1000000007
 
const int dx[]={1,0,-1,0}, dy[]={0,-1,0,1};

typedef long long ll;
typedef unsigned long long ull;

template <typename T>
inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <typename T>
inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template <typename T>
inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template <typename T>
inline T nHr(T a,T b){return nCr(a+b-1,b);}
template <typename T>
inline T POW(T a,T b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}

signed main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	string s;
	ll k;
	cin >> s >> k;

	int i = 0;
	while(1){
		if(s[i] == '1') k--;
		else{
			cout << s[i] << endl;
			break;
		}
		if(k == 0){
			cout << 1 << endl;
			break;
		}
		i++;
	}
	rtn 0;
}

Measured memory_bytes: 256
def f(S):
    k,l = 0,0
    num = ""
    A = []
    for i in range(len(S)):
        s = S[i]
        if s=="[":
            k+=1
            if k==3 and l==0:
                l = i-1
        elif s=="]":
            k-=1
            if l==0 and k==1:
                num = int(num)
                num = num//2 if num%2==0 else num//2+1
                A.append(num)
                num = ""
            elif l!=0 and k==1:
                A.append(f(S[l:i+1]))
                num = ""
                l = 0
        else:
            num += s
    A.sort()
    return sum(A[:len(A)//2+1])
for i in [0]*int(input()):
    S = input()
    print(f(S))


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

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

    static class B {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int h = Integer.parseInt(in.next());
            int w = Integer.parseInt(in.next());

            for (int i = 0; i < h + 2; i++) {
                for (int j = 0; j < w + 2; j++) {
                    if (i == 0 || i == h + 1) {
                        out.print("#");
                    } else if (j == 0 || j == w + 1) {
                        out.print("#");
                    } else {
                        String tmp = in.next();
                        out.print(tmp);
                        j += tmp.length() - 1;
                        continue;
                    }
                }
                out.println();
            }

        }

    }
}



Measured memory_bytes: 21844
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    if len(x) == 0:
        return []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

def pow_k(x, n):
    ans = 1
    while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
    return ans

"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""


n = onem()

a = l()
a.sort()
cou = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        for k in range(j+1,n):
            
            if a[i] + a[j] > a[k] and a[k] + a[j] > a[i] and a[i] + a[k] > a[j] and a[i] != a[j] and a[j] != a[k]:
                cou += 1
print(cou)



Measured memory_bytes: 68400
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#define ll long long int
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
using namespace std;

int mx8[] = {0,0,1,-1,-1,1,-1,1};
int my8[] = {-1,1,0,0,-1,-1,1,1};
int mx4[] = {1,-1,0,0};
int my4[] = {0,0,-1,1};
const int MOD = 1000000007;

ll y[10000005];

int main() {
    int d; cin >> d;
    vector<int> c(26);
    rep(i,26) cin >> c[i];
    int s[d][26];
    rep(i,d) rep(j,26) cin >> s[i][j];
    int las[26];
    rep(i,26) las[i] = 0;
    int man = 0;
    rep(i,d){
        int t; cin >> t;
        t--;
        man += s[i][t];
        int human = 0;
        las[t] = i+1;
        rep(j,26){
            human += c[j] * (i+1-las[j]);
        }
        man -= human;
        cout << man << endl;
    }

}




Measured memory_bytes: 3632
import java.util.*;
public class Main{

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int w = sc.nextInt();
        char[][] c =new char[h][w];



        for(int i =0;i<h;i++){
            String moji = sc.next();
            for(int j = 0;j<w;j++){
                c[i][j] = moji.charAt(j);
            }
        }

        for(int i = 0;i<h;i++){
            for(int j =0;j<w;j++){
                System.out.print(c[i][j]);
            }
            System.out.println();
            for(int j =0;j<w;j++){
                System.out.print(c[i][j]);
            }
            System.out.println();
        }
            

    }
}






Measured memory_bytes: 27536
import scala.io.StdIn

object Main {

  def main(args: Array[String]) {

    val Array(n, m) = StdIn.readLine().split(' ').map(_.toInt)
    val kss: Seq[Seq[Int]] =
      Seq() +: (1 to m).map(_ => StdIn.readLine().split(' ').toSeq.map(_.toInt))
    val ps: Seq[Int] = 0 +: StdIn.readLine().split(' ').toSeq.map(_.toInt)

    println(solve(n, m, kss, ps))

  }

  def solve(n: Int, m: Int, kss: Seq[Seq[Int]], ps: Seq[Int]): Int = {
    searchAndCount(n, Seq(), m, kss, ps)
  }

  def searchAndCount(n: Int, onOff: Seq[Int], m: Int, kss: Seq[Seq[Int]], ps: Seq[Int]): Int  = {
    if (n == 0) {
      if (checkBulbs(m, 0 +: onOff, kss, ps)) 1 else 0
    } else {
      val caseOn = searchAndCount(n - 1, 1 +: onOff, m, kss, ps)
      val caseOff = searchAndCount(n - 1, 0 +: onOff, m, kss, ps)
      caseOn + caseOff
    }
  }

  def checkBulbs(m: Int, onOff: Seq[Int], kss: Seq[Seq[Int]], ps: Seq[Int]): Boolean = {
    (1 to m).foldLeft(true)((sum, i) => sum && checkBulb(i, onOff, kss, ps))
  }

  def checkBulb(i: Int, onOff: Seq[Int], kss: Seq[Seq[Int]], ps: Seq[Int]) = {
    val sumOn = kss(i).tail.foldLeft(0)((sum, si) => sum + onOff(si))
    sumOn % 2 == ps(i)
  }

}


Measured memory_bytes: 28776
#include<iostream>
using namespace std;
const int N = 1e7 + 5;
int a[N];
int main(){
    int n;
    cin >> n;
    
    long long ans = 0;
    for(int i = 1 ; i <= n ; i++){
        for(int j = 1 ; j*i <= n ; j++ ){
            a[i*j]++;
        }
        ans += ( (long long)i * a[i] ); 
    }

    cout << ans;
}

Measured memory_bytes: 42648
#include<bits/stdc++.h>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;

/**
 * vector<int>ar(3);
 * for(auto&e:ar){
 *     scanf("%d",&e);
 * }
 * sort(ar.begin(),ar.end())
 * int sum=accumulate(ar.begin(),ar.end(),0);
 ***/

int main(){
    double pai=3.141592653589;
    char s[100], p[100];
    string scp="", s2="",chk="";
    scanf("%s",&s);
    scanf("%s",&p);
    scp=s;
    chk=p;
    s2=scp+scp;
    size_t pos = s2.find(p);
    if(pos != string::npos){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
    return 0;
}

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

//--------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define LL long long
#define INF INT_MAX/3

//--------------------------------------------
const double EPS = 1e-14;
const double PI  = acos(-1.0);

//--------------------------------------------

int main(){
  int n,m;

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

  printf("%d\n",(n - 1) * (m - 1));
}


Measured memory_bytes: 256
from itertools import groupby
def calc():
  s = 0
  for i in range(h):
    gr = groupby(g[i])
    j = 0
    for key,it in gr:
      l = len(list(it))
      if key!=-1:
        if l >= K:
          g[i][j:j+l] = [-1]*l
          # for k in range(l):
          #   g[i][j+k] = -1
          s += key*l
      j += l
 
  return s

def flatten():
  for j in range(w):
    lst = []
    for i in range(h-1, -1, -1):
      if g[i][j] > 0:
        lst.append(g[i][j])

    lst += [-1] * (h - len(lst))

    for i in range(h-1, -1, -1):
      g[i][j] = lst[h-i-1]

h,w,K = map(int,input().split())
mat = [ [int(e) for e in list(input())] for _ in range(h) ]

res = 0
for i in range(h):
  for j in range(w):
    score = 0
    g = [ [ mat[n][m] for m in range(w) ] for n in range(h) ]
    g[i][j] = -1
    time = 0
    flatten()
    while True:
      s = calc()
      if s==0: break
      score += (2**time)*s
      flatten()
      time += 1
    res = max(res, score)

print(res)


Measured memory_bytes: 75916
import math
import itertools

def l2(z1, z2):
  return math.sqrt(pow(z1[0] - z2[0], 2) + pow(z1[1] - z2[1], 2))

n = int(input())
l = [list(map(int, input().split(' '))) for _ in range(n)]
seq_list = itertools.permutations(l, n)

dist = 0
for seq in seq_list:
  z_fr = []
  z_to = []
  
  for z in seq:
    z_fr = z_to
    z_to = z
    if len(z_fr)==0:
      continue
    dist += l2(z_fr, z_to)

print(dist/math.factorial(n))

Measured memory_bytes: 9028
def check(n):
    num=int(n**0.5)
    l=[]
    for i in range(1,num+1):
        if n%i==0:
            l.append(i)
            l.append(n//i)
    return set(l)

n=int(input())
a=list(map(int,input().split()))

box=[0]*n
cnt=0
ans=[0]*n
for i in range(n):
    if a[-(i+1)]==box[-(i+1)]:continue
    cnt+=1
    ans[-(i+1)]=1
    l=check(n-i)
    for j in l:
        box[j-1]=(box[j-1]+1)%2

print(cnt)
if cnt==0:exit()
for i in range(n):
    if ans[i]:
        print(i+1,end=' ')

Measured memory_bytes: 65256
#include "bits/stdc++.h"
using namespace std;

#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
const int inf = 1000000001;
const ll INF = 1e18 * 4;
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<<fixed<<p<<endl;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };

static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;
static const int N = 2005;

//tt時刻、d[v]vを最初に発見した時刻、f[v]vを調べ終わった時刻
int n, tt = 0;
vii M(N,vi());
vi color(N, WHITE), d(N), f(N), nt(N, 0);

int next(int u) {
	int v;
	for (v = nt[u]; v < n; v++) {
		nt[u] = v;
		if (M[u][v]) {
			return v;
		}
	}
	return -1;
}


void dfs(int r) {
	stack<int> s;
	s.push(r);
	color[r] = GRAY;
	d[r] = 0;

	while (!s.empty()) {
		int u = s.top();
		for (; nt[u] < M[u].size(); nt[u]++) {
			if (color[M[u][nt[u]]] == WHITE) {
				int v = M[u][nt[u]];
				color[v] = GRAY;
				d[v] = d[u] + 1;
				s.push(v);
				break;
			}
		}
		if (nt[u] == M[u].size()) {
			s.pop();
			color[u] = BLACK;
		}
	}
}


int main() {
	int n, k;
	scanf("%d%d", &n, &k);
	vector<pii> edge(n - 1);
	for (int i = 0; i < n - 1; i++) {
		int a, b;
		scanf("%d%d", &a, &b);
		a--; b--;
		M[a].push_back(b);
		M[b].push_back(a);
		edge[i] = pii(a, b);
	}
	int ans = inf;
	if (!(k % 2)) {
		for (int i = 0; i < n; i++) {
			fill(color.begin(), color.end(), WHITE);
			fill(d.begin(), d.end(), -1);
			fill(nt.begin(), nt.end(), 0);
			dfs(i);
			int cnt = 0;
			bool flag = false;
			for (int j = 0; j < n; j++) {
				if (d[j] > k / 2) {
					cnt++;
				}
			}
			ans = min(ans, cnt);

		}
	}
	else {
		for (int i = 0; i < n - 1; i++) {
			fill(color.begin(), color.end(), WHITE);
			fill(d.begin(), d.end(), -1);
			fill(nt.begin(), nt.end(), 0);
			color[edge[i].second] = GRAY;
			dfs(edge[i].first);
			dfs(edge[i].second);
			int cnt = 0;
			bool flag = false;
			for (int j = 0; j < n; j++) {
				if (d[j] > k / 2) {
					cnt++;
				}
			}
			ans = min(ans, cnt);
		}
	}
	cout << ans << endl;
	return 0;

}

Measured memory_bytes: 384
n, m = map(int, input().split())

memo = [0] * (n+1)
for i in range(m):
    l, r = map(int, input().split())
    l-= 1
    r -= 1
    memo[l] += 1
    memo[r+1] -= 1
for i in range(n):
    memo[i+1] += memo[i]

count = 0
for i in range(n):
    if memo[i] == m:
        count += 1

print(count)


Measured memory_bytes: 45912
# ２次元配列バージョン
# かつ、内包表記バージョン
n = int(input())
suits = ["S", "H", "C", "D"]
cards = [[s, n] for s in suits for n in range(1, 14)]
for i in range(n):
    target = list(map(
        lambda a: int(a) if a.isnumeric() else a, input().split()
    ))
    if target in cards:
        cards.remove(target)
[print("{} {}".format(c[0], c[1])) for c in cards]



Measured memory_bytes: 5600
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string.h>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <time.h>
#define int long long
#define US unsigned
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define nin(ary, n) for (int i = 0; i < (n); i++) cin >> ary[i]
#define nnin(ary, h, w) for (int i = 0; i < (h); ++i) for (int j = 0; j < (w); ++j) cin >> ary[i][j]
#define OPT(conditions, a, b) cout << ((conditions) ? #a : #b) << endl
using namespace std;
const double PI = acos(-1.0);
const int MOD = 1e9 + 9;

int max_n(int ary[], int length) {
	int max = ary[0];
	for (int i = 1; i < length; i++)
		if (max < ary[i]) max = ary[i];
	return max;
}

int max_o(int ary[], int length) {
	int max;
	max = max_n(ary, length);
	for (int i = 0; i < length; i++) {
		if (ary[i] == max) return i;
	}
	return -1;
}

int min_n(int ary[], int length) {
	int min = ary[0];
	for (int i = 1; i < length; i++)
		if (min > ary[i]) min = ary[i];
	return min;
}

int min_o(int ary[], int length) {
	int min;
	min = min_n(ary, length);
	for (int i = 0; i < length; i++) {
		if (ary[i] == min) return i;
	}
	return -1;
}

int gcm(int a, int b) {
	int result = a;
	int k = 0;
	int n = b;
	do {
		k = result % n;
		result = n;
		n = k;
	} while (k != 0);
	return result;
}

int gcm_n(int ary[], int length) {
	int g = ary[0];
	for (int i = 0; i < length; i++)
		g = gcm(g, ary[i]);
	return g;
}

int lcm(int a, int b) {
	int g, n;
	g = gcm(a, b);
	n = gcm(a, g);
	a = a / n;
	b = b / (g / n);
	return a*b;
}

int lcm_n(int ary[], int length) {
	int l = ary[0];
	for (int i = 0; i < length; i++)
		l = lcm(l, ary[i]);
	return l;
}

signed main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	cout << max((int)0, (min(b, d) - max(a, c))) << endl;
	return 0;
}

Measured memory_bytes: 256
import itertools
n = int(input())
cnt = [0, 0, 0, 0, 0]
perm = [0, 1, 2, 3, 4]
for i in range(n):
    name = input()
    if name[0] == 'M':
        cnt[0] += 1
    elif name[0] == 'A':
        cnt[1] += 1
    elif name[0] == 'R':
        cnt[2] += 1
    elif name[0] == 'C':
        cnt[3] += 1
    elif name[0] == 'H':
        cnt[4] += 1
ans = 0
for i, j, k in itertools.combinations(perm, 3):
    ans += cnt[i] * cnt[j] * cnt[k]
print(ans)


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


/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/

int main(void){
  int d,t,s;
  scanf("%d%d%d",&d,&t,&s);

  /*
  
  分数で表した解答は切り捨ての関係で落ちる

  今回の問題は大丈夫だけど，小数は誤差が怖いから基本的に使わないほうがいい

  */

  if(d<=t*s){
    printf("Yes\n");
  }
  else{
    printf("No\n");
  }

  return 0;
}

Measured memory_bytes: 1644
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int x = sc.nextInt();
    
    if (n < 10)
      x = x + 100 * (10 - n);
    
    System.out.println(x);
  }
}

Measured memory_bytes: 21844
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>

using namespace std;

const int nmax = 1e9 + 7;
typedef long long ll;

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

  int sum = N * (N + 1) / 2;

  int min_group = 0;
  for (int i = 2; i < N; i++){
    if (sum % i == 0){
      min_group = i;
      break;
    }
  }
  
  vector < vector <int> > Group(min_group);
  vector <int> Group_sum(min_group);

  int sum_limit = sum / min_group;

  for (int i = N; i >= 1; i--){
    for (int j = 0; j < min_group; j++){
      if (Group_sum[j] + i <= sum_limit){
        Group_sum[j] += i;
        Group[j].push_back(i);
        break;
      }
    }
  }

  int ans = 0;
  for (int i = 0; i < min_group - 1; i++){
    for (int j = i + 1; j < min_group; j++){
      ans += Group[i].size() * Group[j].size();
    }
  }
  cout << ans << endl;
  
  for (int i = 0; i < min_group - 1; i++){
    for (int j = i + 1; j < min_group; j++){
      for (int k = 0; k < Group[i].size(); k++){
        for (int l = 0; l < Group[j].size(); l++){
          cout << Group[i][k] << " " << Group[j][l] << endl;
        }
      }
    }
  }
  
  return 0;
}


Measured memory_bytes: 256
n, q = map(int, input().split())
s = input()
t = [0]*(n + 1)
for i in range(n):
    t[i+1] = t[i] + (1 if s[i:i+2] == 'AC' else 0)
for i in range(q):
    l, r = map(int, input().split())
    print(t[r-1] - t[l-1])

Measured memory_bytes: 7748
#include <stdio.h>

int main()
{
    int c[20],v[20],n,sum = 0;

    scanf("%d",&n);
    for (int i = 0; i < n; i++)
    {
        scanf("%d",&v[i]);
    }
    for (int i = 0; i < n; i++)
    {
        scanf("%d",&c[i]);
        if (v[i] > c[i]){
            sum += (v[i] - c[i]);
        }
    }

    printf("%d",sum);
    

}

Measured memory_bytes: 128
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;

class Node {
    Integer p, l, r;

    public Node(){}
}

public class Main {

    int n;
    Node[] nodes;
    List<Integer> preorderList = new ArrayList<>();
    List<Integer> inorderList = new ArrayList<>();
    List<Integer> postorderList = new ArrayList<>();

    void run() {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();

        nodes = new Node[n];

        for (int i = 0; i < n; i++) {
            nodes[i] = new Node();
        }

        for (int i = 0; i < n; i++) {
            int id = sc.nextInt();
            int l = sc.nextInt();
            int r = sc.nextInt();

            if (l != -1) {
                nodes[id].l = l;
                nodes[l].p = id;
            }

            if (r != -1) {
                nodes[id].r = r;
                nodes[r].p = id;
            }
        }

        System.out.println("Preorder");
        int rootId = getRoot();
        preorder(rootId);
        System.out.print(" ");
        System.out.println(preorderList.stream().map(String::valueOf).collect(Collectors.joining(" ")));

        System.out.println("Inorder");
        int leftId = getLeft(rootId);
        inorder(leftId);
        System.out.print(" ");
        System.out.println(inorderList.stream().map(String::valueOf).collect(Collectors.joining(" ")));

        System.out.println("Postorder");
        postorder(leftId);
        System.out.print(" ");
        System.out.println(postorderList.stream().map(String::valueOf).collect(Collectors.joining(" ")));

    }

    int getRoot() {
        int rootId = 0;
        for (int i = 0; i < n; i++) {
            if (nodes[i].p == null) {
                rootId = i;
            }
        }
        return rootId;
    }

    int getLeft(int id) {
        if (nodes[id].l == null) return id;
        else return getLeft(nodes[id].l);
    }

    void preorder(int id) {
        preorderList.add(id);
        if (nodes[id].l != null) preorder(nodes[id].l);
        if (nodes[id].r != null) preorder(nodes[id].r);
    }

    void inorder(int id) {
        if (nodes[id].l != null && !inorderList.contains(nodes[id].l)) inorder(nodes[id].l);
        if (!inorderList.contains(id)) inorderList.add(id);
        if (nodes[id].r != null && !inorderList.contains(nodes[id].r)) inorder(nodes[id].r);
        if (nodes[id].p != null) inorder(nodes[id].p);
    }

    void postorder(int id) {
        if (nodes[id].l != null && !postorderList.contains(nodes[id].l)) postorder(nodes[id].l);
        if (nodes[id].r != null && !postorderList.contains(nodes[id].r)) postorder(nodes[id].r);
        if (!postorderList.contains(id)) postorderList.add(id);
        if (nodes[id].p != null) postorder(nodes[id].p);
    }

    public static void main(String[] args) {
        new Main().run();
    }

}


Measured memory_bytes: 32240
#include<bits/stdc++.h>
using namespace std;
#define r(i,n) for(int i=0;i<n;i++)

// semi-open   Range minimum query

struct RMQ{
  int n,q,data[(1<<19)];
  RMQ(){
    n=(1<<18);
    int tmp=1;
    while(tmp<n)tmp*=2;
    n=tmp;
    for(int i=0;i<n*2-1;i++)data[i]=INT_MAX;
  }
  void update(int k,int x){
    k+=n-1;
    data[k]=x;
    while(k>0){
      k=(k-1)/2;
      data[k]=min(data[k*2+1],data[k*2+2]);
    }
  }
  int find(int a,int b,int k=0,int l=0,int r=(1<<18)){
    if(r<=a || b<=l)return INT_MAX;
    if(a<=l && r<=b)return data[k];
    int v1=find(a,b,k*2+1,l,(l+r)/2);
    int v2=find(a,b,k*2+2,(l+r)/2,r);
    return min(v1,v2);
  }
};


int main(){
  RMQ a;
  int c,x,y,n,q;
  cin>>n>>q;
  for(int i=0;i<q;i++){
    scanf("%d%d%d",&c,&x,&y);
    if(c)cout<<a.find(x,y+1)<<endl;
    else a.update(x,y);
  }
}


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

const double PI=acos(-1.0);

int main() {
    int n;
    cin >> n;
    ll power = 1;

    for(int i = 1; i <= n; i++) {
        power *= i;
        power %= 1000000007;
    }

    cout << power << endl;

    return 0;
}

Measured memory_bytes: 384
/*input
1a 132 243
1c 324 183
1f 93 199
2b 372 163
2c 229 293
2e 391 206
3a 118 168
3b 263 293
3d 281 102
*/
macro_rules! input_vec {
    () => {
        input!().split_whitespace().map(|x| x.to_string()).collect()
    };
    ($delimiter:expr) => {
        input!()
            .split($delimiter)
            .map(|x| x.parse().unwrap())
            .collect()
    };
}

macro_rules! input {
    () => {{
        let mut return_ = String::new();
        std::io::stdin().read_line(&mut return_).ok();
        return_.pop();
        return_
    }};
}

fn main() {
    let mut v: Vec<String>;
    let (mut a, mut b): (i32, i32);
    for _ in 0..9 {
        v = input_vec!();
        a = v[1].parse().expect("");
        b = v[2].parse().expect("");
        println!("{} {} {}", v[0], a + b, a * 200 + b * 300);
    }
}



Measured memory_bytes: 5036
#include <iostream>
#include<string>
using namespace std;
int main(){
    string S;
    for(int i=0;i<4;i++)cin>>S[i];
    if(S[0]==S[1]||S[1]==S[2]||S[2]==S[3])cout<<"Bad"<<endl;
    else cout<<"Good"<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
// Begin Header {{{
#define all(x) (x).begin(), (x).end()
#define lli long long int
#define rep(i,n) for(lli i=0; i<n; i++)
#define loop(i, j, n) for(lli i=j; i<n; i++)
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) < (b) ? (a) : (b))
constexpr int INF  = 0x3f3f3f3f;
const long long mod=1e9+7;
//Function
lli combi(lli n, lli r)
{
	if(r==0 || r==n) return 1;
	else return combi(n-1,r) + combi(n-1,r-1);
}
lli sigma1(lli n){return n*(n+1)/2;}
lli sigma2(lli s, lli n){return sigma1(n) - sigma1(s -1);}
using namespace std;
// }}} End Header

int main()
{
	ios::sync_with_stdio(false); cin.tie(nullptr);
	lli a, b, c;
	cin >> a >> b >> c;
	lli t = b/a;
	lli ans;
	if(t >= c) ans = c;
	else ans = t;
	cout << ans << endl;
	return 0;
}

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

int main(){
    int N, Y;
    cin >> N >> Y;
    int man1 = -1, sen5 = -1, sen1 = -1;

    for(int a=0;a<=N;++a){
        for(int b=0;b + a <=N;++b){
            int c = N - a - b;
            if(Y == a*10000 + b*5000 + c*1000) {
                man1 = a;
                sen5 = b;
                sen1 = c;
            }
        }
    } 
    cout << man1 << " " << sen5 << " " << sen1 << " " << endl ;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<climits>
#include<set>

#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--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
using namespace std;
typedef pair<int, int> pii;
typedef long long int ll;
typedef pair<ll,ll> pll;
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
#define MOD 1000000007
#define ARRAY_MAX 10005

const int INF = 1e9+7;

int mp[2005][2005];

int main(){

    int n,k;
    cin >> n >> k;

    int black = 0,sum = 0;
    //sum=白マスの数-黒マスの数
    for(int i = 0;i < n;i++){
        int x,y;
        char c;
        cin >> x >> y >> c;
        x %= 2*k;
        y %= 2*k;
        if(c == 'W'){
            mp[x+1][y+1]++;
            sum++;
        }else{
            mp[x+1][y+1]--;
            sum--;
            black++;
        }

    }

    //二次元いもす（横方向）
    for(int i = 0;i <= 2*k;i++){
        for(int j = 1;j <= 2*k;j++){
            mp[i][j] += mp[i][j-1];
        }
    }
    
    //二次元いもす(縦方向)
    for(int i = 1;i <= 2*k;i++){
        for(int j = 0;j <= 2*k;j++){
            mp[i][j] += mp[i-1][j];
        }
    }

    int ans = -INF;
    for(int i = 0;i <= k;i++){
        for(int j = 0;j <= k;j++){
            //白マスの数(条件を満たすのマスの数)
            int a = mp[i][j];
            int b = mp[i+k][j+k] - mp[i+k][j] - mp[i][j+k] + mp[i][j];
            int c = mp[2*k][j] - mp[i+k][j];
            int d = mp[i][2*k] - mp[i][j+k];
            int e = mp[2*k][2*k] - mp[2*k][j+k] - mp[i+k][2*k] + mp[i+k][j+k];
            int tmp = a + b + c + d + e + black;
            ans = max(ans,max(tmp,n - tmp));
        }
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 15872
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define m 1000000007
ll large(ll n){
	ll ans=INT_MIN;
	for(ll i=1;i*i<=n;i++){
		if(n%i==0){
			ans=max(ans,i);
		}
	}
	return ans;
}
int main()
{
   ll n;
cin>>n;
ll temp=large(n);
ll temp2=n/temp;
cout<<(temp-1)+(temp2-1)<<endl;

	return 0;
} 

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

int main() {
  int W, H, x, y, r;
  cin >> W >> H >> x >> y >> r;
  if (x - r >= 0 && y - r >= 0 && x + r <= W && y + r <= H) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}



Measured memory_bytes: 3112
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> void printvec(const vector<T>& v) {
  for (auto x : v) { cout << x << " "; }
  cout << endl;
}
template<class T> void printtree(const vector< vector<T> >& tree) {
  for (long long i = 0; i < tree.size(); ++i) {
    cout << i + 1 << ": "; printvec(tree[i]);
  }
}
template<class T, class U> void printmap(const map<T, U>& mp) {
  for (auto x : mp) { cout << x.first << "=>" << x.second << endl; }
}

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 rep(i, n) for(ll i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()
#define fr first
#define sc second
#define mp make_pair
#define pb push_back

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;

const ll INF = 1e10;
const ll MOD = 1000000007;  // 1e9 + 7

struct D {
  vector<double> l; // left-most values
  vector<double> r; // right-most values

  D() : l(3, INF), r(3, -INF) {}

  void add(double x, ll dir) {
    ++dir; // [-1,1] => [0,2]
    chmin(l[dir], x);
    chmax(r[dir], x);
  }

  // NOTE: Use double for t because i*t should be double.
  double get(double t) {
    double nl = INF;
    double nr = -INF;
    rep(i, 3) {
      chmin(nl, l[i]+i*t);
      chmax(nr, r[i]+i*t);
    }
    return nr-nl;
  }

  vector<double> events() {
    vector<double> ts;
    rep(i,3) rep(j, i) {
      {
        double t = (l[j]-l[i])/(i-j);
        if (t > 0) { ts.push_back(t); }
      }
      {
        double t = (r[j]-r[i])/(i-j);
        if (t > 0) { ts.push_back(t); }
      }
    }
    return ts;
  }
};

int main(int argc, char** argv) {
  cin.tie(NULL);
  cout.tie(NULL);
  ios_base::sync_with_stdio(false);
  cout << setprecision(10) << fixed;

  ll n;
  cin >> n;
  D xd, yd;
  rep(i, n) {
    ll x, y;
    char d;
    cin >> x >> y >> d;
    if (d == 'L') { xd.add(x, -1); yd.add(y, 0); }
    if (d == 'R') { xd.add(x, 1);  yd.add(y, 0); }
    if (d == 'U') { xd.add(x, 0);  yd.add(y, 1); }
    if (d == 'D') { xd.add(x, 0);  yd.add(y, -1); }
  }

  vector<double> ts; // changing events
  ts.push_back(0);
  ts.push_back(INF);
  {
    auto nts = xd.events();
    // cout << "xd.events:"; printvec(nts);
    ts.insert(ts.end(), all(nts));
  }
  {
    auto nts = yd.events();
    // cout << "yd.events:"; printvec(nts);
    ts.insert(ts.end(), all(nts));
  }
  sort(all(ts));
  double ans = 1e18;
  for (double t : ts) {
    double now = xd.get(t) * yd.get(t);
    ans = min(ans, now);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll  unsigned long long
#define ld  long double
#define endl '\n'
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const ll MOD = 998244353;
const double PI = 3.141592653589793238463;
const int MAXN = 1000030;

int main()
{
    FAST

    int n;
    cin>>n;
    string h;
    cin>>h;
    int i=0,j=n-1;
    ll cnt=0,cnt1=0;
    while(i<=j)
    {
        while(i<n && h[i]!='W')
            i++;
        while(j>=0 && h[j]!='R')
            j--;
        if(i==n || j==-1 || i>=j)
            break;
        swap(h[i],h[j]);
        i++;
        j--;
        cnt++;
    }

   // cout<<h<<endl;
    cout<<cnt<<endl;
    return 0;
}


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

int dp[1040][100005];

int main()
{
    int n;
    cin >> n;
    int v[300000], w[300000];
    for(int i = 1; i <= n; i++) scanf("%d %d", &v[i], &w[i]);
    for(int i = 1; i <= 10; i++){
        for(int j = (1 << (i - 1)); j < min(n + 1, (1 << i)); j++){
            for(int k = 0; k < (1 << i); k++){
                int m = j;
                int s = 0, t = 0;
                for(int l = 0; l < i; l++){
                    if((k >> l) & 1){
                        s += v[m];
                        t += w[m];
                    }
                    m /= 2;
                }
                if(t <= 100000) dp[j][t] = max(dp[j][t], s);
            }
            for(int t = 1; t <= 100000; t++) dp[j][t] = max(dp[j][t], dp[j][t - 1]);
        }
    }
    int q;
    cin >> q;
    while(q--){
        int u, l;
        cin >> u >> l;
        if(u < 256){
            printf("%d\n", dp[u][l]);
            continue;
        }
        int ans = 0;
        for(int b = 0; b < 256; b++){
            int m = u;
            int s = 0, t = 0;
            for(int i = 0; i < 8; i++){
                if((b >> i) & 1){
                    s += v[m];
                    t += w[m];
                }
                m /= 2;
            }
            if(t <= l) ans = max(ans, dp[m][l - t] + s);
        }
        printf("%d\n", ans);
    }
}


Measured memory_bytes: 405508
import math

N,M = map(int,input().split())

a = int(M/N)
q = int(math.sqrt(M))

m = 0
for i in range(1,q+1):
    if M % i == 0:
        if i <= a:
            m = max(m,i)
        b = int(M / i)
        if b <= a:
            m = max(m,b)

print(m)



Measured memory_bytes: 3060
#include<iostream>
#include<iomanip>
using namespace std;
typedef pair<int,int> Pt;
typedef pair<int,Pt> P;
#define fr first
#define sc second
#define INF (1 << 26)
#define FOR(i,b,n) for(int i = (b) ; i < (n) ; ++i)
#define rep(i,n) FOR(i,0,n)
int main(){
  double dp[101000],ans[101000];
  dp[1] = 1.0;
  FOR(i,1,100001){
    double ogmm = dp[i] , nkmr = 1.0;
    rep(j,/*about*/10){
      dp[i + j + 1] += ogmm * ( 1.0 - nkmr );
      ans[i + j] += ogmm * nkmr;
      ogmm *= nkmr;
      nkmr /= 2;
    }
  }
  FOR(i,1,100001) ans[i] += ans[i-1];
  int n;
  while(cin >> n && n)
    cout << fixed << setprecision(3) <<  ans[n] << endl;
}

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

using namespace std;

int main()
{
    #ifdef LOCAL_EXEC
    #else
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #endif // LOCAL_EXEC
    int k,i,j;
    string s,r;
    cin>>k>>s;
    if(s.size()<=k)
        cout<<s;
    else{
        r=s.substr(0,k);
        r+="...";
        cout<<r;
    }
    return 0;
}


Measured memory_bytes: 3676
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <queue>

using namespace std;

const int N=1000050;

char S[N],T[N];
queue<int> q;
int n,ans;

void calc()
{
	for (int i=n-1,p=n-1;i>=0;--i)
	{
		for (;i>0&&T[i-1]==T[i];--i);
		for (p=min(p,i);p>=0&&S[p]!=T[i];--p);
		if (p==-1)
		{
			ans=-1;
			return;
		}
		for (;!q.empty()&&q.front()-(int)q.size()>=i;q.pop());
		q.push(p);
		if (p!=i) ans=max(ans,(int)q.size());
	}
	++ans;
}

int main()
{
	//freopen("game.in","r",stdin),freopen("game.out","w",stdout);
	scanf("%d%s%s",&n,S,T);
	bool judge=1;
	for (int i=0;i<n&&judge;++i) judge&=S[i]==T[i];
	if (!judge) calc();
	printf("%d\n",ans);
	//fclose(stdin),fclose(stdout);
	return 0;
}

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

int main(){
  string s;
  cin>>s;
  int i;
  
    if(s== "SUN")
      i=7;
    if(s== "MON")
      i=6;
    if(s== "TUE")
      i=5;
    if(s== "WED")
      i=4;
    if(s== "THU")
      i=3;
    if(s== "FRI")
      i=2;
    if(s=="SAT")
      i=1;
      
  cout<<i<<endl;
}

Measured memory_bytes: 256
<?php
define('MOD', pow(10, 9) + 7);

fscanf(STDIN, "%d %d", $N, $K);
$A = array_map('intval', explode(' ', trim(fgets(STDIN))));
// 内部転倒
$inv_i = 0;
for ($i = 0; $i < $N; $i++) {
    for ($j = $i + 1; $j < $N; $j++) {
        if ($A[$i] > $A[$j]) {
            $inv_i++;
        }
    }
}
$inv_e = 0;
for ($i = 0; $i < $N; $i++) {
    for ($j = 0; $j < $N; $j++) {
        if ($A[$i] > $A[$j]) {
            $inv_e++;
        }
    }
}
$total = (1 + $K) * $K / 2;
$total %= MOD;
$cnt_i = $K;
$cnt_e = $total - $cnt_i;
if ($cnt_e < 0) {
    $cnt_e += MOD;
}
$ans = $cnt_i * $inv_i + $cnt_e * $inv_e;
printf("%d", $ans % MOD);


Measured memory_bytes: 4856
class Solver
  def prepare
    @d = gets.to_i
    @cs = gets.split(" ").map(&:to_i)
    @mans = []  # mans[date][contest]
    @ts = []

    @last = [0] * 26

    @d.times do
      @mans << gets.split(" ").map(&:to_i)
    end

    @d.times do
      @ts << gets.to_i
    end
  end

  # ----------- #

  def score(contest_id, date)
    @mans[date][contest_id]
  end

  def decrease_per_contest(contest_id, date)
    @cs[contest_id] * (date - @last[contest_id])
  end

  def decrease_all(date)
    (0..25).map do |contest_id|
      decrease_per_contest(contest_id, date)
    end.sum
  end

  def solve
    res = 0

    @ts.each.with_index do |t, d|  # d = date
      t -= 1
      # puts "Contest #{t} ga jisshi"
      res += score(t, d)
      # puts "score(#{t}, #{d}) = #{score(t, d)}"
      @last[t] = d+1
      # p @last
      res -= decrease_all(d+1)
      # puts "dec: #{decrease_all(d+1)}"

      puts res
    end
  end
end

solver = Solver.new
solver.prepare
solver.solve


Measured memory_bytes: 14192
#include <vector>
#include <cmath>
#include <iostream>
#include <algorithm>

typedef char                SINT8;
typedef unsigned char       UINT8;
typedef short               SINT16;
typedef unsigned short      UINT16;
typedef int                 SINT32;
typedef unsigned int        UINT32;
typedef long long           SINT64;
typedef unsigned long long  UINT64;
typedef double              DOUBLE;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)

using namespace std;

int main() {

	SINT32 N = 0;
	cin >> N;
	SINT32 ANS = 1000000001;


	vector<SINT32> DATA(12);
	
	DATA[0] = 1;
	DATA[1] = 6;
	DATA[2] = 9;
	DATA[3] = 36;
	DATA[4] = 81;
	DATA[5] = 216;
	DATA[6] = 729;
	DATA[7] = 1296;
	DATA[8] = 6561;
	DATA[9] = 7776;
	DATA[10] = 46656;
	DATA[11] = 59049;
	
	for (SINT32 D1 = 0; D1 < 6; D1++) {
	for (SINT32 D2 = 0; D2 < 6; D2++) {
	for (SINT32 D3 = 0; D3 < 8; D3++) {
	for (SINT32 D4 = 0; D4 < 6; D4++) {
	for (SINT32 D5 = 0; D5 < 8; D5++) {
	for (SINT32 D6 = 0; D6 < 6; D6++) {
	for (SINT32 D7 = 0; D7 < 8; D7++) {
	for (SINT32 D8 = 0; D8 < 6; D8++) {
	for (SINT32 D9 = 0; D9 < 8; D9++) {
	for (SINT32 D10 = 0; D10 < 6; D10++) {
	for (SINT32 D11 = 0; D11 < 3; D11++) {
	for (SINT32 D12 = 0; D12 < 2; D12++) {
		SINT32 BUF = D1 * DATA[0] +D2 * DATA[1] + D3 * DATA[2]			
					+D4 * DATA[3] +D5 * DATA[4] + D6 * DATA[5]
					+D7 * DATA[6] +D8 * DATA[7] + D9 * DATA[8]
					+D10 * DATA[9] +D11 * DATA[10]+ D12 * DATA[11];

		if (BUF == N) {
			BUF = D1+D2+D3+D4+D5+D6+D7+D8+D9+D10+D11+D12;

			ANS = MIN(ANS,BUF);
		}		
					

	}}}}}}}}}}}}



	

	cout << ANS << endl;
	return 0;
}

//	sort(DATA.begin(),DATA.end());
//	sort(DATA.begin(),DATA.end(),std::greater<SINT32>());
//	__gcd(ANS,DATA[i]);

//	// DATA.emplace_back(BUF);	//後ろに追加

//  DATA.erase(std::unique(DATA.begin(), DATA.end()), DATA.end());

//	vector<vector<SINT32>> DP(N,vector<SINT32>(3));　//2次元配列

/*
	SINT32 M = 3;
	vector<pair<SINT32,SINT32>> DATA2(M);
	for (SINT32 i = 0; i < M; i++) {
		cin >> DATA2[i].first;
		cin >> DATA2[i].second;
	}
	sort(DATA2.begin(),DATA2.end());
	cout << DATA2[0].first << endl;
	cout << DATA2[0].second << endl;
*/

// 	vector<pair<int,pair<int,int>>> DATA(M);
//	cin >> DATA[i].first;
//	cin >> DATA[i].second.first;
//	cin >> DATA[i].second.second;


//		APOSI = lower_bound(ADATA.begin(),ADATA.end(),QDATA[i]) - ADATA.begin();
//		BPOSI = lower_bound(BDATA.begin(),BDATA.end(),QDATA[i]) - BDATA.begin();


/* 文字列回転
	string N;
	cin >> N;
	N = N[N.length()-1] + N.substr(0,N.length()-1);
*/

Measured memory_bytes: 256