akhauriyash/Code-Regression huggingface dataset:
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "


// CHECK THE LIMITS
typedef long long ll;

const int MOD = 1000000007;
const ll INFLL = 1e18;
const int INF = 1e9;
const int NMAX = 1000001;

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

int TT[NMAX];
int sz[NMAX];

int find(int x)
{
	if(x != TT[x])
	{
		TT[x] = find(TT[x]);
	}
	return TT[x];
}

void unite(int node1, int node2)
{
	int parent1 = find(node1);
	int parent2 = find(node2);

	if(parent1 == parent2)
		return;

	TT[parent2] = parent1;

	sz[parent1]+=sz[parent2];
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
	int n,m,k;
	cin >> n >> m >> k;

	vector<int> sol(n);
	vector<int> A(m),B(m),C(k),D(k);
	// Initialise

	for(int i= 0; i< n; ++i)
	{
		TT[i] = i;
		sz[i] = 1;
	}

	for(int i =0; i< m; ++i)
	{
		cin >> A[i]>> B[i];
		A[i]--;B[i]--;

		unite(A[i],B[i]);
	}

	for(int i =0; i< k; ++i)
	{
		cin >> C[i] >> D[i];
		C[i]--;D[i]--;
	}

	for(int i = 0; i< n; ++i)
	{
		sol[i] = sz[find(i)] - 1;
	}

	for(int i =0; i < m; ++i)
	{
		sol[A[i]]--;
		sol[B[i]]--;
	}

	for(int i =0; i< k; ++i)
	{
		if(find(C[i]) == find(D[i]))
		{
			sol[C[i]]--;
			sol[D[i]]--;
		}
	}

	for(int i=0; i < n; ++i)
	{
		cout << sol[i] << " ";
	}


	cout << '\n';


    return 0;
}

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

int main(){
  int A,B,H,W;
  cin>>A>>B>>H>>W;
  double N=max((H*30-W*5.5),360-(H*30-W*5.5))*3.14159265358979*2/360;
  cout<<setprecision(16)<<pow(pow(sin(N)*A,2)+pow(B-cos(N)*A,2),0.5)<<endl;
}

Measured memory_bytes: 4236
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define EPS (1e-7)
#define INF (1e9)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
const double PI = acos(-1);
const ll MOD = 1000000007;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
 
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
///////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N; cin >> N;
    vector<int> a(N);
    rep(i,N) cin >> a[i];

    int I = count(all(a),1);
    int J = count(all(a),2);
    int K = count(all(a),3);
    vector<vector<vector<double>>> dp(I+J+K+1, vector<vector<double>>(I+J+K+1, vector<double>(I+J+K+1,0.0)));
    rep(k,K+1) {
        rep(j,J+K+1) {
            rep(i,I+J+K+1) {
                if (i == 0 && j == 0 && k == 0) continue;
                if (i + j + k > N) continue;
                dp[i][j][k] = double(N - i - j - k);
                if (i > 0) {
                    dp[i][j][k] += double(i)*(dp[i-1][j][k] + 1.0);
                }
                if (j > 0) {
                    dp[i][j][k] += double(j)*(dp[i+1][j-1][k] + 1.0);
                }
                if (k > 0) {
                    dp[i][j][k] += double(k)*(dp[i][j+1][k-1] + 1.0);
                }
                dp[i][j][k] /= double(i+j+k);
            }
        }
    }

    cout << fixed << setprecision(10) << dp[I][J][K] << endl;
}


Measured memory_bytes: 216832
N = int(input())
A = list(map(int, input().split()))
ans = 0
A = sorted(A)

for i in range(N):
    r = i+1
    for j in range(i):
        t = A[i] + A[j]
        while r < N and A[r] < t:
            r += 1
        l = i+1
        ans += max(0, r-l)
print(ans)

Measured memory_bytes: 3316
// I can't tell you what it really is,
// I can only tell you what it feels like.
#include "bits/stdc++.h"
using namespace std;
 
#define int long long
#define F first
#define S second
#define sz(x) ((int)x.size())
#define rep(i,a,n) for (int i = a; i <= n; ++i)
#define all(v)  v.begin(), v.end()
#define pb push_back
#define P pair < int, int >
#define E cout << '\n'

#ifdef LOCAL
#define cerr cout
#else
#endif
 
#define TRACE
 
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

const int mod = 1e9 + 7;
const int N = 4e5 + 5;

int a[N];
 
inline void solve() {
 string s;
 cin >> s;
 int i = 0, j = sz(s) - 1, x = 0;
 while (i < j) {
   if (s[i] != s[j])++x;
   ++i,--j;
 }
 cout << x;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL); 
  //int t = 1;cin >> t; while(t--)
  solve();
  E;
  return 0;
}

Measured memory_bytes: 256
w,h,n=map(int,input().split())
answ=set(range(w+1)) 
ansh=set(range(w+1))
for i in range(n):
  x,y,a=map(int,input().split())
  if a==1:
    answ=answ & set(range(x,w+1))
  elif a==2:
    answ=answ & set(range(x+1))
  elif a==3:
    ansh=ansh & set(range(y,h+1))
  elif a==4:
    ansh=ansh & set(range(y+1))
if len(answ) == 0 or len(ansh)==0:
  print(0)
else:
  print((max(answ)-min(answ))*(max(ansh)-min(ansh)))

Measured memory_bytes: 9240
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

int main() {
  int64 W, H, x, y;
  cin >> W >> H >> x >> y;
  double ret = 0.5 * W * H;
  int p = 0;
  if (x * 2 == W && y * 2 == H) p = 1;
  cout << ret << " " << p << endl;
  return 0;
}


Measured memory_bytes: 256
W, H, N = map(int, input().split())
xl, yl = 0, 0
xr, yr = W, H
for i in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        if x > xl:
            xl = x
    elif a == 2:
        if x < xr:
            xr = x
    elif a == 3:
        if y > yl:
            yl = y
    else:
        if y < yr:
            yr = y
    if xl >= xr or yl >= yr:
        print(0)
        exit()
print((xr - xl) * (yr - yl))

