akhauriyash/Code-Regression huggingface dataset:
def resolve_c():
    res = ''
    n, m = map(int, input().split())
    l = [list(map(int, input().split())) for i in range(m)]
    ans = [-1] * n
    flg = 0

    for p in l:
        if n != 1 and p[0] == 1 and p[1] == 0: # n!=1でかつ1桁目が0のとき
            print(-1)
            flg = 1
        elif ans[p[0]-1] != -1 and ans[p[0]-1] != p[1]:# 同じ桁で別の数字が指定されている時
            print(-1)
            flg = 1
        else:
            ans[p[0]-1] = p[1]

    for i in range(len(ans)):
        if i == 0 and ans[0] == -1 and len(ans) != 1:
            res = res + '1'
        elif ans[i] == -1:
            res = res + '0'
        else:
            res = res + str(ans[i])
    if flg == 0:
        print(int(res))
resolve_c()

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

#define LL long long

#define FOR(INDEX, START, END) for (LL INDEX = (START); INDEX < (END); ++INDEX)
#define REP(INDEX, COUNT) for (LL INDEX = 0; INDEX < (COUNT); ++INDEX)

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

	LL a[30];
	REP(i, N) {
		cin >> a[i];
	}

	int cnt = 0;
	for (int i = 1; i < N - 1; ++i) {
		vector<int> t;
		for (int j = -1; j <= 1; ++j) {
			t.push_back(a[i + j]);
		}
		sort(t.begin(), t.end());

		if (t[1] == a[i]) {
			++cnt;
		}
	}
	cout << cnt << endl;

	return 0;
}


Measured memory_bytes: 256
//Jai Bhole Ki
#include <bits/stdc++.h>
using namespace std;
#define fast static int fastline = []() { std::ios::sync_with_stdio(false); cin.tie(NULL); return 0; }();
#define ll long long
#define LL unsigned ll
#define pb push_back
#define pi pair<ll,ll>
#define debug(x) cout<<x<<"\n";
#define debug cout<<"debugged\n";
#define minval -2e9
#define maxval 2e9
long double PI =3.14159265358979323846;
 
const ll M=1e9+7;
const ll inf=1e18;
const ll ms=1e7+2;
fast;
ll ans;
ll a,b,c;
void solve()
{
   cin>>a>>b>>c;
   for(int i=0;i<10;i++)
    {
        c=c*a-b;
        cout<<c<<endl;
    }
}

int main()
{
 // freopen("input.txt","r",stdin);
//  freopen("output.txt","w",stdout);
   // int t;cin>>t;while(t--)
    {
        solve();
    }
    return 0;
}


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

int main() {
  int sx, sy, tx, ty;
  cin >> sx >> sy >> tx >> ty;
  int diff_x = tx - sx;
  int diff_y = ty - sy;
  for (int i=0 ; i<diff_y ; i++) cout << "U";
  for (int i=0 ; i<diff_x ; i++) cout << "R";
  for (int i=0 ; i<diff_y ; i++) cout << "D";
  for (int i=0 ; i<diff_x ; i++) cout << "L";

  cout << "L";
  for (int i=0 ; i<diff_y+1 ; i++) cout << "U";
  for (int i=0 ; i<diff_x+1 ; i++) cout << "R";
  cout << "D";

  cout << "R";
  for (int i=0 ; i<diff_y+1 ; i++) cout << "D";
  for (int i=0 ; i<diff_x+1 ; i++) cout << "L";
  cout << "U";

  cout << endl;
}


Measured memory_bytes: 256
import math
M, N = (int(x) for x in input().split())
def combinations_count(n, r):
  if n >= 2:
    ans = math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
  else:
    ans = 0
  return ans

print(combinations_count(M, 2) + combinations_count(N, 2))



Measured memory_bytes: 2940
N, L = gets.split.map(&:to_i)

min_abs = Float::INFINITY
min_val = 0
expected = 0
(1..N).each do |n|
  a = L+n-1
  if a.abs < min_abs
    min_abs = a.abs
    min_val = a
  end
  expected += a
end

p expected - min_val

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

int main() {
	long long a,b;
	int k;
	cin>>a>>b>>k;
	int cnt=0;
	for(int i=0;i<k;i++)
	{
		if(cnt%2==0)
		{
		if(a%2!=0)a--;
		b+=a/2;
		a=a/2;
		}
		else
	    {
	    if(b%2!=0)b--;
		a+=b/2;
		b=b/2;	
	    }
		cnt++;
	}
	cout<<a<<" "<<b<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
int main(){
    fast
    int n, k, d, tmp;
    cin >> n >> k;
    set<int> ans;
    while(k--){
        cin >> d;
        for(int i = 0; i < d; i++){
            cin >> tmp;
            ans.insert(tmp);
        }
    }
    cout << n - ans.size() << "\n";
    return 0;
}


Measured memory_bytes: 3660
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include<cassert>
#include<numeric>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
const int INF = 1001001001;
const long long LINF = 1001002003004005006ll;
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; }
typedef long long ll;
typedef pair<int,int> P;

const int MAXN = 1005;
const int MAXV = MAXN*(MAXN-1)/2;

int id[MAXN][MAXN];
int calc_v(int a,int b){
  if(a>b)swap(a,b);
  return id[a][b];
}

vector<int> to[MAXV];
vector<int> d(MAXV,-1);
vector<int> calced(MAXV,-1);
bool dag = 1;

int dfs(int v){
  if(d[v]!=-1)return d[v];
  d[v]=0;
  calced[v]=0;
  for(int u:to[v]){
    if(calced[u]==0){
      dag = 0;
      continue;
    }
    chmax(d[v],dfs(u)+1);
  }
  calced[v]=1;
  return d[v];
}

int main(){
  int n;
  cin >> n;
  vector<vector<int>> a(n,vector<int>(n-1));
  rep(i,n)rep(j,n-1){
    int t;
    cin >> t;
    t--;
    a[i][j]=t;
  }
  int v=0;
  rep(i,n)rep(j,n){
    if(i<j){
      id[i][j]=v;
      v++;
    }
  }
  rep(i,n)rep(j,n-2){
    int from = calc_v(i,a[i][j]);
    int tov = calc_v(i,a[i][j+1]);
    to[from].push_back(tov);
  }
  int ans = 0;
  rep(i,v){
    chmax(ans,dfs(i));
  }
  if(dag)cout << ans + 1 << endl;
  else cout << -1 << endl;
}

