akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
#include <queue>
#include <cmath>
#include <string>
#include <iterator>
#include <map>
#include <set>
#include <iomanip>
#include <vector>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using Graph = vector<vector<int>>;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
#define INF 100000000000
#define MAX 200001
#define MOD 1000000007

int main(){
    int H, W, N;
    cin >> H >> W >> N;
    int sr, sc;
    cin >> sr >> sc;
    string S, T;
    cin >> S >> T;
    int w_l = 1;
    int w_r = W;
    int h_u = 1;
    int h_d = H;
    int flag = 0;
    for(int i = N - 1; i >= 0; i--){
        if(i != N - 1){
            if(T[i] == 'R') w_l = max(1, w_l - 1);
            if(T[i] == 'L') w_r = min(W, w_r + 1);
            if(T[i] == 'U') h_d = min(H, h_d + 1);
            if(T[i] == 'D') h_u = max(1, h_u - 1);
        }
        if(S[i] == 'R') w_r--;
        if(S[i] == 'L') w_l++;
        if(S[i] == 'U') h_u++;
        if(S[i] == 'D') h_d--;
        if(w_r < w_l or h_d < h_u)
        {
            flag = 1;
            break;
        }
    }
    if(w_r < sc or sc < w_l or h_u > sr or sr > h_d) flag = 1;
    if(flag) cout << "NO" << endl;
    else cout << "YES" << endl;
}

Measured memory_bytes: 3916
h, w = map(int, input().split())

s = h * w

ts = s / 3
ans = s
ps = [s, 0, 0]

for pattern in range(4):
    p = list(bin(pattern)[2:].zfill(2))
    p = [int(_p) for _p in p]
    size = [h, w]
    ps = [s, 0, 0]
    for i, f in enumerate(p):
        df = round(ts / size[f ^ 1])
        ps[i + 1] = ps[i] - df * size[f ^ 1]
        ps[i] = df * size[f ^ 1]
        size[f] -= df
    ans = min(ans, max(ps)-min(ps))

print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define FOR(i, s, e) for(int i = (s); i < (e); i++)
#define FOE(i, s, e) for(int i = (s); i <= (e); i++)
#define FOD(i, s, e) for(int i = (s); i >= (e); i--)
#define ll long long

int ans, K, S;