Measured memory_bytes: 9116
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n) ; ++i)
using namespace std;
using ll = long long ;
using P = pair<int, int> ;
#define PI 3.14159265358979323846264338327950
int main () {
    int n ,r ;
    cin >> n >> r;
    int ans ;
    if (n >= 10){
        ans = r;
    }
    else {
        ans = r + 100 * (10 - n);
    }
    cout << ans << endl;

}
    
    


Measured memory_bytes: 256
#include "math.h"
#include <iostream>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <vector>
#include <functional>
#include <numeric>
#include <cmath>
using namespace std;

int t;
const int N = 10001;
int arr[N];

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	for (int i = 0; i < N; i++)
	{
		arr[i] = 0;
	}
	for (int x = 1; x < 101; x++)
	{

		for (int y = x; y <101; y++)
		{
			for (int z = y; z <101; z++)
			{
				long long s = x * x + y * y + z * z + x * y + x * z + y * z;
				int k = 6;
				if (x == y && x == z)
				{
					k = 1;
				}
				else if (x == y) {
					k = 3;
				}
				else if (x == z) {
					k = 3;
				}
				else if (y == z) {
					k = 3;
				}
				if (s < N) arr[s - 1] += k;
			}

		}
	}
	cin >> t;
	for (int i = 0; i < t; i++)
	{
		cout << arr[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 3616
/*ヽ｀、ヽ｀｀、ヽ｀ヽ｀、、ヽ ｀ヽ 、ヽ｀🌙｀ヽヽ｀ヽ、ヽ｀
ヽ｀、ヽ｀｀、ヽ 、｀｀、 ｀、ヽ｀ 、｀ ヽ｀ヽ、ヽ ｀、ヽ｀｀、
ヽ、｀｀、｀、ヽ｀｀、 、ヽヽ｀、｀、、ヽヽ、｀｀、 、 ヽ｀、
ヽ｀｀、 ヽ｀ヽ｀、、ヽ ｀ヽ 、 🚶ヽ｀｀｀｀ヽヽヽ｀、、ヽ｀、、ヽ*/
#include <bits/stdc++.h> 
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
 
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long   ll;
typedef long double ld;
typedef complex< ld > cd;
 
typedef pair<int, int> pi;
typedef pair<ll, ll>   pl;
typedef pair<ld, ld>   pd;
 
typedef vector< int > vi;
typedef vector< ld >  vd;
typedef vector< ll >  vl;
typedef vector< pi >  vpi;
typedef vector< pl >  vpl;
typedef vector< cd >  vcd;
 
#define l00p(i, a, b) for (int i=a; i<(b); i++)
#define loop(i, a)    for (int i=0; i<(a); i++)
#define rep1(i, a, b) for (int i = (b)-1; i >= a; i--)
#define rep(i, a)     for (int i = (a)-1; i >= 0; i--)
#define trav(a, x)    for (auto& a : x)
#define uid(a, b)     uniform_int_distribution<int>(a, b)(rng)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f  first
#define s  second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
//#define MOD 998244353
 
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ld pii=3.14159265359; 
const int MOD = 1000000007;
const char nl = '\n';
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy
int n,m;
vi t[200001];
vi counter(200001);
void dfs(int node ,int root)
{
	counter[node]+=counter[root];
	trav(i,t[node])
	{
		if(i!=root)
		dfs(i,node);
	}
}
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); 
	int n,m;
	cin>>n>>m;
	loop(i,n-1)
	{
		int a,b;
		cin>>a>>b;
		t[a].pb(b);
		t[b].pb(a);
	}
	while(m--)
	{
		ll u,v;
		cin>>u>>v;
		counter[u]+=v;
	}
	dfs(1,0);
	l00p(i,1,n+1)
	cout<<counter[i]<<" ";
	return 0;
}
// read the question correctly (ll vs int)
// template by bqi343

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

int main(){
  string s;
  cin >> s;
  int n = s.size();
  reverse(s.begin(), s.end());
  vector<int> md(2019,0);
  md[0]=1;
  int sum = 0, k = 1;
  for(int i = 0; i < n; i++) {
    sum += k * (s[i] - '0'), sum %= 2019;
    k = k * 10 % 2019;
    md[sum]++;
  }
  int ans = 0;
  for(int i = 0; i < 2019; i++)
    ans += md[i] * (md[i] - 1) / 2;
  cout << ans << endl;
}


Measured memory_bytes: 3744
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,n) for(int i = 1; i <= n; i++)
#define rrep(i,n) for(int i = n - 1; i >= 0; i--)
#define rreps(i,n) for(int i = n; i >= 1; i--)
#define mrep(i,from,n) for(int i = from; i < n; i++)
#define mreps(i,from,n) for(int i = from; i <= n; i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define ERASE(x,val) x.erase(remove(ALL(x), val), x.end())
typedef long long ll;
typedef pair<ll, ll> P;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }
ll MOD = 1000000007;
int INF = 1001001001;

void solve()
{
	int n; cin >> n;
	vector<int> a(n);
	rep(i, n) cin >> a[i];
	rrep(i,n)
	{
		cout << a[i];
		if(i != 0)cout<<" ";
		else cout << endl;
	}
	return;
}

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}



Measured memory_bytes: 3136
#include <bits/stdc++.h>
#define re return
#define ull unsigned long long
#define ll long long
#define ld long double
#define f first
#define s second
#define oo 1e9
#define pi acos(-1)
#define OO 4e18
#define EPS 1e-12
#define FX(n) fixed<<setprecision(n)
#define mm(o,k) memset(o,k,sizeof o)
#define Hossam_Yehia ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
int n,x,ans;
map<int,int> mp;
int main(){
    Hossam_Yehia;
    cin >> n;
    while(n--)
        cin >> x,mp[x]++;
    for(auto i:mp)ans+=(i.s%2);
    cout<<ans<<endl;
    re 0;
}

Measured memory_bytes: 4992
from math import pi, atan2

def andrange(a, b):
    if a == (0, 0) or b == (0, 0): return (0, 0)
    if a == (0, 1): return b
    if b == (0, 1): return a
    if a[0] > b[0]: a, b = b, a
    if b[1] < a[1]: return b
    if b[0] < a[1]: return (b[0], a[1])
    if b[1] < a[0] + 1: return (0, 0)
    if b[1] < a[1] + 1: return (a[0], b[1] - 1)
    return a