Measured memory_bytes: 39680
n, k = map(int, input().split())
r, s, p = map(int, input().split())
point = {"r": r, "s": s, "p": p}
v = {"r": "p", "s": "r", "p": "s"}
t = input()
ans = 0
for i in range(k):
    for j in range(i, n, k):
        if j == i:
            prev = v[t[j]]
            ans += point[v[t[j]]]
        else:
            if v[t[j]] != prev:
                ans += point[v[t[j]]]
                prev = v[t[j]]
            else:
                # rに勝つ手が出せない
                if t[j] == "r":
                    if j + k < n:
                        if t[j + k] == "r":
                            prev = "s"
                        elif t[j + k] == "s":
                            prev = "s"
                        else:
                            prev = "r"
                elif t[j] == "s":
                    if j + k < n:
                        if t[j + k] == "r":
                            prev = "s"
                        elif t[j + k] == "s":
                            prev = "s"
                        else:
                            prev = "p"
                elif t[j] == "p":
                    if j + k < n:
                        if t[j + k] == "r":
                            prev = "r"
                        elif t[j + k] == "s":
                            prev = "p"
                        else:
                            prev = "r"
print(ans)
# dp = [{x: 0 for x in ["r", "s", "p"]} for y in range(n + 1)]
# v = {"r": "p", "s": "r", "p": "s"}
# for i in range(1, n + 1):
#     for j in ["r", "s", "p"]:
#         now_v = v[t[i - 1]]
#         if i < k + 1:
#             if j == now_v:
#                 dp[i][j] = max(dp[i - 1].values()) + 1
#             else:
#                 dp[i][j] = max(dp[i - 1].values())
#         else:
#             if j == now_v:
#                 if now_v == "r":
#                     dp[i][j] = max(dp[i - 1][j] + dp[i - k]["s"], dp[i - 1][j] + dp[i - k]["p"])
#                 elif now_v == "s":
#                     dp[i][j] = max(dp[i - 1][j] + dp[i - k]["r"], dp[i - 1][j] + dp[i - k]["p"])
#                 elif now_v == "p":
#                     dp[i][j] = max(dp[i - 1][j] + dp[i - k]["r"], dp[i - 1][j] + dp[i - k]["s"])
# print(dp)
# for i in dp:
#     print(i)


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

using namespace std;

typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

const int MC = 100010;
int N;
int a[MC];
int ans;

