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

using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

typedef pair<int, int> Pi;
typedef tuple<int, int, int> Ti;
typedef vector<int> vint;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

struct SegmentTree {
  vector< set<int> > dataO, dataP;
  int sz;
  SegmentTree(int n) {
    sz = 1; while(sz < n) sz<<=1;
    resz(dataO, 2*sz-1);
    resz(dataP, 2*sz-1);
  }
  void update(int a, int b, int c, int k, int l, int r) {
    if(r <= a || b <= l) return;
    if(a <= l && r <= b) {
      dataO[k].insert(c);
      return;
    }
    update(a, b, c, 2*k+1, l, (l+r)/2);
    update(a, b, c, 2*k+2, (l+r)/2, r);
    dataP[k].insert(c);
  }
  void update(int a, int b, int c) {
    update(a, b, c, 0, 0, sz);
  }
  bool query(int a, int b, int c, int d, int k, int l, int r) {
    if(r <= a || b <= l) return true;
    bool vO = dataO[k].lower_bound(c) == dataO[k].upper_bound(d);
    if(!vO) return false;
    bool vP = dataP[k].lower_bound(c) == dataP[k].upper_bound(d);
    if(a <= l && r <= b) return vP;
    bool vl = query(a, b, c, d, 2*k+1, l, (l+r)/2);
    bool vr = query(a, b, c, d, 2*k+2, (l+r)/2, r);
    return vl&&vr;
  }
  bool query(int a, int b, int c, int d) {
    return query(a, b, c, d, 0, 0, sz);
  }
};

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int N;
  cin >> N;
  vint px(N), py(N), qx(N), qy(N);
  vint cx, cy;
  rep(i, N) {
    cin >> px[i] >> py[i] >> qx[i] >> qy[i];
    cx.push_back(px[i]); cy.push_back(py[i]);
    cx.push_back(qx[i]); cy.push_back(qy[i]);
  }
  sort(all(cx));
  cx.erase(unique(all(cx)), end(cx));
  sort(all(cy));
  cy.erase(unique(all(cy)), end(cy));

  rep(i, N) {
    px[i] = lower_bound(all(cx), px[i])-begin(cx);
    py[i] = lower_bound(all(cy), py[i])-begin(cy);
    qx[i] = lower_bound(all(cx), qx[i])-begin(cx);
    qy[i] = lower_bound(all(cy), qy[i])-begin(cy);
    if(px[i] > qx[i]) swap(px[i], qx[i]);
    if(py[i] > qy[i]) swap(py[i], qy[i]);
  }

  SegmentTree segX(cx.size()), segY(cy.size());

  rep(i, N) {
    if(segX.query(px[i], qx[i]+1, py[i], qy[i]) &&
       segY.query(py[i], qy[i]+1, px[i], qx[i])) {
      cout << 1 << endl;
      if(px[i] == qx[i]) segY.update(py[i], qy[i]+1, px[i]);
      else segX.update(px[i], qx[i]+1, py[i]);
    } else {
      cout << 0 << endl;
    }
  }
  return 0;
}

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