def calcrange(P, Q):
    c = atan2(P[1]-Q[1], P[0]-Q[0]) / (2*pi)
    if c > 0: return (c, c+0.5)
    else: return (c+1, c+1.5)

N = int(input())
X = []
for _ in range(N):
    x, y = map(int, input().split())
    X.append((x, y))

A = [(0, 1) for _ in range(N)]

for i in range(N):
    for j in range(N):
        if i != j:
            A[i] = andrange(A[i], calcrange(X[i], X[j]))

for a in A:
    print("{:.15f}".format(a[1] - a[0]))


Measured memory_bytes: 44272
import java.util.Scanner;

public class Main {
    //
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(), d = sc.nextInt();
        int[][] A = new int[n][d];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < d; j++) {
                A[i][j] = sc.nextInt();
            }
        }
        System.out.println(sln(A, n, d));
        sc.close();
    }

    static int sln(int[][] A, int n, int d) {
        int res = 0;
        for (int i = 0; i < n - 1; i++) {
            for (int j = i + 1; j < n; j++) {
                int[] B = A[i];
                int[] C = A[j];
                if (helper(B, C, d)) res++;
            }
        }
        return res;
    }

    static boolean helper(int[] A, int[] B, int d) {
        int sum = 0;
        for (int i = 0; i < d; i++) {
            sum += Math.pow(A[i] - B[i], 2);
        }
        int m = (int) Math.sqrt(sum);
        if (m * m == sum) return true;
        return false;
    }
}


Measured memory_bytes: 23124
def solve(s):
    l = len(s)
    even_0 = len([s[i] for i in range(l) if i % 2 == 0 and s[i] == '0'])
    even_1 = len([s[i] for i in range(l) if i % 2 == 0 and s[i] == '1'])
    odd_0 = len([s[i] for i in range(l) if i % 2 == 1 and s[i] == '0'])
    odd_1 = len([s[i] for i in range(l) if i % 2 == 1 and s[i] == '1'])

    return even_0 + odd_1 if even_0 + odd_1 < even_1 + odd_0 else even_1 + odd_0


if __name__ == '__main__':
    s = input()
    print(solve(s))


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

int gcd(int64_t a, int64_t b)
{
  return b == 0 ? a : gcd(b, a % b);
}

int main()
{
  int64_t a, b;
  cin >> a >> b;
  cout << a / gcd(a, b) * b << endl;
}


Measured memory_bytes: 256
#include <string>
#include <iostream>
#include <vector>
#include <stack>
#include <stdio.h>
#include <math.h>
#include <utility>
#include <algorithm>
#include <sstream>

using namespace std;

bool funcsec(pair<int, long long> i, pair<int, long long> j) {
	return i.second > j.second;
}

bool funcfir(pair<int, long long> i, pair<int, long long> j) {
	return i.first > j.first;
}

bool func(long long i, long long j) {
	return i < j;
}

int main() {
	int n,m;
	cin >> n >> m;
	vector<long long> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a.begin(),a.end(), func);

	vector<pair<int,long long> > bc(m);
	for (int i = 0; i < m; i++) {
		cin >> bc[i].first >> bc[i].second;
	}
	sort(bc.begin(), bc.end(), funcsec);
	int cnt = 0;
	for (int i = 0; i < n; i++) {
		if (cnt < bc.size()) {
			if (a[i] < bc[cnt].second) {
				if (bc[cnt].first > 0) {
					a[i] = bc[cnt].second;
					bc[cnt].first--;
				}
				if (bc[cnt].first <= 0) {
					cnt++;
				}
			}
		}
	}
	long long sum = 0;
	for (int i = 0; i < n; i++) {
		sum += a[i];
	}

	cout << sum;
	return 0;
}


Measured memory_bytes: 2560
import java.util.Scanner;

public class Main {
    
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        final int N = sc.nextInt();
        
        long maxA = Long.MIN_VALUE;
        long minA = Long.MAX_VALUE;
        long maxB = Long.MIN_VALUE;
        long minB = Long.MAX_VALUE;
        
        for (int i = 0; i < N; i++) {
            long x = sc.nextLong();
            long y = sc.nextLong();
            
            long a = x + y;
            long b = x - y;
            
            if (maxA < a) {
                maxA = a;
            }
            if (a < minA) {
                minA = a;
            }
            if (maxB < b) {
                maxB = b;
            }
            if (b < minB) {
                minB = b;
            }
        }
        
        System.out.println(Math.max(maxA - minA, maxB - minB));
    }
}


Measured memory_bytes: 59740
#include<iostream>

using namespace std;

int a[51];
int n,sum;

bool dfs (int i, int sum );

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

  for(i=0;i<n-1;i++){
	int temp = a[i];
	for(int j=i+1;j<n;j++){
		sum += temp*a[j];
	}
  }
  cout << sum;
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <list>
#include <set>
using namespace  std;

#define int long long int

constexpr int INF = std::numeric_limits<int>::max();

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int AN, BN, Q;

    cin >> AN >> BN >> Q;

    vector<int> A(AN), B(BN);
    for (int & x: A) {
        cin >> x;
    }
    for (int & x: B) {
        cin >> x;
    }

    if (AN == 1) {
        A.push_back(A.back());
        AN++;
    }
    if (BN == 1) {
        B.push_back(B.back());
        BN++;
    }

    vector<int> MA(AN);
    for (int i = 0, j = 1; i < AN; i++) {
        while (B[j] < A[i] && j < BN - 1) {
            j++;
        }
        MA[i] = min(abs(A[i] - B[j]), abs(A[i] - B[j-1]));
    }

    vector<int> MB(BN);
    for (int i = 0, j = 1; i < BN; i++) {
        while (A[j] < B[i] && j < AN - 1) {
            j++;
        }
        MB[i] = min(abs(B[i] - A[j]), abs(B[i] - A[j-1]));
    }

    while(Q--) {
        int x; cin >> x;

        int ans = INF;
        // check A
        {
            auto itr = lower_bound(A.begin(), A.end(), x);
            int i = distance(A.begin(), itr);
            if (i == 0) {
                i++;
            } else if (i == A.size()) {
                i--;
            }

            int p = abs(A[i] - x) + MA[i];
            int q = abs(A[i-1] - x) + MA[i-1];

            p = (p > 0) ? p : INF;
            q = (q > 0) ? q : INF;
            ans = min(ans, p);
            ans = min(ans, q);
        }

        // check B
        {
            auto itr = lower_bound(B.begin(), B.end(), x);
            int i = distance(B.begin(), itr);
            if (i == 0) {
                i++;
            } else if (i == B.size()) {
                i--;
            }

            int p = abs(B[i] - x) + MB[i];
            int q = abs(B[i-1] - x) + MB[i-1];

            p = (p > 0) ? p : INF;
            q = (q > 0) ? q : INF;
            ans = min(ans, p);
            ans = min(ans, q);
        }
        cout << ans << endl;
    }
}

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

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

  vector<int> S(N, 0);
  for (int i = 0; i < N; i++) {
    int d;
    cin >> d;
    for (int j = 0; j < d; j++) {
      int A;
      cin >> A;
      S.at(A - 1)++;
    }
  }

  int ans = 0;
  for (int i = 0; i < N; i++) {
    if (S.at(i) == 0) ans++;
  }

  cout << ans << endl;
}

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