int main(){
	cin >> N;
	repp(i,0,N) cin >> a[i];
	int z = 1;
	while(z*2<(int)(1e9)) z <<= 1;
	while(z>0){
		bool b = 0;
		repp(i,0,N){
			if(a[i] > z){
				if(a[i] < z*2){
					if(b){
						++ans;
					}
					b = !b;
				} else {
					b = 1;
				}
				a[i] = z;
			} else if(b){
				++ans;
				b = 0;
			}
		}
		if(b) ++ans;
		z >>= 1;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define int long long
#define mp make_pair
#define pb push_back
#define ieps (int) 1e6
#define pii pair<int,int>
vector<pii> adj[ieps];
int lca[ieps][32];
int nivel[ieps] ,  pai[ieps];
int dist[ieps];
int dfs(int x, int y , int z){
	pai[x] = y;
	nivel[x] =  z;
	for(auto v : adj[x]){
		if(v.F != y){
			dist[v.F] = dist[x] + v.S;
			dfs(v.F ,x, z + 1);
		}
	}
}
int getlca(int u , int v){
	if(nivel[u] < nivel[v]) swap(u, v);
	for(int i = 31;i>=0;i--){
		if(nivel[u] - (1LL<<i) >= nivel[v]) u = lca[u][i];
	}
	if(u == v) return u;
	for(int i = 31;i>=0;i--){
		if(lca[u][i] != lca[v][i] && lca[u][i] != -1){
			u = lca[u][i];
			v = lca[v][i];
		}
	}
	return pai[u];
}
int32_t main(){
	int n;
	cin>>n;
	for(int i = 0;i<n-1;i++){
		int x , y , z;
		cin>>x>>y>>z;
		x-- , y--;
		adj[x].pb(mp(y , z));
		adj[y].pb(mp(x , z));
	}
	dist[0] = 0;
	dfs(0 , -1 , 0);
	for(int i = 0;i<32;i++){
		for(int j = 0;j<n;j++) lca[j][i] = -1;
	}
	for(int i = 0;i<n;i++) lca[i][0] = pai[i];
	for(int i = 1;i<32;i++){
		for(int j = 0;j<n;j++){
			if(lca[j][i-1] != -1){
			lca[j][i] = lca[lca[j][i-1]][i-1];
		}
		}
	}
	int q , k;
	cin>>q>>k;
	k--;
	while(q--){
		int x  ,y;
		cin>>x>>y;
		x-- , y--;
		int lc1 = getlca(x , k );
		int lc2 = getlca(y , k );

		cout<<dist[x] + dist[k] - 2*(dist[lc1]) + dist[y] + dist[k] - 2*(dist[lc2])<<endl;
	}
}

Measured memory_bytes: 71296
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
struct edge{ll to,cost;};
const int inf = 1<<28;
const ll INF = 1LL<<53;
const int COMBMAX = 500005;
const ll MOD = 1e9+7;
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<n;++i)
#define repf(i,n) for(int i=0;i<=n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define eachdo(v, e) for(const auto& e : v)
#define all(v) (v).begin(), (v).end()
#define lower_index(v, e) (ll)distance(v.begin(), lower_bound((v).begin(), (v).end(), e))
#define upper_index(v, e) (ll)distance(v.begin(), upper_bound((v).begin(), (v).end(), e))
ll mpow(ll a, ll n,ll mod=MOD){ll res=1;while(n>0){if(n&1)res=res*a%mod;a=a*a%mod;n>>=1;}return res;}
template<class T1, class T2> ll bcount(T1 v, T2 a){return upper_index(v,a)-lower_index(v,a);} 
template<class T> bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
template<class T> void debug2(T v){rep(i,v.size()){rep(j,v[i].size())cout<<v[i][j]<<" ";cout<<endl;}}
template<class T> void rdv(T &v){rep(i,v.size())cin>>v[i];}
template<class T> void rdvv(T &v){rep(i,v.size()){rep(j,v[i].size())cin>>v[i][j];}}

int main(){
    string S;cin >> S;
    ll Q;cin >> Q;
    deque<char> q;
    rep(i,S.size()) q.push_back(S[i]);
    ll isRev = 0;
    rep(i,Q){
        ll m;cin >> m;
        if(m==1){
            isRev++;
        }else{
            ll l;cin >> l;--l;
            char c;cin >> c;
            if((isRev+l)%2==0){
                q.push_front(c);
            }else{
                q.push_back(c);
            }
        }
    }
    if (isRev%2==0){
        while(!q.empty()){
            cout << q.front();
            q.pop_front();
        }
    }else{
        while(!q.empty()){
            cout << q.back();
            q.pop_back();
        }
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
//#define DEBUG
#define REP(i, nn ) for(int i = 0 ; i < (int) nn; i++)
#define deb(x) std::cout << #x << " " << x << endl;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
template<typename... T>
void read(T& ... a){
    ((cin >> a),...);
}
template<typename... T>
void write(T... a){
    ((cout << a << "\n"),...);
}

template<typename... T>
void write_space(T... a){
    ((cout << a << " "),...);
}

void solve(){
    string s, t;
    read(s, t);
    int max_move = t.size();
    // if( s.size() == t.size()){
    //     int count = 0;
    //     for(int j = 0 ; j < t.size(); j++){
    //         count += (s[j] != t[j]);
    //     }
    //     cout << count << endl;
    //     return;
    // }
    for(int i = 0 ; i <= s.size() - t.size() ; i++){
        int count = 0;
        for(int j = 0 ; j < t.size(); j++){
            count += (s[i+j] != t[j]);
        }
        max_move = min(max_move, count);
    }
    cout << max_move << endl;
}

int main()
{
    //making data IO Fast
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    /****************************/
    solve();
    return 0;
}



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

int main(){
  int N;
  cin >> N;
  set<string> s;
  for(int i=0;i<N;i++){
    string S;
    cin >> S;
    s.insert(S);
  }
  cout << s.size() << endl;
  return 0;
}


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

int main(void){
    ll n,d;
    cin>>n>>d;
    ll c=0;
    while(n--){
        ll x,y;
        cin>>x>>y;
        if(sqrt(x*x+y*y)<=d)c++;
    }
    cout<<c<<endl;
}


Measured memory_bytes: 3620
#include <iostream>
#include <vector>
#include <string>
#include <list>
#include <queue>
#include <algorithm>
#define MOD 1000000007
#define PI 3.14159265358979323846
#define INF 1ll << 60
     
using namespace std;
typedef long long ll;
typedef pair<int, int> pp;
     
int main(void) {
    int num, i;
    ll k = 1, ans = 0;
    cin >> num;
    num++;
    vector<ll> d(num), f(num);
    for(i = 0; i < num; i++)
        cin >> d[i];
    for(i = 0; i < num; i++)
        f[i]=d[i];
    for (i = num - 2; i >= 0; i--)
        f[i] += f[i + 1];
    for(i = 0; i < num; i++) {
        if (k < d[i]) {
            ans = -1;
            break;
        }
        ans += min(k, f[i]);
        k -= d[i];
        k <<= 1;
        if (k > INF)
            k = INF;
    }
    cout << ans << "\n";
    return 0;
}

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

int main(){
  int A, B, a, b, c, d, t;
  cin >> A >> B;
  t = 0;
  for(int i = 0; i < B - A + 1; i++){
    a = (A + i) / 100;
    b = (A + i) / 100 % 10;
    c = (A + i) / 10 % 10;
    d = (A + i) % 10;
    if(a == b + 10*c + 100*d){
      t += 1;
    }
  }
  cout << t << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define N 3002
using namespace std;
typedef long long ll;
const int mod=1e9+7;
ll dp[N][N][2];
int n,m;
inline void MOD(ll &x){x=x>=mod?x-mod:x;}
inline ll rd(){
  ll x=0;char c=getchar();bool f=0;
  while(!isdigit(c)){if(c=='-')f=1;c=getchar();}
  while(isdigit(c)){x=(x<<1)+(x<<3)+(c^48);c=getchar();}
  return f?-x:x;
}
int main(){
  n=rd();m=rd();
  for(int i=1;i<=n;++i)dp[0][i][0]=1;
  dp[0][0][1]=1;
  for(int i=1;i<=m;++i){
  	for(int j=0;j<=n;++j)
  		for(int k=0;k<2;++k)if(dp[i-1][j][k]){
  		  if(j){
  		  	MOD(dp[i][j-1][k|(j==1)]+=dp[i-1][j][k]);
  		  	MOD(dp[i][j][k|(j==1)]+=dp[i-1][j][k]);
  		  }
          if(j<n){
          	MOD(dp[i][j+1][k]+=dp[i-1][j][k]);
            MOD(dp[i][j][k]+=dp[i-1][j][k]);
          }
  	    }
  }
  ll ans=0;
  for(int i=0;i<=n;++i)MOD(ans+=dp[m][i][1]);
  cout<<ans;
  return 0;
}


Measured memory_bytes: 141056
#include <bits/stdc++.h>
using namespace std;
static const int64_t INFL = 0x3F3F3F3F3F3F3F3FLL;
typedef int64_t ll;
typedef vector<ll> vll;
struct Solution {
    void solve(std::istream& in, std::ostream& out) {
        ll n;
        in >> n;
        vll a(n, INFL);
        ll ans = 0;
        for (int i = 0; i < n; i++) {
            ll t;
            in >> t;
            if (a[t - 1] == i) {
                ans++;
            }
            a[i] = t - 1;
        }
        out << ans << '\n';
    }
};
void solve(std::istream& in, std::ostream& out) {
    out << std::setprecision(12);
    Solution solution;
    solution.solve(in, out);
}
#include <fstream>
#include <iostream>
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    istream& in = cin;
    ostream& out = cout;
    solve(in, out);
    return 0;
}


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

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> v(n);
  for(int i=0; i < n; i++) cin >> v[i];
  sort(v.begin(), v.end());
  cout << v[n/2]-v[n/2-1] << endl;
}


Measured memory_bytes: 640
#coding: utf-8

N, X = (int(x) for x in input().split())
A = [int(x) for x in input().split()]

ret = 0
for i in range(N-1):
    if A[i] + A[i+1] > X:
        tmp = A[i] + A[i+1] - X
        ret += tmp
        A[i+1] -= min(A[i+1], tmp)


print(ret)



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

int main () {
  int N, C, K; cin >> N >> C >> K;
  
  vector<int>a(N);
  for (int i=0; i<N; i++) {
     cin >> a[i];
  }
  sort (a.begin(), a.end());
  
  int count =0, first = 0;
  for (int i=0; i<N;i++) {
    int diff = a[i] - a[i-first];
    first++;
    if (diff > K || first > C) {
      count++;
      first = 1;
    }
  }
  count++;
  
  cout << count << endl;
}

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

vector<int> buf;

int seeds[] = {3, 5, 7};
int N;
int size_;
int ans;
bool endflag = true;

int convert(){
    bool exist3 = false;
    bool exist5 = false;
    bool exist7 = false;
    int ret = 0;
    for(int i = 0; i < size_; ++i){
        if(buf[i] == 3) exist3 = true;
        else if(buf[i] == 5) exist5 = true;
        else if(buf[i] == 7) exist7 = true;
        else return -1;
        ret += buf[i] * pow(10, size_ - i - 1); 
    }
    if(exist3 && exist5 && exist7) return ret;
    else return -1;
}

void dfs(int i)
{
    if (i == size_) {
        int tmp = convert();
        if(tmp == -1){
            return;
        }
        else if(0 < tmp && tmp <= N){
            ++ans;
        }
        else{
            endflag = false;
            return;
        }
    }
    else{
        for(int j = 0; j < 3; ++j){
            buf[i] = seeds[j];
            dfs(i + 1);
        }
    }
}

int main(void)
{
    cin >> N; 
    buf.resize(20);
    for(int s = 3; endflag == true; ++s){
        size_ = s;
        dfs(0);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define f(i,a,b) for(register int i=a;i<=b;++i)
#define ff(i,a,b) for(register int i=a;i>=b;--i)
#define debug(x) cerr << #x << " : " << x << " " << endl
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<string, string> pss;
const ll mod = 19930726;
const int inf = 0x3f3f3f3f;
const double tiaohe = 0.57721566490153286060651209;
ll oula(ll x) { ll res = x;f(i, 2, x / i) { if (x % i == 0) { res = res / i * (i - 1);while (x % i == 0) x /= i; } }if (x > 1) res = res / x * (x - 1);return res; }
ll quickmod(ll a, ll n, ll m) { ll s = 1;while (n) { if (n & 1) { s = s * a % m; }a = (a*a) % m;n = n / 2; }return s; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
void ex_gcd(ll a, ll b, ll &x, ll &y, ll &d) { if (!b) { d = a, x = 1, y = 0; } else { ex_gcd(b, a % b, y, x, d);y -= x * (a / b); } }
ll inv(ll t, ll p) { ll d, x, y;ex_gcd(t, p, x, y, d);return d == 1 ? (x % p + p) % p : -1; }
bool isPrime(ll x) { if (x == 2)return true;if (x % 2 == 0)return false;for (ll i = 2;i*i <= x;i++) if (x % i == 0)return false; return true; }
inline int in() { char ch = getchar();int x = 0, f = 1;while (ch<'0' || ch>'9') { if (ch == '-')f = -1;ch = getchar(); }while (ch >= '0'&&ch <= '9') { x = x * 10 + ch - '0';ch = getchar(); }return x * f; }
//double a = log(n) +tiaohe + 1.0 / (2 * n);
double eqa = (1 + sqrt(5.0)) / 2.0;
const int N = 6e5 + 4;

int main()
{
	//freopen("in.txt", "r", stdin);
	double a, b, c;
	while (cin >> a >> b >> c)
	{
		if (a / c <= b)puts("Yes");
		else puts("No");
	}
	return 0;
}

Measured memory_bytes: 3716
#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i = ((ll) a); i < ((ll) n); i++)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;

int main(void) {
  ll N;
  cin >> N;
  vector<string> S(N);
  REP(i, 0, N) cin >> S[i];

  vector<pll> left, right;
  REP(i, 0, N) {
    ll bottom = 0, level = 0;
    REP(j, 0, S[i].size()) {
      if(S[i][j] == '(') level++;
      if(S[i][j] == ')') level--;
      bottom = min(bottom, level);
    }
    if(level >= 0) left.push_back(pll(level, bottom));
    else {
      ll bottom = 0, level = 0;
      for(ll j = S[i].size() - 1; j >= 0; j--) {
        if(S[i][j] == ')') level++;
        if(S[i][j] == '(') level--;
        bottom = min(bottom, level);
      }
      right.push_back(pll(level, bottom));
    }
  }

  ll lh = 0, rh = 0;
  vector<bool> lused(left.size(), false), rused(right.size(), false);

  ll sum = 0;
  REP(i, 0, left.size()) sum += left[i].first;
  REP(i, 0, right.size()) sum -= right[i].first;
  if(sum != 0) goto NO;

  REP(i, 0, left.size()) {
    ll t = -1;
    REP(j, 0, left.size()) if(!lused[j] && lh + left[j].second >= 0) t = j;
    if(t == -1) goto NO;
    lh += left[t].first;
    lused[t] = true;
  }

  REP(i, 0, right.size()) {
    ll t = -1;
    REP(j, 0, right.size()) if(!rused[j] && rh + right[j].second >= 0) t = j;
    if(t == -1) goto NO;
    rh += right[t].first;
    rused[t] = true;
  }

  cout << "Yes" << endl;
  return 0;
NO:
  cout << "No" << endl;
}



Measured memory_bytes: 3228
// ABC 147-D
// 2019.12.23 bal4u

#include <stdio.h>
#include <ctype.h>

typedef long long ll;

#define gc() getchar_unlocked()

ll in() {   // 非負整数の入力
	ll n = 0; int c;
	do c = gc();
	while (isspace(c));
	do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0');
	return n;
}

#define M 1000000007
int N;
ll A[300005];

int main()
{
	int i, n, b;
	ll ans, a;
	
	N = (int)in();
	for (i = 0; i < N; ++i) A[i] = in();

	ans = 0;
	b = 61; while (b--) {
		n = 0;
		i = N; while (i--) {
			if ((A[i] >> b) & 1) ++n;
		}
		ans = (ans + (1LL << b) % M * ((ll)n*(N-n) % M) % M) % M;
	}
	printf("%d\n", (int)ans);
	return 0;
}


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

#define REP(i, start, count) for (int i = (start); i < (int)(count); ++i)
#define rep(i, count) REP(i, 0, count)
#define ALLOF(c) (c).begin(), (c).end()

typedef long long ll;
typedef unsigned long long ull;

int N;

int main(void)
{
    cin >> N;
    vector<int> a(N);
    rep(i, N) {
        cin >> a[i];
    }

    sort(ALLOF(a));

    ll ans = 0;
    rep(i, N) {
        ans += a[i] - 1;
    }

    cout << ans << endl;
    

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for((i)=1;(i)<=(n);(i)++) 
using namespace std;
int n,i,j,a[1000005],b[1000005],s,c1;
int c(int x,int y){
	if(x<y) return 0;
	if(x<=1&&y<=1) return 1;
	return c(x/2,y/2)*c(x%2,y%2);
}
int main(){
	scanf("%d ",&n); 
	rep(i,n){
		char c;
		scanf("%c",&c);
		a[i]=c-48;
	}
	if(n==1){
		cout<<a[1]<<endl;
		return 0;
	}
	rep(i,n-1){
		b[i]=abs(a[i+1]-a[i]);
		if(b[i]==1) c1=1;
	}
	if(c1){
		rep(i,n-1){
			if(c(n-2,i-1)) s^=(b[i]&1);
		}
	}
	else{
		rep(i,n-1){
			if(c(n-2,i-1)) s^=b[i];
		}
	}
	cout<<s<<endl;
	return 0;
}

Measured memory_bytes: 8064
import bisect

# 入力
def read_data():
    N_ = int(input())
    L_ = list(map(int, input().split()))
    return N_, L_

# 探索
def Search(N, L):
    ans = 0
    L.sort()
   # a, b は固定する
    for a_index in range(N):
       for b_index in range(a_index + 1, N):
           sum_of_a_and_b = L[a_index] + L[b_index]
           # c の可動範囲の右端を求める
           c_right_id = bisect.bisect_left(L, sum_of_a_and_b)
           # c の可動範囲は[b_index + 1, c_right)
           ans += max(0, c_right_id - b_index - 1)
    print(ans)

N, L = read_data()
Search(N, L)

Measured memory_bytes: 42716
#pragma GCC target("avx2")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#include<bits/stdc++.h>

#define f			first
#define sz(a)       ((int)(a).size())
#define s			second
#define all(v)		v.begin(),v.end()
#define pii 		pair<int,int>
#define vpii 		vector<pii>
#define eb			emplace_back
#define pb			push_back
#define fo(i,n)		for(int i=0;i<n;i++)
#define Fo(i,k,n)	for(int i=k;i<n;i++)
#define vi			vector<ll>
#define deb(x)		cout << #x << " " << x << endl

using namespace std;
using ll  = long long;
using lld = long double;

const int oo = 0x3f3f3f3f;
const ll MOD = 1000000007;

inline void relax(ll & a , ll b){
    a = min(a , b);
    return;
}

signed main(){

#ifndef ONLINE_JUDGE
//	freopen("in.txt" , "r" , stdin);
#endif
	ios_base::sync_with_stdio(0);cin.tie(0);

    int n , k;
    cin >> n >> k;
    
    vi h(n) , dp(n , oo);

    fo(i , n) cin >> h[i];

    dp[0] = 0;
    fo(i , n){
        for(int j = 1 ; j <= k && i + j < n ; j++)
            relax(dp[i + j] , dp[i] + abs(h[j + i] - h[i]));
    }
    
    cout << dp[n - 1] << '\n';
     

    return 0;

}



Measured memory_bytes: 4740
a, v = map(int, input().split())
b, w = map(int, input().split())
t = int(input())
if a >= b:
    if v <= w:
        print("NO")
    else:
        print("YES" if abs(v-w)*t >= abs(a-b) else "NO")
else:
    if v <= w:
        print("NO")
    else:
        print("YES" if abs(v-w)*t >= abs(a-b) else "NO")

Measured memory_bytes: 61840
#!/usr/bin/env pypy3
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    A=[[] for _ in range(3)]
    for i in range(3):
        A[i]=LI()
    N=I()
    for _ in range(N):
        b=I()
        for i in range(3):
            for j in range(3):
                if A[i][j]==b:
                    A[i][j]=0
                    
    f=0
                
    for i in range(3):
        a=0
        for j in range(3):
            a+=A[i][j]
        if a==0:
            f=1
            
    for j in range(3):
        a=0
        for i in range(3):
            a+=A[i][j]
        if a==0:
            f=1
    a=0        
    for i in range(3):
        a+=A[i][i]
    if a==0:
        f=1
            
    a=A[2][0]+A[1][1]+A[0][2]
    if a==0:
        f=1
        
    if f==1:
        print("Yes")
    else:
        print("No")
            
    
        
        
            
        
                
        
    

main()


Measured memory_bytes: 38256
main :: IO ()
main = do ls <- getContents
          putStr (compose ls)

compose :: String -> String
compose = unlines . swapStr . fmap ((\[x,y] -> (x,y)) . take 2 . words) . lines

swapStr :: [(String, String)] -> [String]
swapStr [] = []
swapStr ((m, n):xs) | m == "0" && n == "0" = []
                    | (read m :: Int) > (read n :: Int) = (n ++ " " ++ m) : swapStr xs
                    | otherwise = (m ++ " " ++ n) : swapStr xs

Measured memory_bytes: 4484
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll, ll>;
#define rep(i, n)  for (int i = 0; i <  (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(x) (x).begin(), (x).end()
const ll INF = ll(1e18)+1;

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

    ll X;
    cin >> X;
    ll result = 0;
    ll zandaka = 100;

    while(zandaka<X){
        zandaka *= 1.01;
        result++;
    }

    cout << result;
}

Measured memory_bytes: 3652
# Template 1.0
import sys, re
from collections import deque, defaultdict, Counter, OrderedDict
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from heapq import heappush, heappop, heapify, nlargest, nsmallest
def STR(): return list(input())
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def list2d(a, b, c): return [[c] * b for i in range(a)]
def sortListWithIndex(listOfTuples, idx):   return (sorted(listOfTuples, key=lambda x: x[idx]))
def sortDictWithVal(passedDic):
    temp = sorted(passedDic.items(), key=lambda kv: (kv[1], kv[0]))
    toret = {}
    for tup in temp:
        toret[tup[0]] = tup[1]
    return toret
def sortDictWithKey(passedDic):
    return dict(OrderedDict(sorted(passedDic.items())))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

a,b,h,m = MAP()

angle = 5.5*m - h*30

if(angle<0):
    angle+=360
# print(angle)
angle*=(pi/180)
c = sqrt(a*a + b*b - 2*a*b*cos(angle))
print(c)

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

public class Main {
	public static void main(String[] args) throws IOException {
		int[] data = new int[10];
		final String BR = System.getProperty("line.separator");
		int first = 0, second = 0, third = 0;
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		for (int i = 0; i < 10; i++) {
			data[i] = Integer.parseInt(in.readLine());
		}
		for (int datum : data) {
			int temp1 = 0, temp2 = 0;
			if (first < datum) {
				temp1 = first;
				temp2 = second;
				first = datum;
				second = temp1;
				third = temp2;
			} else if (second < datum) {
				temp2 = second;
				second = datum;
				third = temp2;
			} else if (third < datum) {
				third = datum;
			}
		}

		System.out.println(first + BR + second + BR + third);
	}
}

Measured memory_bytes: 24136
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vl = vector<ll>;
using pii = pair<int, int>;
using vpii = vector<pair<int, int>>;
template<typename T>
using pque = priority_queue<T, vector<T>, greater<T>>;
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define ALL(a) (a).begin(), (a).end()
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

constexpr int N = 524288;
class BIT {
public:
	int a[N] = {};
	
	void add(int x, int y){
		while(x < N){
			a[x] += y;
			x += x&-x;
		}
	}
	
	int sum(int x){ //inclusive, 1-indexed
		int ret = 0;
		while(x > 0){
			ret += a[x];
			x -= x&-x;
		}
		return ret;
	}
} b[32];
char s[N];
void ad(int i, int y){
	b[s[i]-'a'].add(i, y);
}

int main(){
	int n; scanf("%d%s", &n, s+1);
	FOR(i, 1, n+1) ad(i, 1);
	int q; scanf("%d", &q);
	REP(i, q){
		int x; scanf("%d", &x);
		if(x == 1){
			int y; char z[2]; scanf("%d%s", &y, z);
			ad(y, -1);
			s[y] = *z;
			ad(y, 1);
		} else {
			int p, q; scanf("%d%d", &p, &q);
			int ans = 0;
			REP(i, 26){
				if(b[i].sum(q) - b[i].sum(p-1) > 0) ans++;
			}
			printf("%d\n", ans);
		}
	}
}


Measured memory_bytes: 55552
#include "bits/stdc++.h"
#define int long long
#define endl '\n'
using namespace std;
 
typedef long long ll;
typedef long double ld;
#define db(x) cerr << #x << ": " << x << '\n';
#define read(a) int a; cin >> a;
#define reads(s) string s; cin >> s;
#define readb(a, b) int a, b; cin >> a >> b;
#define readc(a, b, c) int a, b, c; cin >> a >> b >> c;
#define readarr(a, n) int a[(n) + 1] = {}; FOR(i, 1, (n)) {cin >> a[i];}
#define readmat(a, n, m) int a[n + 1][m + 1] = {}; FOR(i, 1, n) {FOR(j, 1, m) cin >> a[i][j];}

#define print(a) cout << a << endl;
#define printarr(a, n) FOR (i, 1, n) cout << a[i] << " "; cout << endl;
#define printv(v) for (int i: v) cout << i << " "; cout << endl;
#define printmat(a, n, m) FOR (i, 1, n) {FOR (j, 1, m) cout << a[i][j] << " "; cout << endl;}
#define all(v) v.begin(), v.end()
#define sz(v) (int)(v.size())
#define rz(v, n) v.resize((n) + 1);
#define pb push_back
#define fi first
#define se second
#define vi vector <int>
#define pi pair <int, int>
#define vpi vector <pi>
#define vvi vector <vi>
#define setprec cout << fixed << showpoint << setprecision(20);
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
const ll inf = 1e18;
const ll mod = 1e9 + 7;
const ll N = 2e5 + 1;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	readb(x, n);
	readarr(a, n);
	
	int f[105] = {};
	FOR (i, 1, n) f[a[i]] = 1;
	
	int ans = 0, mn = x;
	FOR (i, 1, 101)
	{
	    if (f[i]) continue;
	    else if (abs(x - i) < mn) ans = i, mn = abs(x - i);
	}
	
	cout << ans;
}



















Measured memory_bytes: 3656
s=input()
q_=int(input())
q=[input() for _ in range(q_)]
reverse=False
pre=[]
fin=[]
for qi in q:
    if qi[0]=='1':
        reverse=not reverse
    elif qi[2]=='1' and reverse==False:
        pre.append(qi[4])
    elif qi[2]=='1' and reverse==True:
        fin.append(qi[4])
    elif qi[2]=='2' and reverse==False:
        fin.append(qi[4])
    elif qi[2]=='2' and reverse==True:
        pre.append(qi[4])
if reverse==False:
    print(''.join([p for p in pre[::-1]])+s+''.join(fin))
else:
    print(''.join([f for f in fin[::-1]])+''.join([si for si in list(s)[::-1]])+''.join(pre))

Measured memory_bytes: 96344
import numpy as np
import itertools
H, W, K = [int(x) for x in input().split(" ")]

a = np.zeros((H, W), dtype=bool)
for i in range(H):
    a[i, [x == "#" for x in input()]] = True

c = [[True, False]] * (H + W)
count = 0
for i in itertools.product(*c):
    h = i[:H]
    w = i[H:]
    ap = np.copy(a)
    ap[h, :] = False
    ap[:, w] = False
    if ap.sum() == K:
        count += 1
print(count)

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

typedef struct Dice {
	int status[7];
} DICE;

void rotation(DICE *dice, char command) {
	int tmp;
	switch(command) {
	case 'S':
		tmp = dice->status[1];
		dice->status[1] = dice->status[5];
		dice->status[5] = dice->status[6];
		dice->status[6] = dice->status[2];
		dice->status[2] = tmp;
		break;
	case 'N':
		tmp = dice->status[1];
		dice->status[1] = dice->status[2];
		dice->status[2] = dice->status[6];
		dice->status[6] = dice->status[5];
		dice->status[5] = tmp;
		break;
	case 'W':
		tmp = dice->status[1];
		dice->status[1] = dice->status[3];
		dice->status[3] = dice->status[6];
		dice->status[6] = dice->status[4];
		dice->status[4] = tmp;
		break;
	case 'E':
		tmp = dice->status[1];
		dice->status[1] = dice->status[4];
		dice->status[4] = dice->status[6];
		dice->status[6] = dice->status[3];
		dice->status[3] = tmp;
		break;
	default:
		break;
	}
	return;
}

int main(void) {
	DICE dice;
	char commands[101];
	int i,tmp;
	
	for (i = 1; i < 7; ++i) {
		scanf("%d", &tmp);
		dice.status[i] = tmp;
	}

	scanf("%s", commands);
	
	for(i = 0; i < strlen(commands); ++i) {
		rotation(&dice, commands[i]);
	}
	printf("%d\n",dice.status[1]);
		
	return 0;
}

Measured memory_bytes: 596
/**
  @date Time-stamp: <2019-05-19 10:53:21 tagashira>
  @file c.cpp
  @title C - GeT AC
  @brief https://atcoder.jp/contests/abc122/tasks/abc122_c
**/

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <sstream> // std::ostringstream
#include <string>
#include <vector>

using namespace std;

int main(int argc, char* argv[]) {
  unsigned int i;

  unsigned long int N, Q;
  cin >> N >> Q;
  string S;
  cin >> S;

  vector<int> l, r;
  unsigned long int tmpL, tmpR;
  for (i = 0; i < Q; i++) {
    cin >> tmpL >> tmpR;
    l.push_back(tmpL);
    r.push_back(tmpR);
  }

  //index:  0 1 2 3 4 5 6 7
  //string: A C A C T A C G
  //memo:  0 0 1 1 2 2 2 3 4 // Cumulative sum
  //index: 0 1 2 3 4 5 6 7 8

  vector<int> sum(N + 1, 0);
  for (i = 1; i < N + 1; i++) {
    sum[i + 1] = sum[i];
    if (S[i - 1] == 'A' && S[i] == 'C') sum[i + 1]++;
  }

  // for debug
  // for (i = 0; i < N + 1; i++) {
  //   cout << sum[i] << " ";
  // }
  // cout << "\n";

  for (i = 0; i < Q; i++) {
    cout << sum[r[i]] - sum[l[i]] << endl;
  }

  return 0;
}


Measured memory_bytes: 2420
#include<algorithm>
#include<iostream>
#include<cstring>
#include<iomanip>
#include<sstream>
#include<cstdio>
#include<string>
#include<vector>
#include<bitset>
#include<queue>
#include<cmath>
#include<stack>
#include<set>
#include<map>
#define rep(i,x,n) for(int i=x;i<=n;i++)
#define per(i,n,x) for(int i=n;i>=x;i--)
#define sz(a) int(a.size())
#define rson mid+1,r,p<<1|1
#define pii pair<int,int>
#define lson l,mid,p<<1
#define ll long long
#define pb push_back
#define mp make_pair
#define se second
#define fi first
using namespace std;
const double eps=1e-8;
const int mod=1e9+7;
const int N=1e5+10;
const int inf=1e9;
ll a,b,c;
int main(){
	//ios::sync_with_stdio(false);
	//freopen("in","r",stdin);
	scanf("%lld %lld.%lld",&a,&b,&c);
	c=b*100+c;
	a=a*c/100;
	printf("%lld\n",a);
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<ll, ll> P;
typedef vector<int> vi;
typedef vector<vi> vvi;

#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REPR(i, n) for (ll i = (n) - 1; i >= 0; --i)
#define FOR(i, n, m) for (ll i = (n); i < (m); ++i)
#define FORR(i, n, m) for (ll i = (m) - 1; i >= (n); --i) 
#define FORE(x, xs) for (auto &x: (xs))
#define ALL(v) v.begin(), v.end()
#define ZERO(a) memset(a,0,sizeof(a))

const int INF = 1000000009;
const int MOD = 1000000007;
const double EPS = 1e-14;
const double PI = acos(-1);

const int MAX = 1e5;
int N, A, B, p;

int main() {

    cin >> N >> A >> B;
    int c1 = 0, c2 = 0, c3 = 0;
    REP (i, N) {
        cin >> p;
        if (p <= A) c1++;
        else if (p <= B) c2++;
        else c3++;
    }
    cout << min(c1, min(c2, c3)) << endl;
}


Measured memory_bytes: 256
N, M = map(int, input().split())
A = [list(input()) for _ in range(N)]
B = [list(input()) for _ in range(M)]

def check(x, y):
    for i in range(M):
        for j in range(M):
            if A[x + i][y + j] == B[i][j]:
                continue
            else:
                return False
    return True
if A == B:
    print("Yes")
    exit()
for x in range(N - M):
    for y in range(N - M):
        if check(x, y):
            print("Yes")
            exit()
print("No")


Measured memory_bytes: 3064
#include <stdio.h>
#include <memory.h>
#include <algorithm>
#include <vector>
#include <iostream>
#include <string>
#include <set>
#include <map>

using ii = std::pair<int, int>;

int main()
{
	int x, k;
	scanf("%d %d", &x, &k);

	std::vector<int> r(k);

	for (int i = 0; i < k; i++)
		scanf("%d", &r[i]);

	int q;
	scanf("%d", &q);
	int maxVal = x;
	int minVal = 0;
	int maxLine = x;
	int minLine = 0;
	int ridx = 0;
	int prevt = 0;

	for (int i = 0; i < q; i++)
	{
		int t, a;
		scanf("%d %d", &t, &a);

		while (ridx < r.size() && r[ridx] <= t)
		{
			//꺾이는 거 처리
			if (ridx % 2 == 0)
			{
				maxVal -= r[ridx] - prevt;

				if (maxVal < 0)
				{
					maxLine += maxVal;
					maxVal = 0;
				}

				minVal -= r[ridx] - prevt;

				if (minVal < 0)
				{
					minLine -= minVal;
					minVal = 0;
				}
			}
			else
			{
				maxVal += r[ridx] - prevt;

				if (maxVal > x)
				{
					maxLine -= maxVal - x;
					maxVal = x;
				}

				minVal += r[ridx] - prevt;

				if (minVal > x)
				{
					minLine += minVal - x;
					minVal = x;
				}
			}

			prevt = r[ridx];
			ridx++;
		}

		//꺾은 다음 t까지 진행하는 거 처리
		if (ridx % 2 == 0)
		{
			maxVal -= t - prevt;

			if (maxVal < 0)
			{
				maxLine += maxVal;
				maxVal = 0;
			}

			minVal -= t - prevt;

			if (minVal < 0)
			{
				minLine -= minVal;
				minVal = 0;
			}
		}
		else
		{
			maxVal += t - prevt;

			if (maxVal > x)
			{
				maxLine -= maxVal - x;
				maxVal = x;
			}

			minVal += t - prevt;

			if (minVal > x)
			{
				minLine += minVal - x;
				minVal = x;
			}
		}

		if (maxLine <= minLine || a >= maxLine)
			printf("%d\n", maxVal);
		else if (a <= minLine)
			printf("%d\n", minVal);
		else
			printf("%d\n", maxVal - (maxLine - a));

		prevt = t;
	}

	return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define show(x) cerr << #x << " = " << x << endl
using namespace std;
using ll = long long;
using ld = long double;
constexpr ll MOD = 1000000007LL;
template <typename T>
constexpr T INF = numeric_limits<T>::max() / 10;
template <typename Functor>
struct fix_type
{
    Functor functor;
    template <typename... Args>
    decltype(auto) operator()(Args&&... args) const& { return functor(functor, std::forward<Args>(args)...); }
};
template <typename Functor>
fix_type<typename std::decay<Functor>::type> fix(Functor&& functor) { return {std::forward<Functor>(functor)}; }

int main()
{
    int N;
    cin >> N;
    vector<ll> a(N);
    for (int i = 0; i < N; i++) {
        cin >> a[i];
        a[i] *= 2;
    }
    sort(a.begin(), a.end());
    pair<ll, ll> maxi = {0, 0};
    for (int i = 1; i < N; i++) {
        const ll v = a[i] / 2;
        const int l = lower_bound(a.begin(), a.end(), v) - a.begin();
        ll cand = -1;
        if (l < i) {
            if (abs(v - cand) > abs(v - a[l])) {
                cand = a[l];
            }
        }
        if (l != 0) {
            if (abs(v - cand) > abs(v - a[l - 1])) {
                cand = a[l - 1];
            }
        }
        if (cand != -1) {
            maxi = max(maxi, {a[i], cand});
        }
    }
    cout << maxi.first / 2 << " " << maxi.second / 2 << endl;
    return 0;
}


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

using namespace std;
typedef long long int ll;

#define PI (acos(-1))
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))


vector <ll> nums;
ll n;
ll d = 1e9 + 7;

int rec(int s) {
    if (nums[s] >= 0){
        return nums[s];
    }
    if (s > n){
        return 0;
    }
    if (s == n){
        return 1;
    }
    ll num = (rec(s+1) + rec(s+2)) % d;
    nums[s] = num;
    return num;
}



int main(void){
    cin >> n;
    REP(i, n+1){
        nums.push_back(-1);
    }
    ll m; cin >> m;
    ll a;
    REP(i, m){
        cin >> a;
        nums[a] = 0;
    }
    cout << rec(0) << endl;
    return 0;
}

Measured memory_bytes: 4340
import java.util.*;

public class Main {
	public static void main(String[] args) throws Exception{
		Scanner scn = new Scanner(System.in);
		int h1 = scn.nextInt();
		int m1 = scn.nextInt();
      int h2 = scn.nextInt();
      int m2 = scn.nextInt();
      int k = scn.nextInt();
      int hh = 0;
      int mm = 0;
      int kh = k / 60;
      int km = k % 60;
      if(km<=m2){
        hh = h2 - kh;
        mm = m2 - km;
      }else{
        hh = h2 - 1 - kh;
        mm = m2 + 60 - km;
      }
      int hhh = hh - h1;
      int mmm = mm - m1;
      int ans = hhh * 60 + mmm;
      System.out.println(ans);
	}
}

Measured memory_bytes: 35672
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repab(i, a, b) for(int i = a; i < b; ++i)
#define rrep(i, n) for(int i = n-1; i >= 0; --i)
typedef unsigned long long ll;

ll mod = 1000000007;

int main(){
  	ll n; cin>>n;
  	ll count = 0;
  	ll *arr = new ll[n];
  	ll *dig = new ll[n];
  	ll mu = 1;
  	ll cum = 0;
  	ll oz[2] = {};
  	rep(i, n){
    	cin>>arr[i];
      	dig[i] = 0;
    }
  	rep(idx, 64){
      	cum = 0;
      	oz[0] = 0;
      	oz[1] = 0;
    	rep(i, n){
          dig[i] = arr[i] % 2;
          arr[i] >>= 1;
        }
      	oz[dig[0]] = 1;
      	repab(i, 1, n){
        	cum += oz[dig[i]?0:1];
          	oz[dig[i]] += 1;
        }
        count += ((cum% mod) * (mu % mod))% mod ;
      	mu *= 2;
      	count %= mod;        
    }
  	cout<<count;
	return 0;
}


Measured memory_bytes: 4992
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#define inf 0x7f7f7f7f
using namespace std;
typedef long long ll;
#define maxn 5000010

void read(int &x) {
  int f = 1;
  x = 0;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  x *= f;
}
struct node {
  int to;
  int nxt;
} edge[maxn];
int tot, head[maxn], maxx, vis[maxn], ans, cnt;
void add(int x, int y) {
  edge[cnt].to = y;
  edge[cnt].nxt = head[x];
  head[x] = cnt++;
}
void dfs(int now, int fa, int stp) {
  tot++;
  if (stp == 0) return;
  for (int i = head[now]; ~i; i = edge[i].nxt) {
    if (edge[i].to == fa) {
      continue;
    }
    dfs(edge[i].to, now, stp - 1);
  }
}
int n, k;
int main() {
  read(n), read(k);
  int u, v, del;
  for (int i = 0; i <= n; i++) head[i] = -1;
  for (int i = 0; i < n - 1; i++) {
    read(u), read(v);
    add(u, v);
    add(v, u);
  }
  ans = 0;
  if (k % 2 == 0) {  // k为偶数，枚举点，跑k/2的边
    for (int i = 1; i <= n; i++) {
      tot = 0;
      dfs(i, 0, k / 2);
      ans = max(tot, ans);
    }
  } else {  // k为奇数，枚举边，跑k/2的点
    for (u = 1; u <= n; u++) {
      for (int j = head[u]; ~j; j = edge[j].nxt) {
        tot = 0;
        int t = edge[j].to;
        dfs(t, u, k / 2);
        dfs(u, t, k / 2);
        ans = max(tot, ans);
      }
    }
  }
  cout << n - ans << endl;
}


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

int main(int argc, char const *argv[])
{
	
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int a,b,c;
	cin>>a>>b>>c;

	if(a+b+c >= 22) cout<<"bust"<<endl;
	else cout<<"win"<<endl;


	return 0;
}

Measured memory_bytes: 256
#include <string>
#include <vector>
#include <map>
#include <list>
#include <iterator>
#include <set>
#include <queue>
#include <iostream>
#include <sstream>
#include <stack>
#include <deque>
#include <cmath>
#include <memory.h>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <algorithm>
#include <utility>
#include <time.h>
#include <bitset>
#include <assert.h>
#include <complex.h>
using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define FILL(A,val) memset(A,val,sizeof(A))

#define ALL(V) V.begin(),V.end()
#define SZ(V) (int)V.size()
#define PB push_back
#define MP make_pair

typedef long long Int;
typedef unsigned long long UInt;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double Pi = acos(-1.0);
const int INF = 1000000000;
const Int INF2 = Int(INF) * 5000;
const Int INF3 = Int(INF) * INF;
const int MAX = 100007;
const int MAXE = 2007000;
const int MAXV = 5000;
const int BASE = 1000000000;
const int ST = 1000000007;

const int MOD = 1000000007;

int p = 1000003;

int main()
{
//    freopen("in.txt", "r", stdin);
//    freopen("out.txt" , "w", stdout);

    int n;
    cin >> n;
    string s;
    cin >> s;
    string t = s.substr(n,n);
    s = s.substr(0,n);
    reverse(ALL(t));

    map<pair<Int, Int>, int > M;


    FOR(mask,0,1 << n)
    {
        Int h1 = 0;
        Int h2 = 0;
        FOR(i,0,n)
        {
            if (mask & (1 << i))
            {
                h1 = h1 * p + s[i];
            }
            else
            {
                h2 = h2 * p + s[i];
            }
        }
        M[MP(h1 , h2)] ++;
    }

    Int res = 0;
    FOR(mask,0,1 << n)
    {
        Int h1 = 0;
        Int h2 = 0;
        FOR(i,0,n)
        {
            if (mask & (1 << i))
            {
                h1 = h1 * p + t[i];
            }
            else
            {
                h2 = h2 * p + t[i];
            }
        }
        res += M[MP(h1 , h2)];
    }

    cout << res << endl;



}

Measured memory_bytes: 33024
n,k = map(int, input().split())
x = list(map(int, input().split()))
minus = [0]
plus = [0]
for i in x:
    if x:
        plus.append(x)
    else:
        minus.append(-x)
k -= 1
ans = 1000000000000000
for i in range(n-k):
    if x[i+k] < 0:
        ans = min(ans, -x[i])
    elif 0 < x[i+k] and x[i] < 0:
        if -x[i] < x[i+k]:
            ans = min(ans, abs(2*(x[i])) + x[i+k])
        else:
            ans = min(ans, 2*x[i+k] + abs(x[i]))
    else:
        ans = min(ans, x[i+k])
    
print(ans)

Measured memory_bytes: 20288