int main() {
    ll n, q;
    ll k;
    cin >> n >> k >> q;

    vector<ll> score(n, k-q);

    for(ll i=0; i<q; i++){
        ll aa;
        cin >> aa;
        score[aa-1]++;
    }

    for(ll i=0; i<n; i++){
        if(score[i]<=0){
            cout << "No" << endl;
        }else{
            cout << "Yes" << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
int main() {
  string a, b, c, d;
  cin >> a >> b >> c;
  d = "aaa";
  d.at(0) = toupper(a.at(0));
  d.at(1) = toupper(b.at(0));
  d.at(2) = toupper(c.at(0));
  cout << d << endl;
}

Measured memory_bytes: 256
import sys
a=int(input())
l=list(map(int,input().split()))
c=1
t=True
for i in l:
  if i==0:
    print(0)
    sys.exit()
  if t:
    c*=i
    if c>10**18:
      t=False
if t:
  print(c)
else:
  print(-1)

Measured memory_bytes: 21564
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <queue>

using namespace std;

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

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

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

  LL N; cin >> N;
  LL ans = 0;
  while(N > 1){
	N = (N + 2) / 3;
	++ans;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1188
#include <cstdio>
#include <map>

using namespace std;

pair<int,int> seg[1<<18];
int N,R,L;

void update(int k,int a){
    int id = k + 1;
    k += (1 << 17)-1;
    seg[k].first += a;
    seg[k].second = id;

    while(k){
        k = (k-1)/2;
        if(seg[2*k+1].first >= seg[2*k+2].first){
            seg[k] = seg[2*k+1];
        }
        else if(seg[2*k+1].first < seg[2*k+2].first){
            seg[k] = seg[2*k+2];
        }
    }
}
    
int main(){
    int data[100000] = {0};
    scanf("%d %d %d",&N,&R,&L);

    for(int i=0;i<N;i++)update(i,0);

    int top=0;
    int prev=0;
    for(int i=0;i<R;i++){
        int d,t,x;
        scanf("%d %d %d",&d,&t,&x);
        data[top] += t - prev;
        update(d-1,x);
        top = seg[0].second - 1;
        prev = t;
    }
    data[top] += L-prev;

    int maxi = 0;

    for(int i=1;i<N;i++)if(data[maxi] < data[i] ) maxi = i;

    printf("%d\n",maxi+1);

    return 0;
}

Measured memory_bytes: 3476
#include <bits/stdc++.h>
#define cinf(n,x) for(int i=0;i<(n);i++) cin >> x[i];
typedef long long int ll;
using namespace std;

int main(){
	string s; cin >>s;
	for(int i=2;i<=s.size();i+=2){
		if(s.substr(0,(s.size()-i)/2)==s.substr((s.size()-i)/2,(s.size()-i)/2)){
			cout <<s.size()-i << endl;
			break;
		}
	}
	return 0;
}


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

#define int long long
typedef pair<int, int> P;
#define mod 1000000007
#define INF (1LL<<60)
 
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
#define YES puts("YES")
#define Yes puts("Yes")
#define NO  puts("NO")
#define No  puts("No")
#define ALL(v) (v).begin(), (v).end()
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
 
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
 
 
#if 1
//-------------
// DUMPマクロ
// https://www.creativ.xyz/dump-cpp-652/
 
// vector
template <typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    for (T& x : vec) is >> x;
    return is;
}
// pair
template <typename T, typename U>
ostream& operator<<(ostream& os, pair<T, U>& pair_var) {
    os << "(" << pair_var.first << ", " << pair_var.second << ")";
    return os;
}
// vector
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
// map
template <typename T, typename U>
ostream& operator<<(ostream& os, map<T, U>& map_var) {
    os << "{";
    repi(itr, map_var) {
        os << *itr;
        itr++;
        if (itr != map_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
// set
template <typename T>
ostream& operator<<(ostream& os, set<T>& set_var) {
    os << "{";
    repi(itr, set_var) {
        os << *itr;
        itr++;
        if (itr != set_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    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 DEB
#define dump(...)                                                              \
    DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                            \
            << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]"        \
            << endl                                                            \
            << "    ",                                                         \
        dump_func(__VA_ARGS__)
#else
#define DEB if (false)
#define dump(...)
#endif
#endif


int calc(int H){
    if(H==0) return 0;
    if(H==1) return 1;
    return 1+calc(H/2)*2;
}

void solve(){
    int H;
    cin >> H;
    cout << calc(H) << endl;
}

signed main(){
    cout << fixed << setprecision(18) << endl;
    cerr << fixed << setprecision(18) << endl;
    solve();
}


Measured memory_bytes: 256
import heapq
import math
n,m=map(int,input().split())
a = list(map(int,input().split()))
h = []
for _a in a:
  heapq.heappush(h,-_a)
for i in range(m):
  heapq.heappush(h,math.ceil(heapq.heappop(h) / 2))
print(sum(h)*(-1))



Measured memory_bytes: 14532
import sys
sys.setrecursionlimit(10**5+5)
from collections import defaultdict,deque
input = sys.stdin.readline
class LCA:

    def __init__(self,n):
        self.size = n+1
        self.bitlen = n.bit_length()
        self.lca = [[0]*self.size for i in range(self.bitlen)]
        self.depth = [-1]*self.size
        self.dis = [-1]*self.size
        self.depth[1] = 0
        self.dis[1] = 0
    def make(self,root):
        q = deque([root])
        while q:
            now = q.popleft()
            for nex,c,w in e[now]:
                if self.depth[nex]>= 0:
                    continue
                self.depth[nex] = self.depth[now]+1
                self.dis[nex] = self.dis[now]+w
                self.lca[0][nex] = now
                q.append(nex)
        for i in range(1,self.bitlen):
            for j in range(self.size):
                if self.lca[i-1][j] > 0:
                    self.lca[i][j] = self.lca[i-1][self.lca[i-1][j]]
    
    def search(self,x,y):
        dx = self.depth[x]
        dy = self.depth[y]
        if dx < dy:
            x,y = y,x
            dx,dy = dy,dx
        dif = dx-dy
        while dif:
            s = dif & (-dif)
            x = self.lca[s.bit_length()-1][x]
            dif -= s
        if x == y:
            return x
        for i in range(self.bitlen-1,-1,-1):
            if self.lca[i][x] != self.lca[i][y]:
                x = self.lca[i][x]
                y = self.lca[i][y]
        
        return self.lca[0][x]

n,q = map(int,input().split())
e = [[] for i in range(n+1)]
for i in range(n-1):
    a,b,c,d = map(int,input().split())
    e[a].append((b,c,d))
    e[b].append((a,c,d))
    
lca = LCA(n)
lca.make(1)

Q = []
dcount = defaultdict(lambda : defaultdict(int))
dweight = defaultdict(lambda : defaultdict(int))
for i in range(q):
    x,y,u,v = map(int,input().split())
    a = lca.search(u,v)
    dcount[u][x] = 0
    dcount[v][x] = 0
    dcount[a][x] = 0
    dweight[u][x] = 0
    dweight[v][x] = 0
    dweight[a][x] = 0
    Q.append((x,y,u,v,a))

dis = [0]*(n+1)


def dfs1(now,p,count1,count2):
    for cou in dcount[now]:
        dcount[now][cou] = count1[cou]
    for wei in dweight[now]:
        dweight[now][wei] = count2[wei]

    for nex,c,w in e[now]:
        if nex == p:
            continue
        count1[c] += 1
        count2[c] += w
        dis[nex] =dis[now]+w
        dfs1(nex,now,count1,count2)
        count1[c] -= 1
        count2[c] -= w
    
dfs1(1,0,defaultdict(int),defaultdict(int))

for x,y,u,v,a in Q:
    cal = dis[u]+dis[v]-2*dis[a]
    cal += y*(dcount[u][x]+dcount[v][x]-2*dcount[a][x]) - dweight[u][x]-dweight[v][x]+2*dweight[a][x]
    print(cal)

Measured memory_bytes: 929768
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <queue>
#include <vector>
#include <algorithm>
#include <cmath>
#include <chrono>
using namespace std;

int main(int argc, const char * argv[]) {
    
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int64_t x, y; cin >> x >> y;
    
    int64_t ans = 1;
    int64_t a = x;
    while (a <= y) {
        a *= 2;
        ans++;
    }
    cout << ans - 1 << endl;
    
    return 0;
}


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

int main(void) {
  int n, k;
  cin >> n >> k;
  vector<int> h(n), b(n - k + 1);
  int i = 0;
  for(; i < n; i++) cin >> h[i];
  sort(h.begin(), h.end());
  for(i = 0; i < n - k + 1; i++) b[i] = h[i + k - 1] - h[i];
  sort(b.begin(), b.end());
  cout << b[0] << endl;
  return 0;
}

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

int main() {
  ll H,a,sum=0;
  cin>>H;
  a=log2(H);
  for(int i=0;i<=a;i++) sum+=pow(2,i);
  cout<<sum<<endl;
}	


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


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

  bool flag = false;
  for (auto i = 0; i < 3; ++i) {
    if(N[i] == '7') {
      flag = true;
      break;
    }
  }
  
  if (flag) {
    cout << "Yes" << endl;
  }
   else {
     cout << "No" << endl;
   }
}

Measured memory_bytes: 3628
import java.util.*;

public class Main {

    Scanner sc = new Scanner(System.in);

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

    void run() {

        char[] arr = sc.next().toCharArray();

        for (int i=0; i<arr.length; i++) {
            if (arr[i] == '?') {
                if (i==0) {
                    arr[0] = 'D';
                } else if (i==arr.length-1) {
                    arr[arr.length-1] = 'D';
                } else {
                    if (arr[i-1]=='P') {
                        arr[i] = 'D';
                    } else {
                        if (arr[i+1] == 'D') {
                            arr[i] = 'P';
                        } else {
                            arr[i] = 'D';
                        }
                    }
                }
            }
        }

        StringBuilder sb = new StringBuilder();

        for (int i=0; i<arr.length; i++) {
            sb.append(arr[i]);
        }

        System.out.println(sb.toString());


    }
}

Measured memory_bytes: 41752
# coding: utf-8

import bisect


def main():
    N = int(input())
    A = list(map(int, input().split()))

    j_minus_aj_ = sorted([(j - A[j], j) for j in range(N)])
    j_minus_aj, j_minus_aj_j = [None] * N, [None] * N
    for j in range(N):
        j_minus_aj[j], j_minus_aj_j[j] = j_minus_aj_[j]

    j_plus_aj_ = sorted([(j + A[j], j) for j in range(N)])
    j_plus_aj, j_plus_aj_j = [None] * N, [None] * N
    for j in range(N):
        j_plus_aj[j], j_plus_aj_j[j] = j_plus_aj_[j]

    ans = 0

    for i in range(N):
        # i <= j
        i_plus_ai = i + A[i]

        left = bisect.bisect_left(j_minus_aj, i_plus_ai)
        right = bisect.bisect_right(j_minus_aj, i_plus_ai)

        # for j in range(left, right):
        #     if j_minus_aj_j[j] >= i:
        #         ans += 1
        ans += right - left
        
        i_minus_ai = i - A[i]

        left = bisect.bisect_left(j_plus_aj, i_minus_ai)
        right = bisect.bisect_right(j_plus_aj, i_minus_ai)

        # for j in range(left, right):
        #     if j_plus_aj_j[j] < i:
        #         ans += 1
        ans += right - left
    
    return ans // 2

    # for i in range(N):
    #     # i <= j
    #     i_plus_ai = i + A[i]
    #     # left = geq_search(j_minus_aj, i_plus_ai-1)
    #     # dif = 0
    #     # while left+dif+1 < N and j_minus_aj[left+dif+1] != i_plus_ai:
    #     #     dif += 1
    #     # left = left + dif
    #     left = bisect.bisect_left(j_minus_aj, i_plus_ai)

    #     # right = leq_search(j_minus_aj, i_plus_ai+1)
    #     # dif = 0
    #     # while 0 <= right-dif-1 and j_minus_aj[right-dif-1] != i_plus_ai:
    #     #     dif += 1
    #     # right = right - dif
    #     right = bisect.bisect_left(j_minus_aj, i_plus_ai)

    #     for j in range(left, right):
    #         if j_minus_aj_j[j] >= i:
    #             ans += 1
        
    #     i_minus_ai = i - A[i]
    #     # left = geq_search(j_plus_aj, i_minus_ai-1)
    #     # dif = 0
    #     # while left+dif+1 < N and j_plus_aj[left+dif+1] != i_minus_ai:
    #     #     dif += 1
    #     # left = left + dif
    #     left = bisect.bisect_left(j_plus_aj, i_minus_ai)

    #     # right = leq_search(j_plus_aj, i_minus_ai+1)
    #     # dif = 0
    #     # while 0 <= right-dif-1 and j_plus_aj[right-dif-1] != i_minus_ai:
    #     #     dif += 1
    #     # right = right - dif
    #     right = bisect.bisect_left(j_plus_aj, i_minus_ai)

    #     for j in range(left, right):
    #         if j_plus_aj_j[j] < i:
    #             ans += 1
    
    # return ans


print(main())


Measured memory_bytes: 123028
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=a;i--)
#define sz(x) (int)(x).size()
#define all(x) (x).begin(),(x).end()
#define de(x) cout << #x << "=" << x << endl
#define dd(x) cout << #x << "=" << x << " "
#define pw(x) (1ll<<(x))
#define pq priority_queue
#define endl "\n"
const ll maxn=1e5+100;
ll a[maxn],b[maxn];
int main()
{
    ios::sync_with_stdio(false);
    ll A,B,M,minn1=maxn,minn2=maxn;
    cin >> A >> B >> M;
    for(int i=1;i<=A;i++){
    	cin>> a[i];
    	minn1=min(minn1,a[i]);
	}
	for(int i=1;i<=B;i++){
		cin >> b[i];
		minn2=min(minn2,b[i]);
	}
	ll ans=minn1+minn2;
	for(int i=0;i<M;i++){
		ll x,y,c;
		cin >> x >> y >> c;
		ans=min(ans,a[x]+b[y]-c);
	}
	cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
 
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
#define mod 1000000007LL
#define nax 200009LL
#define FOR(i,n,m) for(int i = (n); i < (m); i++)
#define REP(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define all(v) v.begin(),v.end()
#define sz(v) int(v.size())
 
 
typedef long long ll;
typedef vector<int> vi; 
typedef pair<int,int> ii;


int main(){
	fastio;

    int n, x, y, ans[2009];
    bool vis[2009];
    vi adj[2009];
    cin>>n>>x>>y;

    FOR(i,1,n){
        adj[i].pb(i+1); adj[i+1].pb(i);
    }
    
    adj[x].pb(y); adj[y].pb(x);

    REP(i,2009) ans[i]=0;
    queue<int> q;
    int dist[2009];

    FOR(i,1,n+1){
        memset(vis, 0, sizeof vis);
        q.push(i);
        vis[i]=1;
        dist[i]=0;
        while(!q.empty()){
            int x=q.front(); q.pop();
            for(auto u : adj[x]){
                if(vis[u]) continue;
                vis[u]=1;
                dist[u]=dist[x]+1;
                q.push(u);
                ans[dist[u]]++;
            }
        }

    }

    FOR(i,1,n) cout<<ans[i]/2<<"\n";

	return 0;
}

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

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

    int N;
    cin >> N;
    vector<int> nums;
    for (int i = 0; i < N; i++)
    {
        int num;
        cin >> num;
        nums.push_back(num);
    }
    int answer = 0;
    int border = 1e7;
    for(int i = 0; i < N; i++){
        if(border > nums.at(i)){
            answer++;
            border = nums.at(i);
        }
    }
    cout << answer << endl;
    return 0;
}

Measured memory_bytes: 1400
(n,k),*a=$<.map{|s|s.split.map &:to_i}
h=[]
v=[9e9]*n
i=x=s=0
p a.sort_by{|t,d|[-d,t]}.map{|t,d|(k<i+=1)?(h[t]||=s+=d-v.pop+x+x+=1):(h[t]?v<<d:s+=x+x+=1;h[t]=s+=d)}.max

Measured memory_bytes: 15080
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<string>
#include<stack>
#include<cstdio>
#include<cmath>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<int,P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i,x) for(int i=0;i<x;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rrep1(i,x) for(int i=x;i>0;i--)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
#define mp1(a,b,c) P1(a,P(b,c))

const int INF=1000000000;
const int dir_4[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
const int dir_8[8][2]={{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};

int main(){
	int H,W,N;
	int a,b;
	string S,T;
	cin >> H >> W >> N >> a >> b >> S >> T;
	
	int l=1,r=W,u=1,d=H;
	rrep(i,N){
		if(T[i] == 'L'){
			if(r != W)r ++;
		}
		else if(T[i] == 'R'){
			if(l != 1)l --;
		}
		else if(T[i] == 'U'){
			if(d != H)d ++;
		}
		else {
			if(u != 1)u --;
		}
		if(S[i] == 'L')l ++;
		else if(S[i] == 'R')r --;
		else if(S[i] == 'U')u ++;
		else d --;
		if(r < l || d < u){
			puts("NO");
			return 0;
		}
		//cout << l << " " << r << " " << u << " " << d << endl;
	}
	if(l <= b && b <= r && u <= a && a <= d)puts("YES");
	else puts("NO");
}


Measured memory_bytes: 776
//  ######    ##   ######    ##   ##    ##
//  ##  ##   ###   ##  ##   ###   ###   ##
//  ######  ####   ######  ####   ##### ##
//  ##     ## ##   ##     ## ##   ## #####
//  ##    ##  ##   ##    ##  ##   ##   ###
#include<bits/stdc++.h>
using namespace std;
typedef long long lo;
typedef pair<lo,lo> ll;//pair
typedef vector<lo> vl;  //vector of long
typedef vector<ll > vll;   //vector of pair
typedef priority_queue<lo>p_q;
#define mp(a,b) make_pair((a),(b))
#define REP(a,b) for(lo i=(a);i<(b);i++)//no need to declare variable i
#define REPE(a,b,c,d) REP(a,b)for(lo j=(c);j<(d);j++)//no need to declare vaiables i,j
#define REPV(a,b,c) for((a)=b;(a)<(c);(a)++)//a is the variable
#define IREP(a,b) for(lo i=(a);i>=(b);i--)
#define IREPV(a,b,c) for((a)=b;(a)>=(c);(a)--)
#define all(v) (v).begin(),(v).end()
#define TRvl(c) for (vl::iterator it = (c).begin(); it != (c).end(); it++)
#define TRvll(c) for (vll::iterator it = (c).begin(); it != (c).end(); it++)
#define mod 1000000007
#define gc getchar_unlocked
#define pc putchar_unlocked3
#define pb(a) push_back((a))
 
int arr[100005];
int ar[10][100005];
int coun[10];
void solve()
{
    int n;
    cin>>n;
    string str;
    cin>>str;
    set<string> s;
    for(int i=0;i<n;i++){arr[i]=str[i]-'0';coun[arr[i]]++;}
    for(int i=0;i<n;i++)
        ar[arr[i]][i]=i;
    for(int i=0;i<10;i++)
    {
        for(int j=100004;j>=0;j--)
        {
            if(!ar[i][j])ar[i][j]=ar[i][j+1];
        }
    }
    for(int i=0;i<10;i++)
    {
        for(int j=0;j<=100004;j++)
        {
            ar[i][j]=ar[i][j+1];
        }
    }

    /*for(int i=0;i<10;i++)
    {
        for(int j=0;j<10;j++)
            cout<<ar[i][j]<<' ';cout<<endl;
    }*/
    for(int i=0;i<n;i++)
    {
        int p = str[i]-'0';

        for(int j=0;j<10;j++)
        {
            if(ar[j][i])
            {
                int c = ar[j][i];
                for(int k=0;k<10;k++)
                {
                    if(ar[k][c])
                    {
                        string st;
                    
                        st.insert(st.end(),p+'0');
                        st.insert(st.end(),j+'0');
                        st.insert(st.end(),k+'0');
                        s.insert(st);
                        //cout<<st<<endl;
                    }
                }
            }
        }
    }
    //cout<<s.size()<<endl;
    for(int i=0;i<10;i++)
    {
        if(coun[i]>=3)
        {
            string st;
            st.insert(st.end(),i+'0');
            st.insert(st.end(),i+'0');
            st.insert(st.end(),i+'0');
            s.insert(st);
        }
    }
    cout<<s.size();
}


int main()
{
    /*
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    */
    
    lo t;
    //cin>>t;
    //while(t--)
        solve();




}


Measured memory_bytes: 4480
h, n = map(int, input().split())
a, b = [], []
for i in range(n):
    ai, bi = map(int, input().split())
    a.append(ai)
    b.append(bi)

lst = [10**9 for i in range(h+1)]
lst[0] = 0

for i in range(1, h+1):
    for j in range(n):
        if i-a[j] > 0:
            lst[i] = min(lst[i], lst[i-a[j]]+b[j])
        else:
            if a[j] >= i:
                lst[i] = min(lst[i], b[j])

print(lst[-1])

Measured memory_bytes: 44368
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    [a, b] <- getIntList
    let m = max a b
        m' = if a == b then m else pred m
    print $ m + m'

Measured memory_bytes: 380
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String s = sc.next();
        char[] c = new char[s.length()];
        for (int i = 0; i < s.length(); i++) {
            int next = s.charAt(i) + n;
            if (next > 90) {
                next -= 26;
            }
            c[i] = (char)next;
        }
        String result = new String(c);
        System.out.println(result);
        sc.close();
    }
}

Measured memory_bytes: 23124
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll inf=1000000000000000000;
double pi=2*acos(0);
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll lmax(ll a,ll b){
    if(a<b)return b;
    else return a;
}
ll lmin(ll a,ll b){
    if(a<b)return a;
    else return b;
}
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
ll gya[1000010];
ll kai[1000010];
ll beki(ll n,ll k){
  ll ret=1;
  ll now=n;
  while(k>0){
    if(k%2==1){
      ret*=now;
      ret%=mod;
    }
    now*=now;
    now%=mod;
    k/=2;
  }
  return ret;
}
ll gyaku(ll n){
  return beki(n,mod-2);
}
void nckinit(ll n){
  kai[0]=1;
  kai[1]=1;
  for(int i=2;i<=n;i++){
    kai[i]=kai[i-1]*i;
    kai[i]%=mod;
  }
  gya[n]=gyaku(kai[n]);
  for(int i=n-1;i>=1;i--){
    gya[i]=gya[i+1]*(i+1);
    gya[i]%=mod;
  }
  gya[0]=1;
}
ll nck(ll n,ll k){
  if(k<0)return 0;
  if(k==0||n==k)return 1;
  ll ret=kai[n];
  ret*=gya[n-k];
  ret%=mod;
  ret*=gya[k];
  ret%=mod;
  return ret;
}
ll npk(ll n,ll k){
  if(k<0)return 0;
  if(k==0)return 1;
  ll ret=kai[n];
  ret*=gya[n-k];
  ret%=mod;
  return ret;
}

int main(){
    ios::sync_with_stdio(false);cin.tie(0);
    ll n,t;cin>>n>>t;
    ll a[n],b[n];
    vector<pll> v;
    rep(i,0,n){
        cin>>a[i]>>b[i];
        v.push_back({a[i],b[i]});
    }
    sort(v.begin(),v.end());
    rep(i,0,n){
        a[i]=v[i].first;
        b[i]=v[i].second;
    }
    ll dp[n+1][6001];
    rep(i,0,n+1){
        rep(j,0,6001)dp[i][j]=-1;
    }
    dp[0][0]=0;
    rep(i,0,n){
        rep(j,0,t){
            if(dp[i][j]==-1)continue;
            dp[i+1][j]=max(dp[i+1][j],dp[i][j]);
            ll u=j+a[i];
            dp[i+1][u]=max(dp[i+1][u],dp[i][j]+b[i]);
        }
    }
    ll ans=0;
    rep(i,0,n+1){
        rep(j,0,6001)ans=max(ans,dp[i][j]);
    }
    cout<<ans<<endl;
    
}



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

template <class T>
struct Primal_Dual {
  using Pa = pair<T, int>;
  T infinity = (long long)(1e10);
  struct edge {
    int to;
    T cap, cost;
    int rev;
  };
  int v;
  vector<vector<edge>> edges;
  vector<T> h;
  vector<T> dist;
  vector<int> prevv, preve;
  Primal_Dual(int vsize = 1) {
    v = vsize;
    edges.resize(v);
    h.resize(v);
    dist.resize(v);
    prevv.resize(v);
    preve.resize(v);
  }
  bool add(int from, int to, T cap, T cost) {
    edges[from].push_back((edge){to, cap, cost, (int)edges[to].size()});
    edges[to].push_back((edge){from, 0, -cost, (int)edges[from].size() - 1});
    return 1;
  }
  T solve(int s, int t, T f) {
    T ans = 0;
    h.assign(v, 0);
    while (f > 0) {
      priority_queue<Pa, vector<Pa>, greater<Pa>> qu;
      dist.assign(v, infinity);
      dist[s] = 0;
      qu.push({0, s});
      while (!qu.empty()) {
        Pa now = qu.top();
        qu.pop();
        int nowv = now.second;
        if (dist[nowv] < now.first) continue;
        for (int i = 0; i < (int)edges[nowv].size(); ++i) {
          edge &e = edges[nowv][i];
          if (e.cap > 0 &&
              dist[e.to] > dist[nowv] + e.cost + h[nowv] - h[e.to]) {
            dist[e.to] = dist[nowv] + e.cost + h[nowv] - h[e.to];
            prevv[e.to] = nowv;
            preve[e.to] = i;
            qu.push({dist[e.to], e.to});
          }
        }
      }
      if (dist[t] == infinity) return -1;
      for (int i = 0; i < v; ++i) h[i] += dist[i];
      T d = f;
      for (int i = t; i != s; i = prevv[i])
        d = min(d, edges[prevv[i]][preve[i]].cap);
      f -= d;
      ans += d * h[t];
      for (int i = t; i != s; i = prevv[i]) {
        edge &e = edges[prevv[i]][preve[i]];
        e.cap -= d;
        edges[i][e.rev].cap += d;
      }
    }
    return ans;
  }
};

struct mat {
  vector<long long> v;
};

int n;
vector<mat> v;
Primal_Dual<long long> pd;

int main() {
  while (1) {
    cin >> n;
    if (n == 0) break;
    v.resize(n);
    for (int i = 0; i < n; ++i) {
      v[i].v.resize(3);
      for (int j = 0; j < 3; ++j) cin >> v[i].v[j];
      sort(v[i].v.begin(), v[i].v.end(), greater<long long>());
    }
    pd = Primal_Dual<long long>((n + 1) * 2);
    long long sum = 0;
    for (int i = 0; i < n; ++i) {
      sum += v[i].v[0] * v[i].v[1] * v[i].v[2];
      pd.add(2 * n, i, 1, 0);
      pd.add(i, 2 * n + 1, 1, 1e8);
      pd.add(i + n, 2 * n + 1, 1, 0);
      for (int j = 0; j < n; ++j) {
        bool ch = 1;
        for (int k = 0; k < 3; ++k)
          if (v[i].v[k] >= v[j].v[k]) ch = 0;
        if (ch)
          pd.add(i, j + n, 1,
                 (long long)1e8 - v[i].v[0] * v[i].v[1] * v[i].v[2]);
      }
    }
    cout << sum - (n * (long long)(1e8)) + pd.solve(2 * n, 2 * n + 1, n)
         << endl;
  }
  return 0;
}



Measured memory_bytes: 3244
#include "bits/stdc++.h"
 
typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
using namespace std;
typedef pair<int,int> pii;
int MOD = 998244353;

signed main(){
    int n,k;
    cin >> n >> k;
    
    if(k > (n-1)*(n-2)/2 ){
        cout << -1 << endl;
        return 0;
    }

    cout << n-1 + (n-1)*(n-2)/2 - k << endl;
    rep(i,n-1){
        cout << 1 << " " << i+2 << endl;
    }
    int cnt = (n-1)*(n-2)/2 - k;
    for(int i = 2;i <= n;i++){
        for(int j = i+1; j <= n;j++){
            if(cnt > 0){
                cout << i << " " << j << endl;
                cnt--;
            }
        }
    }

    
    

    
    
     
    return 0;
}

// g++ -std=c++14 code1.cpp
// rm -r -f test;oj dl https://cf17-final-open.contest.atcoder.jp/tasks/cf17_final_a
// rm -r -f test;oj dl http://abc131.contest.atcoder.jp/tasks/abc131_e


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep0(i,n) for(ll (i) = 0; (i) < (n); ++(i))
#define rrep0(i,n) for(ll (i) = (n) - 1; (i) >= 0; --(i))
#define rep1(i,n) for(ll (i) = 1; (i) <= (n); ++(i))
#define rrep1(i,n) for(ll (i) = (n); (i) >= 1; --(i))
#define nfor(i,a,b) for(ll (i) = (a); (i) < (b); ++(i))
#define rfor(i,a,b) for(ll (i) = (a); (i) > (b); --(i))
#define ll long long
#define mod (1000000007)
#define pf(x) cout << (x) << endl;
#define all(x) (x).begin(),(x).end()

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

ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b;
}

ll factorial(ll n){
    ll t = 1;
    rep1(i, n)t *= i;
    return t;
}

ll combinations(ll n, ll k) {
    ll r = 1;
    rep1(i, k)r = r * n-- / i;
    return r;
}

int main()
{
    double h,w,n;
    cin >> h >> w >> n;
    pf(ceil(n / max(h,w)))
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<string>
#include<stdio.h>
#include<stdlib.h>
#include<float.h>
#include<tuple>
#include<string.h>
#include<iomanip>
#include<stack>
#include<queue>

using namespace std;
#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define ALLOF(c) (c).begin(), (c).end()
#define Pa pair<ll,ll>
const ll mod=1000000007;
const ll INF=10e12;
const ll inf=-1;
ll ABS(ll a){return max(a,-a);}
ll modpow(ll a,ll n) {
    ll res = 1;
    while (n>0) {
        if(n&1) res=res*a%mod;
        a=a*a%mod;
        n>>=1;
    }
    return res;
}

// a^{-1} mod を計算する
ll modinv(ll a) {
    return modpow(a, mod - 2);
}


int main(void){
    ll N;
    cin>>N;
    vector<ll> A(N),S(N+1);
    S.at(0)=0;
    rep(i,N){
        cin>>A.at(i);
        S.at(i+1)=S.at(i)+A.at(i);
    }
    sort(ALLOF(S));
    ll ans=0,now=INF,kosu=1;
    rep(i,N+1){
        if(now!=S.at(i)){
            now=S.at(i);
            ans+=kosu*(kosu-1)/2;
            kosu=1;
        }
        else kosu++;
    }
    ans+=kosu*(kosu-1)/2;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3328
function Main(inp) {
    var input = inp.split("\n");
    input = input[0].split(' ').map(function (n) { return Number(n);});
    var r = input[0];
    var g = input[1];
    var b = input[2];
    if ((r * 100 + g * 10 + b) % 4 === 0) {
        console.log('YES');
        return;
    }
    console.log('NO');
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7500
def binary_search(num_list, num):
    left = 0
    right = len(num_list) - 1

    count = 0

    while left <= right:
        mid = left + (right - left) // 2
        count += 1

        if num_list[mid] == num:
            break
        elif num_list[mid] < num:
            left = mid + 1
        else:
            right = mid - 1

    return count


while True:

    input_count = int(input())

    if input_count == 0:
        break

    num_list = [int(input()) for _ in range(input_count)]

    search_number = int(input())

    result = binary_search(num_list, search_number)

    print(result)



Measured memory_bytes: 5600
#include <cstdio>

const int MaxN = 300 + 5;

int N;
int A[MaxN], Cnt[4];
double dp[MaxN][MaxN][MaxN];
bool vis[MaxN][MaxN][MaxN];

void init() {
  scanf("%d", &N);
  for (int i = 1; i <= N; ++i) scanf("%d", &A[i]);
  for (int i = 1; i <= N; ++i) Cnt[A[i]]++;
}

double dfs(int k, int i, int j) {
  if (vis[k][i][j] == true) return dp[k][i][j];
  vis[k][i][j] = true;
  if (i == 0 && j == 0 && k == 0) return dp[k][i][j] = 0;

  if (k != 0) dp[k][i][j] += dp[k - 1][i][j + 1] * k / N;
  if (i != 0) dp[k][i][j] += dfs(k, i - 1, j) * i / N;
  if (j != 0) dp[k][i][j] += dfs(k, i + 1, j - 1) * j / N;
  dp[k][i][j]++;
  dp[k][i][j] /= 1.0 * (i + j + k) / N;
  return dp[k][i][j];
}

void solve() {
  for (int k = 0; k <= Cnt[3]; ++k)
    for (int i = 0; i <= N; ++i)
      for (int j = 0; j <= N; ++j)
        if (i + j + k <= N) dfs(k, i, j);
  printf("%.10lf\n", dp[Cnt[3]][Cnt[1]][Cnt[2]]);
}

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

Measured memory_bytes: 245888
import java.util.*

fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val aQueue = ArrayDeque(readLine()!!.split(' ').map(String::toInt))
    val result = ArrayDeque<Int>()

    if (n % 2 == 1) {
        result.addFirst(aQueue.pop())
    }
    while (!aQueue.isEmpty()) {
        if (n % 2 == 1) {
            result.addLast(aQueue.pop())
            result.addFirst(aQueue.pop())
        } else {
            result.addLast(aQueue.pop())
            result.addFirst(aQueue.pop())
        }
    }
    println(result.toMutableList().joinToString(" "))
}

Measured memory_bytes: 103180
from fractions import gcd
n,X=map(int,input().split())
x=list(map(int,input().split()))

def hoge():
    global n,x,X
    ret=abs(X-x[0])
    for i in range(1,n):
        ret=gcd(abs(X-x[i]),ret)
    return ret

print(hoge())




Measured memory_bytes: 16276
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
int main()
{
    int A[3][3];
    vector<vector<bool>> check(3, vector<bool>(3, false));
    int N;
    rep(i, 3) {
        rep(j, 3) {
            cin >> A[i][j];
        }
    }

    cin >> N;
    rep(i, N) {
        int b;
        cin >> b;
        rep(j, 3) {
            rep(k, 3) {
                if (b == A[j][k]) {
                    check[j][k] = true;
                }
            }
        }
    }

    rep(i, 3) {
        bool flag = true;
        rep(j, 3) {
            flag &= check[i][j];
        }
        if (flag) {
            cout << "Yes" << endl;
            return 0;
        }
    }

    rep(i, 3) {
        bool flag = true;
        rep(j, 3) {
            flag &= check[j][i];
        }
        if (flag) {
            cout << "Yes" << endl;
            return 0;
        }
    }

    if (check[0][0] && check[1][1] && check[2][2]) {
        cout << "Yes" << endl;
    }
    else if (check[0][2] && check[1][1] && check[2][0]) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }

    return 0;
}

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

int main() {
	// your code goes here
	int n, m, ai;
	float c;
	int mcurr = 0, t = 0;
	vector<int> a;
	cin >> n >> m;
	for(int i = 0; i < n; i++) {
		cin >> ai;
		t += ai;
		a.push_back(ai);
	}
	c = ((float)1 / (4*m)) * t;
	for(int i = 0; i < n; i++) {
		if(a[i] >= c) {
			mcurr++;
		}
	}
	if(mcurr >= m) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}
	return 0;
}

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())

template<typename T>
T mod(T a, T b){
    return (a + b) % b;
}

template<typename T>
T gcd(T a, T b){
    if (b == 0) return a;
    return gcd(b, a % b);
}

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

// n を素因数分解
map<ll, ll> factor(ll n){
    map<ll, ll> mp;
    for (ll i = 2; i*i <= n; i++) {
        while (n % i == 0) {
            mp[i]++;
            n /= i;
        }
    }

    if (n > 1) {
        mp[n]++;
    }

    return mp;
}

// 文字列に "hoge" が含まれているか
// string str = "hogepiyo";
// if (str.find("hoge") != string::npos) {
//     cout << "文字列が含まれています" << endl;
// }

// char to string
// char c = 'a';
// string str = {c};

void solve(){
    int A, B, K;
    cin >> A >> B >> K;

    vi kouho;
    for (int i = 1; i <= min(A,B); i++) {
        if (A % i == 0 && B % i == 0) {
            kouho.push_back(i);
        }
    }

    reverse(all(kouho));
    cout << kouho[K-1] << endl;

    return;
}

int main(int argc, char const* argv[])
{
    solve();
    return 0;
}


Measured memory_bytes: 384
# -*- coding: utf-8 -*-
"""
Created on Mon May  4 15:14:09 2020

@author: Kanaru Sato
"""
import itertools

h,w = list(map(int, input().split()))
mod = 10**9+7
Map = []
for i in range(h):
    Map.append(list(input()))

dp = [[0 for i in range(w)] for j in range(h)]

for i in range(h):
    for j in range(w):
        if i == 0 and j == 0:
            dp[i][j] = 1
        else:
            if Map[i][j] == "#":
                dp[i][j] = -1
            else:
                if i-1 >= 0 and dp[i-1][j] != -1:
                    dp[i][j] += dp[i-1][j]
                if j-1 >= 0 and dp[i][j-1] != -1:
                    dp[i][j] += dp[i][j-1]
                dp[i][j] %= mod

print(dp[h-1][w-1])

Measured memory_bytes: 52464
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <functional>
#include <numeric>
#include <iostream>
#include <string>
#include <time.h>

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }

int X,Y;

int main() {

	scanf("%d%d", &X,&Y);

	int ans = 0;
	if (X < 4) ans += (4 - X) * 100000;
	if (Y < 4) ans += (4 - Y) * 100000;
	if (X == 1 && Y == 1) ans += 400000;

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

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cout << #x << " = " << (x) << endl;
using Graph = vector<vector<int> >;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//#define int long long

//next_permutationは次の順列を生成していく

void solve() {
	int n; cin >> n;
    vector<pair<double, double>> p(n);
    rep(i, n) {
        cin >> p[i].fr >> p[i].sc;
    }
    double ans = 0;
    sort(all(p));
    int c = 0;
    do {
        c++;
        double res = 0;
        rep(i, n - 1) {
            res += pow(pow(p[i + 1].fr - p[i].fr, 2) + pow(p[i + 1].sc - p[i].sc, 2), 0.5);
        }
        //cout << p[1].fr << " " << p[1].sc << endl; 
        //cout << res << endl;
        ans += res;
    } while(next_permutation(all(p)));
    cout << ans / c << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(10);
	//init();
	solve();
	//cout << "finish" << endl;
    return 0;
}

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

int d[200005];

int main() {
  int N;
  string S;
  cin >> N;
  cin >> S;
  int wsum = 0;
  int ans = 0;
  rep(i, N) {
    if(S[i] == 'R') wsum++;
  }
  rep(i, wsum) {
    if(S[i] == 'W') ans++;
  }
  cout << ans << endl;
  return 0;
}




Measured memory_bytes: 3748
import java.util.*;

class Main{
    public static void main(String args[]){
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        for(int i=0;i<n;i++){
            int k=sc.nextInt();
            int h=sc.nextInt();
            if(k%h==0){
                System.out.println(h);
            }else{
                System.out.println(k%h);
            }
        }
    }
}


Measured memory_bytes: 26348
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};


int main() {
    ll N,M;
    cin >>N>>M;
    vector<vector<ll> > G(N);

    rep(i,M){
        ll a,b;
        cin>>a>>b;
        a--;
        b--;
        G[a].pb(b);
        G[b].pb(a);
    }

    vector<ll> ans(N);
    vector<ll> dist(N,-1);
    queue<ll> que;

    dist[0] = 0;
    que.push(0);

    while(!que.empty()){
        ll v = que.front();
        que.pop();

        for(ll i : G[v]){
            if(dist[i] !=-1) continue;
            ans[i] = v;
            dist[i] = dist[v] + 1;
            que.push(i);
        }
    }

    cout << "Yes" << endl;
    rep2(i,N-1){
        cout<<ans[i]+1<<endl;
    }
    


    return 0;
    

}

Measured memory_bytes: 13700
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 
#include <stack>

using namespace std;
typedef long long ll;
#define rep(i, s, e) for (int(i) = (s); (i) <= (e); ++(i))
#define all(x) x.begin(),x.end()


int main()
{
	int n,k,q;cin>>n>>k>>q;
	vector<int> a(100100,0);
	rep(i,1,q){
	    int x;cin>>x;
	    ++a[x];
	}
	rep(i,1,n){
	    if(k>q-a[i])cout<<"Yes"<<endl;
	    else cout<<"No"<<endl;
	}
}


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

using ll = long long;

const int INF = 1001001001;
const ll INF_LL = 1001001001001001001LL;

int main(void){
  int n,m; cin >> n >> m;
  vector<string> a(n); rep(i,n) cin >> a[i];
  vector<string> b(m); rep(i,m) cin >> b[i];

  bool exist = false;
  rep(ay,n){
    rep(ax,n){
      if(ax+m-1>=n || ay+m-1>=n) continue;

      bool match = true;
      rep(y,m){
	rep(x,m){
	  if(a[ay+y][ax+x] != b[y][x]) match = false;
	}
      }
      if(match) exist = true;
    }
  }

  if(exist) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}


Measured memory_bytes: 3620
(n,k),a,f = $<.map{|l|l.split.map &:to_i}
m=a.sort.zip f.sort.reverse
p (0..a.max*f.max).bsearch{|i|
  s=0
  m.each{|a,f|
    if 0 < x=a-i/f
      s+=x
    end
  }
  s <= k
}


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

int gcd(int m, int n){
  if(n==0) return m;
  else return gcd(n, m%n);
}

int main(){
  int n, m;
  cin >> n >> m;
  string s, t;
  cin >> s;
  cin >> t;
  int g = gcd(n, m);

  for(int i = 0; i < g; i++){
    if( s[i*n/g] != t[i*m/g] ){
      cout << "-1\n";
      return 0;
    }
  }
  cout << 1ll*n*m/g << "\n";
  return 0;
}


Measured memory_bytes: 512