int main(){
    string s;
    cin >> s;
    long long counta=0;
    long long count=0;
    if(s[0]=='A')counta++;
    for(int i=1;i<s.size();i++){
        if(s[i]=='A')counta++;
        if(s[i]=='C'&&s[i-1]=='B'){
            count+=counta;
            s[i]='A';
        }
        else if(s[i]=='C'&&s[i-1]!='B'){
            counta=0;
        }
        else if(i>=2&&s[i]=='A'&&s[i-1]=='B'&&s[i-2]=='A'){
            counta=1;
        }
        else if(i>=2&&s[i]=='A'&&s[i-1]=='C'&&s[i-2]=='A'){
            counta=1;
        }
        else if(s[i]=='B'&&s[i-1]=='B'){
            counta=0;
        }
        else if(s[i]=='B'&&s[i-1]=='C'){
            counta=0;
        }
        else if(s[i-1]=='C'&&s[i-1]=='C'){
            counta==0;
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <algorithm>
#include <set>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define ll long long
#define P pair<int, int>

using namespace std;
int mod = 1000000007;

int X, Y;

long gcd(long a, long b) {
  long r = 1;
  while (r != 0) {
    r = a%b;
    a = b;
    b = r;
  }
  return a;
}

int main() {
  cin >> X >> Y;
  if (X%Y == 0) {
    cout << -1 << endl;
  } else {
    cout << X << endl;
  }
}


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

int main()
{
    int n;
    cin >> n;
    int res = 0;
    set<string> s;
    string si;
    for (int i = 0; i < n; i++)
    {
        cin >> si;
        s.insert(si);
    }
    cout << s.size() << endl;
}

Measured memory_bytes: 19224
def solve(s):
    r = s[::-1]
    l = len(s)
    sn, rn = 0, 0
    ins = 0

    while True:
        if sn + rn > l:
            return ins
        sc = s[sn]
        rc = r[rn]
        if sc == rc:
            sn += 1
            rn += 1
            continue
        if sc == 'x':
            sn += 1
            ins += 1
            continue
        if rc == 'x':
            rn += 1
            ins += 1
            continue
        return -1


print(solve(input()))


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

int N,M,Q;

vector<vector<int>> sum;
int buildSumTable(vector<int>L, vector<int>R){
  sum=vector<vector<int>>(N+1,vector<int>(N+1,0));
  for (int i=0;i<M;++i){
    sum[L[i]][R[i]]++;
  }
  
  for (int i=1;i<=N;++i){
    for (int j=1;j<=N;++j){
      sum[i][j]+=sum[i-1][j];
      sum[i][j]+=sum[i][j-1];
      sum[i][j]-=sum[i-1][j-1];
    }
  } 
}

int getSumRange(int L, int R){
  int ans=sum[R][R]-sum[R][L-1]-sum[L-1][R]+sum[L-1][L-1];
  return ans;
}

int main(){
  cin >> N >> M >> Q;
  vector<int> L(M);
  vector<int> R(M);
  for (int i=0;i<M;++i) cin >> L[i] >> R[i];
  vector<int> p(Q);
  vector<int> q(Q);
  for (int i=0;i<Q;++i) cin >> p[i] >> q[i];
  buildSumTable(L,R);
  for (int i=0;i<Q;++i){
    int ans=getSumRange(p[i],q[i]);
    cout << ans << endl;
  }
}


Measured memory_bytes: 5120
def s_in():
    return input()

def n_in():
    return int(input())

def l_in():
    return list(map(int, input().split()))

N, M = l_in()
sc = []
for _ in range(M):
  s, c = l_in()
  sc.append((s,c))

for n in range(1000):
  n = str(n)
  if len(n) != N:
    continue

  if all(n[s-1] == str(c) for s,c in sc):
    print(n)
    break
else:
  print(-1)


Measured memory_bytes: 3064
#include <algorithm>     //sort,二分探索,など
#include <bitset>        //固定長bit集合
#include <cmath>         //pow,logなど
#include <complex>       //複素数
#include <deque>         //両端アクセスのキュー
#include <functional>    //sortのgreater
#include <iomanip>       //setprecision(浮動小数点の出力の誤差)
#include <iostream>      //入出力
#include <iterator>      //集合演算(積集合,和集合,差集合など)
#include <map>           //map(辞書)
#include <numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include <queue>         //キュー
#include <set>           //集合
#include <stack>         //スタック
#include <string>        //文字列
#include <unordered_map> //イテレータあるけど順序保持しないmap
#include <unordered_set> //イテレータあるけど順序保持しないset
#include <utility>       //pair
#include <vector>        //可変長配列

using namespace std;
typedef long long ll;

//マクロ
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = (ll)(n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define FORD(i, a, b) for (ll i = (a); i >= (b); i--)
#define ALL(x) (x).begin(), (x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())      //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 //10^12
#define MOD 10000007      //10^9+7
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define MAXR 100000 //10^5:最大のrange(素数列挙などで使用)

signed main()
{
  ll s;
  ll w;

  cin >> s >> w;

  string ans;
  if (w >= s)
  {
    ans = "unsafe";
  }
  else
  {
    ans = "safe";
  }
  cout << ans << endl;
}


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

int main() {
 
  int A,B,K ;
  cin >>A>>B ;
  if((A+B)%2 == 0){
  cout << (A+B)/2 << endl;
  }
    else if((A+B)%2 == 1){
     cout << "IMPOSSIBLE" << endl; 
    }
}

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

using namespace std;

int main() {
	int h, w;
	cin >> h >> w;
	string s = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			string a;
			cin >> a;
			if (a == "snuke") {
				cout << s[j] << i+1 << endl;
				return 0;
			}
		}
	}
}

Measured memory_bytes: 256
S = input()
N = len(S)

def is_palindrome(s):
  return s == s[::-1]

if is_palindrome(S) \
and is_palindrome(S[:int((N-1)/2)]) \
and is_palindrome(S[int((N+3)/2-1):]):
  print('Yes')
else:
  print('No')

Measured memory_bytes: 3060
//Kaori Miyazono, did I reach you ?
//"I can't die because... I'm the one who will protect you." -Asuna Yuuki
 
#include <bits/stdc++.h>
using namespace std;

const int N =  200200;
const long long int inf = 1e18;
typedef pair<long long int, long long int> ii;
typedef pair<long long int, ii> iii;

int n;
long long int nums[N];
ii preff[N];
ii suff[N];

int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> n;
	for(int i = 0; i < n; i++) cin >> nums[i];
	vector<long long int> f(n);
	f[0] = nums[0];
	for(int i = 1; i < n; i++) {
		f[i] = f[i - 1] + nums[i];
	}
	for(int i = 0; i < N; i++) {
		preff[i].first = -1;
		suff[i].first = -1;
	}
	for(int i = 1; i < n; i++) {
		long long int cur = f[i];
		long long int cur1 = (f[i] + 1) / 2, cur2 = f[i] / 2;
		int id = lower_bound(f.begin(), f.end(), cur1) - f.begin();
		//cout << i << ' ' << id << ' ';
		if (id < i) preff[i] = ii(f[id], cur - f[id]);
		id = upper_bound(f.begin(), f.end(), cur2) - f.begin() - 1;
		//cout << id << '\n' << '\n';
		if (id < 0 || id >= i) continue;
		long long int ot = cur - f[id];
		if (preff[i].first == -1 || ot - f[id] < preff[i].first - preff[i].second) {
			preff[i] = ii(ot, f[id]);
		}
	}
	reverse(nums, nums + n);
	f[0] = nums[0];
	for(int i = 1; i < n; i++) {
		f[i] = f[i - 1] + nums[i];
	}
	for(int i = 1; i < n; i++) {
		long long int cur = f[i];
		long long int cur1 = (f[i] + 1) / 2, cur2 = f[i] / 2;
		int id = lower_bound(f.begin(), f.end(), cur1) - f.begin();
		//cout << i << ' ' << id << ' ';
		if (id < i) suff[n - i - 1] = ii(f[id], cur - f[id]);
		id = upper_bound(f.begin(), f.end(), cur2) - f.begin() - 1;
		//cout << id << '\n' << '\n';
		if (id < 0 || id >= i) continue;
		long long int ot = cur - f[id];
		if (suff[n - i - 1].first == -1 || ot - f[id] < suff[n - i - 1].first - suff[n - i - 1].second) {
			suff[n - i - 1] = ii(ot, f[id]);
		}
	}
	long long int ans = inf;
	for(int i = 0; i < n; i++) {
		//cout << i << '\n';
		//cout << preff[i].first << ' ' << preff[i].second << ' ' << suff[i + 1].first << ' ' << suff[i + 1].second << '\n';
		if (preff[i].first <= 0 || preff[i].second <= 0) continue;
		if (suff[i + 1].first <= 0 || suff[i + 1].second <= 0) continue;
		long long int cur = max(preff[i].first, suff[i + 1].first) - min(preff[i].second, suff[i + 1].second);
		//cout << cur << '\n';
		ans = min(ans, cur);
	}
	assert(ans < inf);
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 9600
fun main(args: Array<String>) {
    solve(java.util.Scanner(System.`in`))
}

fun f(a: Int, b: Int, theta: Double): Double {
    val rad = theta / 180.0 * Math.PI
    val result = if (a * Math.tan(rad) <= b) {
        a * a * b - a * a * (a * Math.tan(rad)) / 2.0
    } else {
        a * b * (b * Math.tan(0.5 * Math.PI - rad)) / 2.0
    }
//    println("($a, $b, $theta) = $result")
    return result
}


fun solve(sc: java.util.Scanner) {
    val A = sc.nextInt()
    val B = sc.nextInt()
    val X = sc.nextInt()

    var ok = 0.0
    var ng = 90.0
    while (ok + 0.0000001 < ng) {
        val mid = (ok + ng) / 2.0
        if (f(A, B, mid) >= X) {
            ok = mid
        } else {
            ng = mid
        }
    }
    print("%f".format(ok))
}


Measured memory_bytes: 31384
#pragma region

#include <bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(), (x).end()
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for (int i = (begin); i < (end); i++)
#define IFOR(i, begin, end) for (int i = (end)-1; i >= (begin); i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define MOD 1000000007
#define debug(x) cerr << #x << " = " << (x) << " (line: " << __LINE__ << ") " << endl;
typedef long long ll;
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (auto &v : vec) is >> v;
  return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "vec[ ";
  REP(i, vec.size())
  i == 0
      ? os << vec[i]
      : os << ", " << vec[i];
  os << " ]";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const deque<T> &deq) {
  os << "deq[ ";
  REP(i, deq.size())
  i == 0
      ? os << deq[i]
      : os << ", " << deq[i];
  os << " ]";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const set<T> &set) {
  os << "{ ";
  for (auto &&s : set) &s == &(*set.begin()) ? os << s : os << ", " << s;
  os << " }";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const unordered_set<T> &set) {
  os << "{ ";
  for (auto &&s : set) &s == &(*set.begin()) ? os << s : os << ", " << s;
  os << " }";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const multiset<T> &set) {
  os << "{ ";
  for (auto &&s : set) &s == &(*set.begin()) ? os << s : os << ", " << s;
  os << " }";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const unordered_multiset<T> &set) {
  os << "{ ";
  for (auto &&s : set) &s == &(*set.begin()) ? os << s : os << ", " << s;
  os << " }";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
  os << "(" << p.first << ", " << p.second << ")";
  return os;
}
template <typename TK, typename TV>
ostream &operator<<(ostream &os, const map<TK, TV> &m) {
  os << "{ ";
  for (auto &&k : m) &k == &(*m.begin()) ? os << k.first << " => " << k.second : os << ", " << k.first << " => " << k.second;
  os << " }";
  return os;
}
template <typename TK, typename TV>
ostream &operator<<(ostream &os, const unordered_map<TK, TV> &m) {
  os << "{ ";
  for (auto &&k : m) &k == &(*m.begin()) ? os << k.first << " => " << k.second : os << ", " << k.first << " => " << k.second;
  os << " }";
  return os;
}

#pragma endregion

bool isCollided(vector<vector<bool>> &map, int h, int w, int x, int y) {
  REP(i, w)
  REP(j, h)
  if (map[y + j][x + i]) return true;
  return false;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  int M1, D1, M2, D2;
  cin >> M1 >> D1 >> M2 >> D2;
  cout << (M1 == M2 ? 0 : 1) << "\n";
}


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

#define fst first
#define snd second
#define ll long long
#define ld long double
#define pb push_back
#define emp emplace_back
#define pii pair<int, int>
#define usg unsigned
#define sg signed
#define mp make_pair

using namespace std;

void setIO(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
}

const ld PI = 4*atan((ld)1);
const int INF = 1e9+7;
const ll _INF = 1e18+7;
const int mxn = 1e6+7;

int spf[mxn];
set<int>s;

int main(){
	setIO();
	for (int i = 1; i < mxn; i++){
		if (i&1) spf[i] = i;
		else spf[i] = 2;
	}
	for (int i = 3; i*i < mxn; i++)
		if (spf[i] == i)
			for (int j = i*i; j < mxn; j+=i)
				if (spf[j] == j)
					spf[j] = i;
	bool pws = true;
	int n, gcd=0; cin >> n;
	for (int i = 0; i < n; i++){
		int x; cin >> x;
		if (!i) gcd = x;
		else gcd = __gcd(gcd, x);
		if (pws){
			set<int>s2;
			while (x > 1){
				s2.insert(spf[x]);
				x /= spf[x];
			}
			for (int y : s2){
				if (s.count(y)){
					pws = false;
					break;
				}
				s.insert(y);
			}
		}
	}
	if (pws) cout << "pairwise coprime\n";
	else if (gcd == 1) cout << "setwise coprime\n";
	else cout << "not coprime\n";
}

Measured memory_bytes: 11244
s = input()

start = ['0', '1']
ans = 10**6
for offset in [0,1]:
    now = 0
    for i in range(len(s)):
        j = (i+offset) % 2
        if s[i] != start[j]:
            now += 1
    ans = min(ans, now)

print(ans)


Measured memory_bytes: 9152
#include <iostream>
#include <algorithm>

using namespace std;

template<class T>
T gcd(T a, T b)
{
    while (a > 0)
    {
        T t = a;
        a = b%a;
        b = t;
    }
    return b;
}

int main()
{
    int N, K;
    cin>>N>>K;
    int g;
    cin>>g;
    int m = g;
    for (int i=0; i<N-1; i++)
    {
        int A;
        cin>>A;
        g = gcd(g, A);
        m = max(m, A);
    }

    cout<<(K%g==0 && K<=m ? "POSSIBLE" : "IMPOSSIBLE")<<endl;
}


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

int dy[] = {0, 0, 1, -1, 0};
int dx[] = {1, -1, 0, 0, 0};
// input
int a, b, c, d, e, f;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    int max_sugar = 0, max_water = 0;
    double max = 0;

    queue<pair<int, int> > queue;
    set<pair<int,int> > visited;

    cin >> a >> b >> c >> d >> e >> f;

    queue.push(make_pair(a,0));
    queue.push(make_pair(b,0));

    while(!queue.empty()){

        auto now = queue.front();
        queue.pop();

        if(visited.find(now) != visited.end()){
            continue;
        }

        visited.insert(now);

        int water = now.first,sugar = now.second;

        if (water * 100 + sugar > f){
            continue;
        }

        if((double)sugar/(double)water <= e){

            if(max < (double)sugar / ((double)water*100)){
                max = (double)sugar / ((double)water*100);
                max_water = water;
                max_sugar = sugar;
            }
        }

        queue.push(make_pair(water+a,sugar));
        queue.push(make_pair(water+b,sugar));
        queue.push(make_pair(water,sugar+c));
        queue.push(make_pair(water,sugar+d));

    }
    if(max_water == 0){
        cout << a*100 << " " << 0 << "\n";
    }
    else{
        cout << max_sugar + max_water*100 << " " << max_sugar << "\n";
    }
}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); ++i)
#define fi first
#define se second
#define INF 1000000009
#define LLINF 1000000000000000009LL
using ll = long long;