int main ()
{
	scanf("%d %d", &K, &S);
	FOE(i, 0, K) FOE(j, 0, K)
	{
		if (i + j <= S && i + j + K >= S) ans++;
	}
	
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
#define int long long
#define double long double
#define fo(a,b) for(int a=0;a<b;a++)
#define Sort(a) sort(a.begin(),a.end())
#define rev(a) reverse(a.begin(),a.end())
#define fi first
#define se second
#define sz size()
#define bgn begin()
#define en end()
#define pb push_back
#define pp() pop_back()
#define V vector
#define P pair
#define yuko(a) setprecision(a)
#define uni(a) a.erase(unique(a.begin(),a.end()),a.end())
#define Q queue
#define pri priority_queue
#define Pri priority_queue<int,vector<int>,greater<int>>
#define PriP priority_queue<P<int,int>,vector<P<int,int>>,greater<P<int,int>>>
#define ff first.first
#define fs first.second
#define sf second.first
#define ss second.second
#define all(a)  (a).begin(),(a).end()


signed main(){
  int n,m;
  cin>>n>>m;
  V<string> a(n);
  fo(i,n){
    cin>>a[i];
  }
  V<string> b(m);
  fo(i,m){
    cin>>b[i];
  }

  bool can=0;

  for(int x=0; x<n; x++){
    for(int y=0; y<n; y++){
      if(x+m>n)
        continue;
      if(y+m>n)
        continue;
      bool c=1;
      fo(i,m){
        fo(j,m){
          if(a[x+i][y+j]!=b[i][j])
            c=0;
        }
      }
      if(c)
        can=1;
    }
  }

  if(can)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
}

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

typedef long long ll;

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

    int n;
    cin >> n;
    vector<string> s(n);
    string ans;
    for(int i=0;i<n;i++) cin >> s[i];
    char now = 'a';
    for(char c=now;c<='z';c++){
        int cnt = 0;
        for(int i=0;i<n;i++){
            for(int j=0;j<s[i].size();j++){
                if(s[i][j]==c){
                    s[i].erase(s[i].begin()+j);
                    cnt++;
                    break;
                }
            }
        }
        if(cnt==n){
            ans += c;
            now = c--;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <cstring>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <stack>
#include <set>
#include <queue>
#include <algorithm>
#include <deque>
#include <map>
#include <cmath>
#include <type_traits>
using namespace std;

#define INF 1e18
#define int long long

signed main() {
    int a, b; cin >> a >> b;

    int ans = max(a + b, max(a - b, a * b));

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#define _DEBUG 1
#define _GLIBCXX_DEBUG

#include <bits/stdc++.h>
using namespace std;

using ll = long long;

#ifdef _DEBUG
#define dump(x) cerr << #x << "=" << x << endl
#define dump2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define dump3(x, y, z)                                                         \
  cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z     \
       << endl
#define check(s) cerr << s << endl
#else
#define dump(x)
#define dump2(x, y)
#define dump3(x, y, z)
#define check(s)
#endif

#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define unique(v) v.erase(unique(v.begin(), v.end()), v.end());

const int INF = 1e9;

void solve(ll H, ll W, std::vector<std::vector<ll>> c,
           std::vector<std::vector<ll>> A) {

  rep(k, 10) {
    rep(i, 10) {
      rep(j, 10) { c[i][j] = min(c[i][j], c[i][k] + c[k][j]); }
    }
  }

  ll result = 0;
  rep(i, H) {
    rep(j, W) {
      auto v = A.at(i).at(j);
      if (v != -1)
        result += c.at(v).at(1);
    }
  }
  cout << result << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You
// use the default template now. You can remove this line by using your custom
// template)
int main() {
  ll H;
  scanf("%lld", &H);
  ll W;
  scanf("%lld", &W);

  vector<vector<ll>> c(10, vector<ll>(10));
  for (int i = 0; i < 10; i++) {
    for (int j = 0; j < 10; j++) {
      scanf("%lld", &c[i][j]);
    }
  }
  std::vector<std::vector<ll>> A(H, std::vector<ll>(W));
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      scanf("%lld", &A[i][j]);
    }
  }
  solve(H, W, std::move(c), std::move(A));
  return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#define rep(i, n)   for(int i = 0; i < (n); i++)
using namespace std;
typedef long long int ll;

int main(){
    int n,x;	cin >> n >> x;
    vector<int>a(n);
    rep(i, n)	cin >> a[i];
    //solve
    ll ans = 0;
    rep(i, n-1){
	int sum = a[i] + a[i+1];
	if(sum > x){
	    if(a[i] <= x){
		ans += sum - x;
		a[i+1] = x - a[i];
	    }else{
		ans += a[i+1];
		a[i+1] = 0;
		ans += a[i] - x;
		a[i] = x;
	    }
	}
    }
    cout << ans << endl;
}


Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 911;
struct lpl{
    int x, y;
    bool operator < (const lpl &a)const{return x < a.x;}
}p[maxn];
struct Segment_Tree{int w, tag;}tr[maxn * 4];
int w, h, n, Y[maxn];
int st[2][maxn], top[2], ans;

inline int ls(int t){return (t << 1);}
inline int rs(int t){return (t << 1 | 1);}

inline void update(int t){tr[t].w = max(tr[ls(t)].w, tr[rs(t)].w);}

inline void pushdown(int t){
    if(!tr[t].tag) return;
    tr[ls(t)].w += tr[t].tag; tr[ls(t)].tag += tr[t].tag;
    tr[rs(t)].w += tr[t].tag; tr[rs(t)].tag += tr[t].tag;
    tr[t].tag = 0;
}

void modify(int k, int l, int r, int x, int y, int val){
    if(l >= x && r <= y){tr[k].w += val, tr[k].tag += val; return;}
    int mid = (l + r) >> 1; pushdown(k);
    if(x <= mid) modify(ls(k), l, mid, x, y, val);
    if(y > mid) modify(rs(k), mid + 1, r, x, y, val);
    update(k);
}

int query(int k, int l, int r, int x){
	if(l == r) return tr[k].w;
	int mid = (l + r) >> 1; pushdown(k);
	if(x <= mid) return query(ls(k), l, mid, x);
	return query(rs(k), mid + 1, r, x);
}

inline void workk(){
	sort(p + 2, p + n + 1);
	top[0] = top[1] = st[0][0] = st[1][0] = 0;
	modify(1, 1, n, 1, n, (h << 1));
	for(int i = 2; i <= n; ++i){
		modify(1, 1, n, 1, i - 1, (p[i].x - p[i - 1].x) << 1);
		ans = max(ans, tr[1].w);
		if(p[i].y >= (h >> 1)){
			modify(1, 1, n, st[0][top[0]], i - 1, (p[i].y - h) << 1);
			while(top[0] && p[st[0][top[0]]].y >= p[i].y){
				modify(1, 1, n, st[0][top[0] - 1], st[0][top[0]] - 1, (p[i].y - p[st[0][top[0]]].y) << 1);
				top[0]--;
			}
			st[0][++top[0]] = i;			
		}
		else{
			modify(1, 1, n, st[1][top[1]], i - 1, -p[i].y << 1);
			while(top[1] && p[st[1][top[1]]].y <= p[i].y){
				modify(1, 1, n, st[1][top[1] - 1], st[1][top[1]] - 1, (p[st[1][top[1]]].y - p[i].y) << 1);
				top[1]--;
			}
			st[1][++top[1]] = i;
		}
	}
	memset(tr, 0, sizeof(tr));
}

int main()
{
	scanf("%d%d%d", &w, &h, &n); ++n;
	for(int i = 2; i <= n; ++i) scanf("%d%d", &p[i].x, &p[i].y);
	p[++n] = (lpl){w, h}; workk();
	swap(w, h); for(int i = 1; i <= n; ++i) swap(p[i].x, p[i].y); workk();
	cout << ans;
    return 0;
}



Measured memory_bytes: 14080
class MaxHeap
  def initialize
    @heap = [nil]
    @size = 0
  end
  attr_reader :heap, :size
  
  def insert(value)
    @heap << value
    @size += 1
    up_heap(@size / 2)
  end
  
  def up_heap(i)
    return if i.zero?
    l, r = i * 2, i * 2 + 1
    largest = (l <= @size && @heap[l] > @heap[i]) ? l : i
    largest = r if r <= @size && @heap[r] > @heap[largest]
    unless largest == i
      @heap[i], @heap[largest] = @heap[largest], @heap[i]
      up_heap(i / 2)
    end
  end
   
  def remove_root
    return nil if @size.zero?
    a = @heap[1]
    b = @heap.pop
    @size -= 1
    return b if @heap.size == 1
    @heap[1] = b
    down_heap(1)
    a
  end
   
  def down_heap(i)
    return if i > @size
    l, r = i * 2, i * 2 + 1
    largest = (l <= @size && @heap[l] > @heap[i]) ? l : i
    largest = r if r <= @size && @heap[r] > @heap[largest]
    unless largest == i
      @heap[i], @heap[largest] = @heap[largest], @heap[i]
      down_heap(largest)
    end
  end
  
  def sum
    @heap[1..-1].inject(:+)
  end
end


n, m = gets.split.map(&:to_i)
prices = gets.split.map(&:to_i)

mh = MaxHeap.new
prices.each {|price| mh.insert(price)}

m.times { mh.insert(mh.remove_root / 2) }

puts mh.sum

Measured memory_bytes: 9740
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<array>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<queue>
#include<vector>
using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define ALL(a) (a).begin(),(a).end()
#define DUMP(o) {cerr<<#o<<" "<<o<<endl;}
#define DUMPC(o) {cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
const int MOD = 1e9 + 7;

//???????????????????§???¢???n??????
vector<ll> pascalTriangle(int n) {
	vector<ll> a(n, 1), b(n, 1);
	//3????????????n???????????§?¨????
	FOR(i, 3, n + 1) {
		swap(a, b);
		a[0] = 1; a[i - 1] = 1;
		FOR(j, 1, i - 1)a[j] = b[j - 1] + b[j];
	}
	return a;
}

signed main() {
	for (string s; cin >> s;) {
		vector<ll> p = pascalTriangle(10);
		ll ans = 0;
		REP(i, 10)ans+= (s[i] - '0')*p[i];
		ans %= 10;
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3132
#include <bits/stdc++.h>
#include <numeric>
#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG true
#define LL long long
#define Num 1000000007
// sort(a.begin(), a.end(), std::greater<int>());
using namespace std;

int main()
{
    int r;
    cin>>r;
    if(r>=2800) cout<<"AGC";
    else if(r>=1200) cout<<"ARC";
    else cout<<"ABC";
    cout<<endl;
    return 0;
}

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

int main(){
	int n;
	cin>>n;
	int ans=n%10;
	if(ans==2||ans==4||ans==5||ans==7||ans==9) cout<<"hon";
	else if(ans==0||ans==1||ans==6||ans==8) cout<<"pon";
	else if(ans==3) cout<<"bon";
	//cout<<ans;
	
	return 0;
}

Measured memory_bytes: 3636
build = range(1, 5)
floor = range(1, 4)
dic = {b: {f: [0]*10 for f in floor} for b in build}

n = input()
for i in range(n):
    info = map(int, raw_input().split())
    dic[info[0]][info[1]][info[2]-1] += info[3]
    if dic[info[0]][info[1]][info[2]-1] > 9:
        print 'error'

for b in build:
    for f in floor:
        print '',
        print ' '.join(map(str, dic[b][f]))
    if b != 4:
        print "#"*20

Measured memory_bytes: 6436
#include <algorithm>  // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>     // bitset
#include <cctype>     // isupper, islower, isdigit, toupper, tolower
#include <cstdint>    // int64_t, int*_t
#include <cstdio>     // printf
#include <deque>      // deque
#include <iomanip>    // fixed, setprecision
#include <iostream>   // cout, endl, cin
#include <map>        // map
#include <numeric>    // accumulate
#include <queue>      // queue, priority_queue
#include <set>        // set
#include <stack>      // stack
#include <string>     // string, to_string, stoi
#include <tuple>      // tuple, make_tuple
#include <unordered_map>  // unordered_map
#include <unordered_set>  // unordered_set
#include <utility>        // pair, make_pair
#include <vector>         // vector
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

int main() {
  ll N, c = 0;
  string s;
  ll R = 0, G = 0, B = 0;
  cin >> N >> s;
  for (int i = 0; i < N; i++) {
    switch (s[i]) {
      case 'R':
        R++;
        break;
      case 'G':
        G++;
        break;
      case 'B':
        B++;
        break;
    }
  }

  ll i, j, k;
  for (ll diff = 1; diff <= N / 2; diff++) {
    for (i = 0; i < N; i++) {
      j = i + diff;
      k = j + diff;
      if (k < N) {
        if (s[i] != s[k] && s[j] != s[k] && s[i] != s[j]) c--;
      } else {
        break;
      }
    }
  }

  c += R * G * B;

  cout << c << endl;
}


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

#define rep(i,n) for(int i=0;i<(n);i++)

typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//定数
#define INF 1000000000 //10^9:極めて大きい値,∞
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

ll lcm(ll A, ll B)
{

    ll a, b, r, tmp;
    a=A;
    b=B;
 
  /* 自然数 a > b を確認・入替 */
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }

  /* ユークリッドの互除法 */
  r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
  return A*B/b;
}

int main() {
    int N,M;
    cin>>N>>M;
    vector<int> a(N);
    int A;
    bool b=false;
    int cc;
    rep(i,N){ 
        cin>>A;
        int c=0;
        while(A%2==0){
            c++;
            A=A/2;
        }
        a[i]=A;
        if(i==0) cc=c;
        else if(cc!=c){
            cout<<"0"<<endl;
            return 0;
        }
    }
    ll l=a[0];
    for(int i=1;i<N;i++) l=lcm(l,a[i]);
    rep(i,cc-1) M/=2;
    int ans=M/l;
    ans=ans/2+ans%2;
    cout<<ans<<endl;
    return 0;
}

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

/*                    ॐ Shree ॐ                     */
/* ॐ ॐ ॐ
ॐ भूर् भुवः स्वः
तत् सवितुर्वरेण्यं
भर्गो देवस्य धीमहि
धियो यो नः प्रचोदयात्
*/
using namespace std;
typedef long long int ll;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#else
// online submission
#endif
	ll n,x,y,d;
	cin>>n>>d;
	ll count=0;
	for(int i=0;i<n;i++){
		cin>>x>>y;
		if(x*x+y*y<=d*d){
			count++;
		}
	}
	cout<<count;
}

Measured memory_bytes: 3612
#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>;

int debug = 0;

int gcd(int a, int b){
    int tmp,r;
    if(a <b){
        tmp =a;
        a = b;
        b = tmp;
    }
    r = a%b;
    while(r!=0){
        a=b;
        b=r;
        r=a%b;
    }
    return b;
}

int gcd3(int i, int j, int k){
    int tmp,tmp1;
    tmp = gcd(i,j);
    tmp1 = gcd(tmp,k);
    if(debug){
        cout << "gcd3(" << i <<"," <<j<<"," << k<<")=" <<tmp1 << endl;  
    }
    return tmp1;
}

int main()
{
    int k;
    int ans=0;

    cin >> k;

    for(int i=1;i<k+1;++i){
        for(int j=1;j<k+1;++j){
            for(int m=1;m<k+1;++m){
                ans+= gcd3(i,j,m);
            }
        }
    }

    cout << ans <<endl;

    return 0;
}

Measured memory_bytes: 3600
/* You are being watched. */


//~ while (clock() <= 69*CLOCKS_PER_SEC)
//~ #pragma comment(linker, "/stack:200000000")

#include <bits/stdc++.h>

//~ #pragma GCC optimize("Ofast")
//~ #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//~ #pragma GCC optimize("unroll-loops")

using namespace std;

//~ #include <ext/pb_ds/assoc_container.hpp>
//~ #include <ext/pb_ds/tree_policy.hpp>
//~ using namespace __gnu_pbds;
//~ template <typename T>
//~ using ordered_set =
  //~ tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define all(x) (x).begin(), (x).end()
#define show(x) cerr << __LINE__ << " says: " << #x << " = " << (x) << "\n"
#define FastIO ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
//using li = __int128;
//using uli = unsigned __int128;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

double getTime() {
  return clock() / (double) CLOCKS_PER_SEC;
}

void read() {};

template<typename T, typename... Args>
void read(T& a, Args&... args) {
  cin >> a;
  read(args...);
}

void print() {};

template <typename T, typename... Args>
void print(T a, Args... args) {
  cout << a << " \n"[sizeof...(args) == 0];
  print(args...);
}

int get(int x, int k) {
  return x / k;
}

void solve() {
  int k; cin >> k;
  int a, b; cin >> a >> b;
  if(get(b, k) - get(a - 1, k) > 0) {
    print("OK");
  }
  else {
    print("NG");
  }
}

int main() {
  int t; t = 1;
  while(t--) solve();
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define rep(i,n) for ((i)=1;(i)<=(n);(i)++)
using namespace std;
int n,i,j,k,f[1505][1505],l[1505][1505],r[1505][1505];
long long ans;
char a[1505][1505];
int main(){
	cin>>n;
	rep(i,n){
		rep(j,n){
			cin>>a[i][j];
		}
	}
	for(i=0;i<=n+1;i++){
		a[0][i]=a[i][0]=a[n+1][i]=a[i][n+1]='#';
	}
	for(i=n;i;i--){
		for(j=n;j;j--){
			if(a[i][j]!='#'){
				if(a[i+1][j]=='#'&&a[i][j+1]=='#'){
					l[i][j]=r[i][j]=j;
					for(k=i+1;k<=n;k++){
						l[k][j]=n+1;
						r[k][j]=0;
					}
				}
				if(a[i+1][j]!='#'&&a[i][j+1]=='#'){
					f[i][j]=f[i+1][j];
					l[i][j]=r[i][j]=j;
				}
				if(a[i+1][j]=='#'&&a[i][j+1]!='#'){
					f[i][j]=f[i][j+1];
					l[i][j]=j;
					r[i][j]=r[i][j+1];
					for(k=i+1;k<=n;k++){
						l[k][j]=l[k][j+1];
						r[k][j]=r[k][j+1];
					}
				}
				if(a[i+1][j]!='#'&&a[i][j+1]!='#'){
					l[i][j]=j;r[i][j]=r[i][j+1];
					f[i][j]=f[i+1][j]+f[i][j+1];
					int lst=0;
					for(k=i+1;k<=n;k++){
						if(l[k][j+1]<=r[k][j]&&l[k][j+1]>lst){
							f[i][j]-=f[k][l[k][j+1]];
						}
						lst=max(lst,r[k][j]);
						l[k][j]=min(l[k][j],l[k][j+1]);
						r[k][j]=max(r[k][j],r[k][j+1]);
					}
				}
				ans+=f[i][j]*(a[i][j]&15);
				f[i][j]+=(a[i][j]&15);
			}
			else{
				l[i][j]=n+1;
				r[i][j]=0;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

template<typename T_char>
T_char ToUpper(T_char cX){return toupper(cX);}

int main(){
  int n, k;
  cin >> n >> k;
  vector<int> p(n);
  for(int i=0; i<n; ++i) cin >> p[i];
  sort(p.begin(), p.end());
  int sum =0;
  for(int i=0; i<k; ++i){
    sum+=p[i];
  }
  cout << sum;
  return 0;
}

Measured memory_bytes: 3632
#include<stdio.h>
#include<algorithm>
using namespace std;
int main()
{
    int a[3];
    scanf("%d%d%d",&a[0],&a[1],&a[2]);
    sort(a,a+3);
    int time=0;
    while(1)
    {
        if(a[1]-a[0]>=2)
        {
            time++;
            a[0]=a[0]+2;
            continue;
        }

            sort(a,a+3);
            int sum=(a[1]-a[0])+(a[2]-a[0]);
            time=time+sum;
            break;
    }
    printf("%d\n",time);
    return 0;
}


Measured memory_bytes: 128
N,M=map(int,input().split())
info=[None]*M
pre=[None]*(N+1)
for i in range(M):
  p,y=map(int,input().split())
  info[i]=[p,y]
  if pre[p]==None:
    pre[p]=[y]
  else:
    pre[p].append(y)
    
for i in range(1,len(pre)):
  cities=pre[i]
  if cities==None:
    continue
  cities=sorted(cities)
  dic={}
  for j in range(len(cities)):
    dic[cities[j]]=j+1
  pre[i]=dic
  
for i in range(len(info)):
  p=info[i][0]
  y=info[i][1]
  print(str(p).zfill(6)+str(pre[p][y]).zfill(6))


Measured memory_bytes: 54524
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,cnt=0;
    cin>>n;
    char st[n+1];
    cin>>st;
    if(n%2==0){
        for(int i=0;i<(n/2);i++){
            if(st[i]==st[n/2+i]) cnt++;
        }

    }
    if(n%2!=0)
        cout<<"No\n";
    else if(cnt==n/2)
        cout<<"Yes\n";
    else cout<<"No\n";

    return 0;
}


Measured memory_bytes: 256
import bisect
sizeA, sizeB, Q = map(int, input().split())
A = []
B = []
for h in range(sizeA):
    A.append(int(input()))
for hh in range(sizeB):
    B.append(int(input()))
for i in range(Q):
    now = int(input())
    a_place = bisect.bisect_left(A, now)
    b_place = bisect.bisect_left(B, now)
    if a_place != 0:
        a_left = A[a_place - 1]
    else:
        a_left = -10**11
    if a_place != sizeA:
        a_right = A[a_place]
    else:
        a_right = 10 ** 20
    if b_place != 0:
        b_left = B[b_place - 1]
    else:
        b_left = -10 ** 10
    if b_place != sizeB:
        b_right = B[b_place]
    else:
        b_right = 10 ** 20
    kouho1 = max(a_right, b_right) - now
    kouho2 = abs(now - min(a_left, b_left))
    kouho3 = abs(a_left - b_right)+min(b_right-now,now-a_left)
    kouho4 = abs(b_left - a_right)+min(a_right-now, now-b_left)
    print(min(kouho1, kouho2, kouho3, kouho4))
#print(A,B)


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

int main(){
  int A, B, C, X; cin >> A >> B >> C >> X;
  int count=0;
  for(int i=0;i<=A;i++){
    for(int j=0;j<=B;j++){
      for(int k=0;k<=C;k++){
        if(i*500+j*100+k*50==X){
          count++;
        }
      }
    }
  }
  cout << count << endl;
}
        

Measured memory_bytes: 256
#include<iostream>
#include<queue>
using namespace std;
static const int N = 100;
static const int INFTY = (1<<21);

int n,M[N][N];
int d[N];

void bfs(int s){
    queue<int> q;
    q.push(s);
    for(int i=0;i<n;i++){
        d[i] = INFTY;
    }
    d[s] = 0;
    int u;
    while(!q.empty()){
        u = q.front();q.pop();
        for(int v = 0;v<n;v++){
            if(M[u][v] == 0)continue;
            if(d[v] != INFTY)continue;
            d[v] = d[u]+1;
            q.push(v);
        }
    }
    for(int i=0;i<n;i++){
        cout << i+1 << " " << ( (d[i] == INFTY) ? (-1) : d[i]) << endl;
    }
}

int main(){
    int  u,k,v;
    cin >> n;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
             M[i][j] = 0; 
        }
    }
    for(int i=0;i<n;i++){
        cin >> u >> k;
        u--;
        for(int j =0;j<k;j++){
            cin >> v;
            v--;
            M[u][v] = 1;
        }
    }
    bfs(0);

    return 0;
}


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

int main()
{
  string a, b;
  cin >> a >> b;
  int ans = -1;
  if(a.size() > b.size())
  {
    ans = 0;
  }
  else if(a.size() < b.size())
  {
    ans = 1;
  }
  else if(a == b)
  {
    ans = 2;
  }
  else
  {
    int i;
    for(i = 0; i < a.size(); i++)
    {
      if(a.at(i) > b.at(i))
      {
        ans = 0;
        break;
      }
      else if(a.at(i) < b.at(i))
      {
        ans = 1;
        break;
      }
    }
  }
  if(ans == 0)
  {
    cout << "GREATER" << endl;
  }
  else if(ans == 1)
  {
    cout << "LESS" << endl;
  }
  else if(ans == 2)
  {
    cout << "EQUAL" << endl;
  }
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <iterator>
#define loop(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define debug(x)  cout << #x << " = " << (x) << endl;

using namespace std;
using LL = long long;
using ULL = unsigned long long;

int main() {
    int n; cin >> n;
    string str; cin >> str;

    int x = 0;
    int ans = 0;
    for (auto ch: str) {
        if (ch == 'I') x++;
        else x--;

        ans = max(ans, x);
    }

    cout << ans << endl;
}


Measured memory_bytes: 888
//Relive your past life.
//Face your demons.
//The past is never dead,it is not even past.
//The memories are not only the key to the past but...also to the future.
//coded in Rusty Lake
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
#define ll   long long
#define pb   push_back
#define mp   make_pair
#define orz  1000000007
//作者:中国江苏南京丁天行
using namespace std;
int n,o=-1;
ll ans;
bool ok;
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;++i){
        int x,y;
        scanf("%d%d",&x,&y);
        if(x!=y)ok=1;
        ans+=y;
        if(x>y){
            if(o==-1||y<o)o=y;
        }
    }
    if(!ok)puts("0");
    else cout<<ans-o*1ll<<endl;
	//system("pause");
	return 0;
}


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

using namespace std;

constexpr int MAXN = 2e5 + 5;

template<typename T>
inline void read(T& x, T f = 1, char ch = getchar()) {
    x = 0;
    while (!isdigit(ch)) f = (ch == '-') ? -1 : 1, ch = getchar();
    while (isdigit(ch)) x = x * 10 + ch - 48, ch = getchar();
    x *= f;
}

int tc, n, m, ans = 1e9;
array<int, MAXN> a;
string s, t;

signed main() {
    std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cin >> s >> t;
    for (int i = 0; i < s.size(); i++) {
        if (i + t.size() > s.size()) break;
        int cnt = 0;
        for (int j = 0; j < t.size(); j++) {
            if (s[i + j] != t[j]) cnt++;
        }
        ans = min(ans, cnt);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3648
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <iomanip>

using namespace std;

template<class T> using vec = vector<T>;
template<class T> using vvec = vector<vector<T>>;
using ll = long long;
using ld = long double;

#define REP(i, s, e) for (ll i = (s); i < (e); ++i)

ll gcd(ll a, ll b)
{
    return b != 0 ? gcd(b, a % b) : a;
}

int main()
{
    cin.tie(0);
    
    ll A, B; cin >> A >> B;
    ll g = gcd(A, B);
    ll t = 1;
    for (ll i = 2; i * i <= g; ++i)
    {
        if (g % i != 0) continue;
        ++t;
        while (g % i == 0) g /= i;
    }
    if (g != 1) ++t;
    
    cout << t << endl;
    
    return 0;
}

Measured memory_bytes: 256
def read_input():
    n = int(input())
    top = list(map(int, input().split()))
    bottom = list(map(int, input().split()))

    return n, top, bottom


def submit():
    n, top, bottom = read_input()

    max_candies = 0
    for i in range(n):
        top_candies = sum(top[:i + 1])
        bottom_candies = sum(bottom[i:])

        total = top_candies + bottom_candies
        if total > max_candies:
            max_candies = total

    print(max_candies)


if __name__ == '__main__':
    submit()


Measured memory_bytes: 38384
#include <bits/stdc++.h>
#define repr(i,from,to) for(int (i)=(from);(i)<(to);(i)++)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
#define vprint(x) for(auto a:(x)) cout << x << endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) { a = b; return true;}
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) { a = b; return true;}
    return false;
}
int main(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m;
    cin>>n>>m;
    int a[n];
    int sum = 0;
    rep(i,n) {cin>>a[i];sum+=a[i];}
    int cnt = 0;
    rep(i,n) {
        if (a[i]*4*m>= sum) {
            cnt++;
        }
    }
    cout << ((cnt>=m) ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(c) c.begin(),c.end()
typedef long long ll;
const int N=110;
int n,k,x;
string s;
ll dp[N][100010];
ll w[N],v[N];
ll solve(int i,ll weight){
	if(i==n||weight>k){
		if(weight>k)return -1e11;
		return 0;
	}
	ll &res=dp[i][weight];
	if(res!=-1)return res;
	res = solve(i+1,weight+w[i])+v[i];
	res = max(res,solve(i+1,weight));
	return res;
}
int main(){

	scanf("%d%d",&n,&k);
	memset(dp,-1,sizeof dp);
	for(int i =0;i<n;i++){
		scanf("%I64d%I64d",&w[i],&v[i]);
	}
	printf("%lld\n",solve(0,0) );
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef complex<double> P;
typedef pair<int,int> pii;
#define REP(i,n) for(ll i=0;i<n;++i)
#define REPR(i,n) for(ll i=1;i<n;++i)
#define FOR(i,a,b) for(ll i=a;i<b;++i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define MOD (ll)(1e9+7)
#define ADD(a,b) a=((a)+(b))%MOD
#define FIX(a) ((a)%MOD+MOD)%MOD

int main(){
  float x;
  while(~scanf("%f",&x)){
    string s;
    if(x<=48.00) s="light fly";
    else if(x<=51.00) s="fly";
    else if(x<=54.00) s="bantam";
    else if(x<=57.00) s="feather";
    else if(x<=60.00) s="light";
    else if(x<=64.00) s="light welter";
    else if(x<=69.00) s="welter";
    else if(x<=75.00) s="light middle";
    else if(x<=81.00) s="middle";
    else if(x<=91.00) s="light heavy";
    else s="heavy";
    cout<<s<<endl;
  }
  return 0;
}

Measured memory_bytes: 1236
#include<bits/stdc++.h>
#define INF 1e9

using namespace std;

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

  for(int i=0;i < n;i++){
    cin >> a[i] >> a[i+1];
  }
  //dp[i][j] := iからj番目の行列積に必要なスカラー積の最小値
  int dp[105][105] = {};

  //init
  for(int i=0;i < n;i++){
    for(int j=0;j < n;j++){
      if(i == j) dp[i][j] = 0;//iからiまでは当然 0回
      else dp[i][j] = INF;
    }
  }
  
  for(int m = 0; m < n ;m++){
    for(int i = 0; i+m < n ;i++){
      int j = i+m;
      for(int k = i; k < j ;k++){
	dp[i][j] = min(dp[i][j], dp[i][k] + dp[k+1][j] + a[i]*a[k+1]*a[j+1]);
      }
    }
  }
  cout << dp[0][n-1] << endl;
  return 0;
}


Measured memory_bytes: 3164
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 
using vs = vector<string>;
using vvs = vector<vs>; 
using vc = vector<char>;
using vvc = vector<vc>; 
using vb = vector<bool>;
using vvb = vector<vb>; 

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define f(i,a,b) for(int i=a;i<b;i++)
#define pri(a)  printf("%.14lf\n",a);
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}
ll keta(ll x){
  ll n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}

ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;//繰り返し二乗法
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
ll kaijo(ll x){
  ll z=1;
  while(x>0){
    z *=x;
    z %=MOD;
    x--;
  }
  return z;
}
ll yakusu_num(ll n){
  vl yakusu(n+1,1);
  for(ll i=2;i*i<=n;i++){ 
    while(n%i==0){
      n /=i;
      yakusu[i]++;
    }
  }
  if(n!=1)yakusu[n]++;
  ll num=1;
  for(ll i=0;i <=n;i++){
    num*=yakusu[i];
  }
  return num;
}
int main(){
  ll N;cin>>N;
  vl a(N);rep(i,N)cin>>a[i];
  ll s=0;
  vl b(N);
  rep(i,N)s+=a[i];
  b[0] =s;
  for(int i=1 ; 2*i-1<N-1;i++){
    b[0]-=2*a[2*i-1];
  }
  for(int i=0;i<N-1;i++){
    b[i+1] =2*a[i]-b[i];
  }
  rep(i,N){
    cout<<b[i]<<" ";
  }
  cout<<endl;

  
  
    cout<<endl;

}

Measured memory_bytes: 2944
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <queue>
#include <stack>

using namespace std;

typedef long long int ll;
typedef pair<int, int> Pii;

const ll mod = 1000000007;

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

  int d, t, s;
  cin >> d >> t >> s;

  int f = t * s;
  if (f >= d) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 3620
package main

import (
	"bufio"
	"fmt"
	"log"
	"math"
	"os"
	"strconv"
	"strings"
)

func find(as []int, a int) int {
	for i, e := range as {
		if e == a {
			return i
		}
	}
	return -1
}

func main() {
	scanner := makeWordScanner()
	n := eGetInt(scanner)
	as := make([]int, n)
	for i := 0; i < n; i++ {
		as[i] = eGetInt(scanner)
	}
	t := 1
	idx := 0
	for idx < len(as) {
		next := find(as[idx:], t)
		if next == -1 {
			break
		}
		idx = idx + next
		t++
	}
	if t == 1 {
		fmt.Println("-1")
	} else {
		fmt.Println(len(as) - (t - 1))
	}
}

////////////////////////////////////////////////////////////////////////////////
// ライブラリ
////////////////////////////////////////////////////////////////////////////////
func makeScanner(maxByte int) *bufio.Scanner {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Buffer(make([]uint8, 0, 8192), maxByte)
	return scanner
}
func makeCharScanner() *bufio.Scanner {
	scanner := makeScanner(8192)
	scanner.Split(bufio.ScanRunes)
	return scanner
}
func makeWordScanner() *bufio.Scanner {
	scanner := makeScanner(8192)
	scanner.Split(bufio.ScanWords)
	return scanner
}
func eGetLine(r *bufio.Scanner) string {
	if r.Scan() {
		return r.Text()
	}
	err := r.Err()
	if err != nil {
		log.Fatal(err)
	}
	// EOF
	return ""
}
func eGetInt(r *bufio.Scanner) int {
	line := eGetLine(r)
	return eAtoi(line)
}
func eGetInt64(r *bufio.Scanner) int64 {
	line := eGetLine(r)
	return eAtoInt64(line)
}
func eGetFields(r *bufio.Scanner) []string {
	line := eGetLine(r)
	return strings.Fields(line)
}
func eGetInts(r *bufio.Scanner) []int {
	fields := eGetFields(r)
	ints := make([]int, len(fields))
	for i := 0; i < len(ints); i++ {
		ints[i] = eAtoi(fields[i])
	}
	return ints
}
func eGetInt64s(r *bufio.Scanner) []int64 {
	fields := eGetFields(r)
	ints := make([]int64, len(fields))
	for i := 0; i < len(ints); i++ {
		ints[i] = eAtoInt64(fields[i])
	}
	return ints
}
func eGetChars(r *bufio.Scanner) []string {
	line := eGetLine(r)
	return strings.Split(line, "")
}
func eAtoi(s string) int {
	n, err := strconv.Atoi(s)
	if err != nil {
		log.Fatal(err)
	}
	return n
}
func eAtoInt64(s string) int64 {
	n, err := strconv.ParseInt(s, 10, 64)
	if err != nil {
		log.Fatal(err)
	}
	return n
}
func pow(a, n int) int {
	return int(math.Pow(float64(a), float64(n)))
}
func countBitOfOn(i, numbits int) int {
	count := 0
	var bit uint64
	for bit = 0; bit < uint64(numbits); bit++ {
		t := 1 << bit
		if i&t > 0 {
			count++
		}
	}
	return count
}


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

#define     fast()              ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); 
#define     ll                  long long int
#define     test()              ll t; cin>>t; while(t--) 
#define     lp0(i,begin,end)    for(ll i=begin;i<end;i++)
#define     lp1(i,begin,end)    for(ll i=begin;i<=end;i++)
#define     rlp(i,begin,end)    for(ll i=end;i>=begin;i--)
#define     prec(n)             fixed<<setprecision(n)
#define     initial(a,i)        memset(a,i,sizeof(a))
#define     pb                  push_back
#define     PI                  3.1415926535897932384626433832795
#define     MOD                 1000000007
#define     F                   first
#define     S                   second
#define     all(a)              (a).begin(),(a).end()
#define     BPC(x)              __builtin_popcountll(x)
#define     gcd(a,b)            __gcd(a,b)

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

ll power(ll x,ll n)
{
    ll result = 1;
    while (n)
    {
        if (n & 1)
            result = result * x;
        n = n / 2;
        x = x * x;
    }
    return result;
}


// Solution Function
void solution(ll compte)
{
    // cout<<compte<<"\n";
    ll k;
    cin>>k;
    ll s,w;
    cin>>s>>w;
    for(ll i=s;i<w+1;i++)
    {
      if(i%k==0)
      {
        puts("OK");
        return;
      }
    }
    cout<<"NG\n";  
}
// Driver Function
int main()
{
    ll compte = 1;
    //test()
    //{
        solution(compte);
        compte++;
    //}
    return 0;
}


Measured memory_bytes: 3596
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <math.h>
#include <algorithm>
using namespace std;
#define ll long long
const double EPS = 1e-10;
const ll MOD = 7+(1e+9);

int main (){
  ll n,q;
  string s;
  cin>>n>>q;
  cin>>s;
  vector<ll>l(q,0);
  vector<ll>r(q,0);
  for(ll i=0;i<q;i++){
    cin>>l[i]>>r[i];
    l[i]--;
    r[i]--;
  }
  vector<ll>v(n,0);
  ll f=0;
  if(s[0]=='A'){
    f=1;
  }
  for(ll i=1;i<n;i++){
    if(s[i]=='A'){
      f=1;
      v[i]=v[i-1];
      continue;
    }
    if(f==1&&s[i]=='C'){
      f=0;
      v[i]=v[i-1]+1;
      continue;
    }
    f=0;
    v[i]=v[i-1];
  }
  for(ll i=0;i<q;i++){
    ll ans=v[r[i]]-v[l[i]];
    // if(v[r[i]]=='C'&&r[i]-1>0&&r[i]!=l[i]&&v[l[i]]=='A'){
    //   ans--;
    // }
    if(ans<0)ans=0;
    cout<<ans<<endl;
  }
}


Measured memory_bytes: 3456
#include<string>
#include<stdio.h>
#include<climits>
#include<iostream>
#include<math.h>
#include<algorithm>
using namespace std;
typedef long long ll;
struct node{
    char x;
    ll y;
};
struct node ai[100005],bi[100005];
ll gcd(ll a,ll b)
{
    return b==0?a:gcd(b,a%b);
}
int main()
{
    ll n,m; cin>>n>>m;
    string a,b; cin>>a>>b;
    ai[0].y = 1; ai[0].x = a[0];
    bi[0].y = 1; bi[0].x = b[0];
    for(ll i=1;i<n;i++)
    {
        ll t = m*i + 1;
        ai[i].y = t; ai[i].x = a[i];
    }
    for(ll i=1;i<m;i++)
    {
        ll t = n*i + 1;
        bi[i].y = t; bi[i].x = b[i];
    }
    int flag = 0;
    if(n<=m){
        for(ll i=0;i<n;i++)
        {
            ll q = ai[i].y; char w = ai[i].x;
           // printf("%d %c%c\n",q,w);
            for(ll j=i;j<m;j++){
                if(bi[j].y<=q)
                {
                    if(bi[j].y==q&&bi[j].x!=w)
                    {
                        flag = 1;
                        break;
                    }
                }
                else {
                    break;
                }
            }
            if(flag == 1)
                break;
        }
    }
    else {
        for(ll i=0;i<m;i++)
        {
            ll q = bi[i].y; char w = bi[i].x;
           // printf("%d %c%c\n",q,w);
            for(ll j=i;j<n;j++){
                if(ai[j].y<=q)
                {
                    if(ai[j].y==q&&ai[j].x!=w)
                    {
                        flag = 1;
                        break;
                    }
                }
                else {
                    break;
                }
            }
            if(flag == 1)
                break;
        }

    }
    if(flag==1){
        printf("-1\n");
    }
    else {
        printf("%lld\n",n*m/gcd(n,m));
    }
    return 0;
}


Measured memory_bytes: 3072
#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<vector>
#include<utility>
#define FOR(i, a, b) for(int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define MOD 1000000007

using namespace std;


int main(void) {
	int sx, sy, tx, ty;
	cin >> sx >> sy >> tx >> ty;
	FOR(i, sx, tx - 1) {
		cout << "R";
	}
	FOR(i, sy, ty - 1) {
		cout << "U";
	}
	cout << "R";
	FOR(i, 1, ty - sy+1) {
		cout << "D";
	}

	FOR(i, 1, tx - sx + 1) {
		cout << "L";
	}
	cout << "U";
	FOR(i, 1, ty - sy) {
		cout << "U";
	}

	FOR(i, 1, tx - sx) {
		cout << "R";
	}
	cout << "U";
	FOR(i, 1, tx - sx + 1) {
		cout << "L";
	}
	FOR(i, 1, ty - sy + 1) {
		cout << "D";
	}
	cout << "R";
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var a, b int
	_, _ = fmt.Scan(&a, &b)
	
	answer := 0
	n := 1
	
	for {
		if n >= b {
			break
		} else {
			answer++
			n += a - 1
		}
	}
	
	fmt.Println(answer)
}


Measured memory_bytes: 512
n=int(input())
*A,=map(int,input().split())

cnt = [0]*n
for i,a in enumerate(A):
    a -= 1
    if cnt[a] == 0:
        cnt[a] = i+1
    else:
        N = i-cnt[a] #同じ数に挟まれている数字の数

p = 10**9+7
fac = [1]*n
inv = [1]*n
finv = [1]*n
for i in range(2,n):
    fac[i] = (fac[i-1]*i) %p
    inv[i] = (-inv[p%i]*(p//i)) %p
    finv[i] = (finv[i-1]*inv[i]) %p
def comb(n,k):
    if n<k : return 0
    if n<0 or k<0 : return 0
    return fac[n]*(finv[k]*finv[n-k]%p)%p

for k in range(1,n+1):
    print((comb(n-1,k)+comb(n-1,k-2)+(comb(n-1,k-1)*2-comb(n-1-N,k-1)))%p)
print(1)

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

INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())
MAP = lambda: map(int, INPUT().split())
S_MAP = lambda: map(str, INPUT().split())
LIST = lambda: list(map(int, INPUT().split()))
S_LIST = lambda: list(map(str, INPUT().split()))
ZIP = lambda: zip(*(MAP() for _ in range(n)))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7


def theta(h, m):
    mr = m*6
    hr = h*30 + m/2

    if hr > mr:
        if hr - mr < 180:
            rad = radians(hr - mr)
        else:
            rad = radians(360 - hr + mr)
    else:
        if hr - mr < 180:
            rad = radians(mr - hr)
        else:
            rad = radians(360 - mr + hr)
    
    return rad


def main():
    A, B, H, M = MAP()

    print(sqrt(A**2 + B**2 - 2 * A * B * cos(theta(H, M)))) 


if __name__ == '__main__':
    main()


Measured memory_bytes: 10376
#include "bits/stdc++.h"
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define FOR(i,init,a) for(int i=init; i<a; i++)
#define rep(i,a) FOR(i,0,a)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()
#define chmin(a,b) a=min(a,b);
#define chmax(a,b) a=max(a,b);

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

int nxt[200009][26], n[26], len[200009], chr[200009];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    string s;
    cin>>s;
    int N=s.size();
    
    rep(i,26) n[i]=N+1;
    rrep(i,N){
        len[i]=INF;
        rep(j,26){
            nxt[i][j]=n[j];
            if(len[i]>len[n[j]]){
                len[i]=len[n[j]];
                chr[i]=j;
            }
        }
        len[i]++;
        if(i) n[s[i-1]-'a']=i;
    }
    
    string ans;
    int cur=0;
    while(cur<N+1){
        ans+='a'+chr[cur];
        cur=nxt[cur][chr[cur]];
    }
    cout1(ans)
}

Measured memory_bytes: 22420
#include <stdio.h>
#include <stdlib.h>
int int_sort(const void * a, const void * b)
{
    if(*(int*)a<*(int*)b)
    {
        return -1;
    }
    else if(*(int*)a==*(int*)b)
    {
        return 0;
    }
    return 1;
}
int main(void)
{
    int n;
    scanf("%d",&n);
    int d[n];
    for(int p=0;p<n;p++)scanf("%d",&d[p]);
    qsort(d,n,sizeof(d[1]),int_sort);
    int c=0;
    int check=0;
    int ans=0;
    while(c!=n)
    {
        if(check!=d[c])
        {
            ans++;
            check=d[c];
        }
        c++;
    }
    printf("%d",ans);
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define RI register int
typedef long long LL;

#define FILEIO(name) freopen(name".in", "r", stdin), freopen(name".out", "w", stdout);

using namespace std;

char buf[1000000], *p1 = buf, *p2 = buf;
inline char gc() {
  if (p1 == p2) p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin);
  return p1 == p2 ? EOF : *(p1++);
}
template <class T> inline void read(T &n) {
  n = 0; RI ch = gc(), f;
  while ((ch < '0' || ch > '9') && ch != '-') ch = gc();
  f = (ch == '-' ? ch = gc(), -1 : 1);
  while (ch >= '0' && ch <= '9') n = n * 10 + (ch ^ 48), ch = gc();
  n *= f;
}

int vis[25][25];
char s[25][25];
int x[4] = {0, 1, 0, -1};
int y[4] = {1, 0, -1, 0};
struct node { int x, y; } q[25 * 25];
int h, w;

int Solve(int a, int b, int c, int d) {
  if (s[a][b] == '#' || s[c][d] == '#') return 0;
  memset(vis, 0, sizeof(vis));
  vis[a][b] = 1;
  int head = 1, tail = 0;
  q[++tail] = (node){a, b};
  while (head <= tail) {
    node t = q[head++];
    for (RI i = 0; i < 4; ++i) {
      if (t.x + x[i] >= 1 && t.x + x[i] <= h && t.y + y[i] >= 1 && t.y + y[i] <= w)
        if (!vis[t.x + x[i]][t.y + y[i]] && s[t.x + x[i]][t.y + y[i]] != '#')
          vis[t.x + x[i]][t.y + y[i]] = vis[t.x][t.y] + 1, q[++tail] = (node){t.x + x[i], t.y + y[i]};
    }
  }
    return vis[c][d] - 1;
}

int main() {
  
#ifdef LOCAL
  FILEIO("a");
#endif

  cin >> h >> w;
  for (RI i = 1; i <= h; ++i)
    cin >> (s[i] + 1);
  int ans = 0;
  for (RI i = 1; i <= h; ++i)
    for (RI j = 1; j <= w; ++j)
      for (RI k = 1; k <= h; ++k)
        for (RI l = 1; l <= w; ++l)
          ans = max(ans, Solve(i, j, k, l));
  printf("%d\n", ans);

  return 0;
}

Measured memory_bytes: 384
import math
def main():
    N = int(input())
    K = 0
    X = 0
    Y = 0
    R = 90

    while True:
        R = (N+R)%360
        K+=1
        X += math.cos(math.radians(R))
        Y += math.sin(math.radians(R))
        if abs(X)<0.0005 and abs(Y)<0.0005:
            print(K)
            break

if __name__ == '__main__':
    main()

Measured memory_bytes: 62432