int main(){
  int n;
  cin>>n;
  queue<string>que;
  vector<string>ans;
  rep2(i,1,10){
    string s;
    s+=char(i+'0');
    que.push(s);
    ans.push_back(s);
  }
  for(int i=10;i<=n;i++){
    string s=que.front();que.pop();
    int sz=s.size();
    if(s[sz-1]!='0'){
      string temp=s;
      temp+=char(s[sz-1]-1);
      que.push(temp);
      ans.push_back(temp);
    }
    {
      string temp=s;
      temp+=char(s[sz-1]);
      que.push(temp);
      ans.push_back(temp);
    }
    if(s[sz-1]!='9'){
      string temp=s;
      temp+=char(s[sz-1]+1);
      que.push(temp);
      ans.push_back(temp);
    }
  }
  cout<<ans[n-1]<<endl;
  return(0);
}


Measured memory_bytes: 23408
#include <stdio.h>

int main(void)
{
	int n;
	int i;
	double height[40];
	int count_1=0,count_2=0,count_3=0,count_4=0,count_5=0,count_6=0;
	
	scanf("%d",&n);
	
	for(i=0;i<n;i++)
	{
		scanf("%lf",&height[i]);
	}
	
	for(i=0;i<n;i++)
	{
		if(height[i] < 165.0)
		{
			count_1++;
		}
		else if(height[i] >= 165.0 && 170.0 > height[i])
		{
			count_2++;
		}
		else if(height[i] >= 170.0 && 175.0 > height[i])
		{
			count_3++;
		}
		else if(height[i] >= 175.0 && 180.0 > height[i])
		{
			count_4++;
		}
		else if(height[i] >= 180.0 && 185.0 > height[i])
		{
			count_5++;
		}
		else if(185.0 <= height[i])
		{
			count_6++;
		}
	}
	
	printf("1:");
	for(i=0;i<count_1;i++)
	{
		printf("*");
	}
	printf("\n");
	printf("2:");
	for(i=0;i<count_2;i++)
	{
		printf("*");
	}
	printf("\n");
	printf("3:");
	for(i=0;i<count_3;i++)
	{
		printf("*");
	}
	printf("\n");
	printf("4:");
	for(i=0;i<count_4;i++)
	{
		printf("*");
	}
	printf("\n");
	printf("5:");
	for(i=0;i<count_5;i++)
	{
		printf("*");
	}
	printf("\n");
	printf("6:");
	for(i=0;i<count_6;i++)
	{
		printf("*");
	}
	printf("\n");
	
	return 0;
}

Measured memory_bytes: 2612
s=input()

sub=list(s)

count=0
max=-1

for i in range(0,len(sub)):
    if sub[i]=='A' or sub[i]=='G' or sub[i]=='C' or sub[i]=='T':
        for j in range(i,len(sub)):
            if sub[j]=='A' or sub[j]=='G' or sub[j]=='C' or sub[j]=='T':
                count+=1
                if count>=max:
                    max=count
            else:
                break
    count=0

if max!=-1:
    print(max)
else:
    print(0)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define rep(i,n) for (int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
int main(){
  int a,b;
  while(scanf("%d",&a)&&a){
    for(int i=0;i<9;i++){
      scanf("%d",&b);
      a-=b;
    }
    printf("%d\n",a);
  }
}

Measured memory_bytes: 1188
import sys
input = sys.stdin.readline

n, m = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

C = [[0] * (n*m + 1) for i in range(2)]

for i in range(n):
    C[0][A[i]] += 1
for i in range(m):
    C[1][B[i]] += 1

ans = 1
mod = 10**9 + 7

ng = 0
ui = 0
uj = 0
um = 0
for i in range(n*m, 0, -1):
    if C[0][i] > 1 or C[1][i] > 1:
        ng = 1
        break
    
    if C[0][i] == 1:
        ui += 1
    if C[1][i] == 1:
        uj += 1
    
    if C[0][i] == 1 and C[1][i] == 1:
        u = 1
    elif C[0][i] == 0 and C[1][i] == 1:
        u = ui
    elif C[0][i] == 1 and C[1][i] == 0:
        u = uj
    else:
        u = ui*uj - um
    # print(i, u)
    if u <= 0:
        ng = 1
        break
    else:
        ans = (ans * u) % mod
    um += 1

if ng == 1:
    print(0)
else:
    print(ans)
        

Measured memory_bytes: 57068
#include <bits/stdc++.h>
using namespace std;
const int MOD=1e9+7;
#define int long long
//template
//main
signed main(){
  int N;string s;cin>>N>>s;
  int ans=1,l=0;
  for(int i=1;i<=N;i++)ans=ans*i%MOD;
  for(int i=0;i<2*N;i++){
    if((s[i]=='B')^(l&1))l++;
    else ans*=l--,ans%=MOD;
  }
  if(l)ans*=0;
  cout<<ans<<endl;
}


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

int A, B, C, K;

int main(){
    cin >> A >> B >> C >> K;

    int a = A, b = B, c = C, k = K;
    while(a >= b){ b *= 2; --k; }
    while(b >= c){ c *= 2; --k; }

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

}







Measured memory_bytes: 3620
#include<iostream>
using namespace std;
typedef long long ll;
ll n;
ll  ans=-1000000000000;
ll f[100][10],p[100][11];
void calc(ll day,ll dec[]){
  if(day==10){
    ll addr=0;
    for(ll i=0;i<10;i++){
      addr+=dec[i];
    }
    if(addr==0){
      return;
    }
    ll same[n],tmp;
    fill(same,same+n,0);
    tmp=0;
    for(ll i=0;i<n;i++){
      for(ll j=0;j<10;j++){
        if(f[i][j]&&dec[j])same[i]++;
      }
    }
    for(ll i=0;i<n;i++){
      tmp += p[i][same[i]];
    }
    ans = max(tmp,ans);
    return ;
  }
  dec[day]=0;
  calc(day+1,dec);
  dec[day]=1;
  calc(day+1,dec);
}
int main(){
  cin >> n;
  ll dec[10];
  for(ll i=0;i<n;i++){
    for(ll j=0;j<10;j++){
      cin >> f[i][j];
    }
  }
  for(ll i=0;i<n;i++){
    for(ll j=0;j<11;j++){
      cin >>p[i][j];
    }
  }
  calc(0,dec);
  cout << ans << endl;
}


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

using namespace std;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long x, y;
  cin >> x >> y;
  long long ans = 0;
  for(long long i=x; i<=y;){
    ans++;
    i *= 2;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
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 ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;

struct L {
  int a, b, c;
  L(int a = 0, int b = 0, int c = 0): a(a), b(b), c(c) {}
};

signed main() {
  int N, M; 
  cin >> N >> M;

  vector<L> vx, vy;
  map<int, int> mx, my;
  mx[0] = 0; my[0] = 0;

  REP(i, N){
    int a, b, c;
    cin >> a >> b >> c;
    mx[a] = 0;
    mx[b] = 0;
    my[c] = 0;
    vx.emplace_back(a, b, c);
  }
  REP(i, M){
    int a, b, c;
    cin >> a >> b >> c;
    mx[a] = 0;
    my[b] = 0;
    my[c] = 0;
    vy.emplace_back(a, b, c);
  }

  vector<int> xs, ys;
  for(auto& p : mx){
    p.second = xs.size();
    xs.emplace_back(p.first);
  }
  for(auto& p : my){
    p.second = ys.size();
    ys.emplace_back(p.first);
  }

  int H = xs.size()*2;
  int W = ys.size()*2;

  vector<vector<int>> d(H, vector<int>(W));
  REP(i, N){
    int a = mx[vx[i].a]*2;
    int b = mx[vx[i].b]*2;
    int c = my[vx[i].c]*2;
    FOR(x, a, b+1) d[x][c] = -1;
  }
  REP(i, M){
    int a = mx[vy[i].a]*2;
    int b = my[vy[i].b]*2;
    int c = my[vy[i].c]*2;
    FOR(x, b, c+1) d[a][x] = -1;
  }

  int sx = mx[0]*2;
  int sy = my[0]*2;

  queue<pair<int, int>> q;
  q.emplace(sx, sy);

  d[sx][sy] = 1;

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

  while(!q.empty()){
    auto [x, y] = q.front(); q.pop();

    REP(i, 4){
      int nx = x+dx[i];
      int ny = y+dy[i];
      if(OUT(0, nx, H) || OUT(0, ny, W)) continue;
      if(d[nx][ny] != 0) continue;
      d[nx][ny] = 1;
      q.emplace(nx, ny);
    }
  }

  int ans = 0;
  REP(i, H) REP(j, W){
    if(d[i][j] != 1) continue;
    if(i == 0 || i == H-1 || j == 0 || j == W-1){
      cout << "INF" << "\n";
      return 0;
    }
    if(i%2 == 0 || j%2 == 0) continue;

    int ex = xs[i/2+1]-xs[i/2];
    int ey = ys[j/2+1]-ys[j/2];
    ans += ex*ey;
  }

  cout << ans << "\n";

  return 0;
}

Measured memory_bytes: 285352
#include <iostream>
#include <cstring>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <math.h>
#include <string>
#include <map>
#include <cstdlib>
#include <sstream>
#include <bitset>
using namespace std;

typedef long long ll;
int mod=3;
int INF=100000000;
typedef pair<int, int> P;

int main()
{
    int N,M;
    cin >> N >> M;
    vector<vector <int> > vt(N);
    for(int i=0; i<M; i++){
        int t1,t2;
        cin >> t1 >> t2;
        t1--;
        t2--;
        vt[t1].push_back(t2);
    }
    int S,T;
    cin >> S >> T;
    S--;
    T--;

    int dist[N][3];
    for(int i=0; i<N; i++){
        for(int j=0; j<3; j++){
            dist[i][j]=INF;
        }
    }
    dist[S][0]=0;
    queue<P> que;
    que.push(P(S, 0));//今いる頂点、距離を3で割った余り
    while(que.size()!=0){
        int v=que.front().first;
        int l=que.front().second;
        que.pop();
        for(int u : vt[v]){
            int nl=(l+1)%3;
            if(dist[u][nl]!=INF) continue;
            dist[u][nl]=dist[v][l]+1;
            que.push(P(u,nl));
        }
    }
    
    int ans=dist[T][0];
    if(ans==INF) ans=-1;
    else ans/=3;
    cout << ans << endl;
    

    return 0;
}

Measured memory_bytes: 6912
H,W = (int(x) for x in input().split())
lines = [input() for i in range(H)]
dp = [[0] * W for _ in range(H)]
if lines[0][0] == "#":
    dp[0][0] = 1
q = r = dp[0][0]
for i in range(H):
    for j in range(W):
        if i == j == 0: continue
        if j > 0:
            q = dp[i][j-1]
            if lines[i][j] == "#" and lines[i][j-1] == ".":
                q = dp[i][j-1] + 1
        if i > 0:
            r = dp[i-1][j]
            if lines[i][j] == "#" and lines[i-1][j] == ".":
                r = dp[i-1][j] + 1
        if j == 0: 
            dp[i][j] = r
        elif i == 0:
            dp[i][j] = q
        else:
            dp[i][j] = min(q,r)
print(dp[H-1][W-1])

Measured memory_bytes: 3188
#include <bits/stdc++.h>
 
#define Set(a, b) memset(a, (b), sizeof(a))
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define repi(i, l, r) for (int i=l ; i <= (int)(r) ; ++i)
#define repd(i, l, r) for (int i=r ; i >= (int)(l) ; --i)
#define all(cont) cont.begin(), cont.end()
#define Sort(n) sort(all(n))
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define ll long long
#define ull unsigned long long

/* ASCII Table */
/* 48 == '0', 57 = '9', 65 == 'A', 90 == 'Z', 97 == 'a', 122 == 'z' */  

using namespace std;
 
int main()
{
    long x1, x2 ,y1, y2;
    long dif, difx, dify;

    cin >> x1 >> y1 >> x2 >> y2;

    if(x1 == x2){
        dif = abs(y1 - y2);
        if(y1 < y2){
            cout << x2-dif << " " << y2 << " " << x1-dif << " " << y1; 
        } else {
            cout << x2+dif << " " << y2 << " " << x1+dif << " " << y1;
        }
    } else if(y1 == y2){
        dif = abs(x1 - x2);
        if(x1 < x2){
            cout << x2 << " " << y2+dif << " " << x1 << " " << y1+dif; 
        } else {
            cout << x2 << " " << y2-dif << " " << x1 << " " << y1-dif;
        }
    } else {
        difx = abs(x1 - x2);
        dify = abs(y1 - y2);
        if(x1 < x2){
            if(y1 < y2){
                cout << x2-dify << " " << y2+difx << " " << x1-dify << " " << y1+difx; 
            } else {
                cout << x2+dify << " " << y2+difx << " " << x1+dify << " " << y1+difx; 
            }
        } else {
            if(y1 < y2){
                cout << x2-dify << " " << y2-difx << " " << x1-dify << " " << y1-difx; 
            } else {
                cout << x2+dify << " " << y2-difx << " " << x1+dify << " " << y1-difx; 
            }
        }
    }

    cout << endl;

    return 0;
}
 
 
 
/* Source code dengan case
 
int main(){
    int T;
    cin >> T;
    for(int counterT = 1 ; counterT <= T ; T++){
         
        printf("%d\n", ans);
    }
    return 0;
}
 */
 
/* Source code dengan case
 
int main(){
    int T;
    cin >> T;
    for(int counterT = 1 ; counterT <= T ; T++){
         
        printf("Case #%d: %d\n", counterT, ans);
    }
    return 0;
}
 */

Measured memory_bytes: 256