akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
 int main( ) {
  int W, H, x, y, r;
  scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);
  if (W >= (x + r) && 0 <= (x - r)) {
    if (H >= (y + r) && 0 <= (y - r)) {
      printf("Yes\n");
    }
    else {
      printf("No\n");
    }
  }
  else {
    printf("No\n");
  }
   return 0;
}

Measured memory_bytes: 1828
#include <stdio.h>
#define MAX 105
int main(){

  int i,j,n,u,k,v,A[MAX][MAX];
  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      A[i][j]=0;

    }
  }
  for(i=0;i<n;i++){
  scanf("%d %d",&u,&k);
  for(j=0;j<k;j++){
    scanf("%d",&v);
    A[u-1][v-1]=1;
  }
  }
   for(i=0;i<n;i++){
    for(j=0;j<n-1;j++){
      printf("%d ",A[i][j]);
    }
    printf("%d\n",A[i][n-1]);
  }
  
  return 0;
}



Measured memory_bytes: 2108
// finish date: 2018/07/07
#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>>
        vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<double> vd;
typedef vector<vector<double>> vvd;
typedef vector<vector<vector<double>>>
        vvvd;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
const int bigmod = 1000000007;
const int INF = 1050000000;

vl dijkstra(int s, int V, vector<vector<pli>> edge) {
    vl dist(V, LONG_LONG_MAX / 4); //INFの値がこれでいいか確認するべき
    vb used(V, false);
    priority_queue<pli, vector<pli>, greater<pli>> pq;
    pq.push(pli(0, s));
    while (!pq.empty()) {
        ll d;
        int t;
        tie(d, t) = pq.top();
        pq.pop();
        if (used[t]) continue;
        used[t] = true;
        dist[t] = d;
        for (pli e:edge[t]) {
            if (dist[e.second] < d + e.first) continue;
            pq.push(pli(d + e.first, e.second));
        }
    }
    return dist;
}

int main() {
    int n, m, s, t;
    cin >> n >> m >> s >> t;
    s--;
    t--;
    vector<vector<pli>> yen(n);
    vector<vector<pli>> snuke(n);
    rep(i, m) {
        int u, v, a, b;
        cin >> u >> v >> a >> b;
        u--;
        v--;
        yen[u].push_back(pli(a, v));
        yen[v].push_back(pli(a, u));
        snuke[u].push_back(pli(b, v));
        snuke[v].push_back(pli(b, u));
    }
    vl distY = dijkstra(s, n, yen);
    vl distS = dijkstra(t, n, snuke);
    vl ans(n, 0);
    for (int i = n - 1; i >= 0; i--) {
        ans[i] = distY[i] + distS[i];
        if (i != n - 1) ans[i] = min(ans[i], ans[i + 1]);
    }
    rep(i, n) {
        cout << (ll) (round(pow(10, 15))) - ans[i] << endl;
    }
    return 0;
}



Measured memory_bytes: 26676
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1155&lang=jp

#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<cmath>
#include<climits>
#include<ctime>
#include<cstring>
#include<numeric>
#include<stack>
#include<queue>

#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;

using namespace std;

int NOT(int x){ return 2-x; }
int AND(int x, int y){ return min(x,y); }
int OR(int x, int y){ return max(x,y); }
bool is_operator(char op){
	return (op == '-' || op == '*' || op == '+');
}

string postfix(string fml)
{
	string res="";
	stack<char> st;
	queue<char> que;
	rep(i, fml.size())
	{
		if(is_operator(fml[i])){
			while(!st.empty()){
				if(!is_operator(st.top())) break;
				if(fml[i] == '-') break;
				que.push(st.top());
				st.pop();
			}
			st.push(fml[i]);
		}
		else if(fml[i] == '('){
			st.push(fml[i]);
		}
		else if(fml[i] == ')'){
			while(!(st.top() == '(')){
				que.push(st.top());
				st.pop();
			}
			st.pop();
		}
		else{
			que.push(fml[i]);
		}
	}

	while(!st.empty()){
		que.push(st.top());
		st.pop();
	}

	while(!que.empty()){
		res += que.front();
		que.pop();
	}
	return res;
}

int solve(int p, int q, int r, string fml)
{
	int res=0;
	stack<int> st;
	rep(i,fml.size())
	{
		if(fml[i] == 'P'){
			st.push(p);
		}
		else if(fml[i] == 'Q'){
			st.push(q);
		}
		else if(fml[i] == 'R'){
			st.push(r);
		}
		else if(isdigit(fml[i])){
			st.push(fml[i]-'0');
		}
		else if(fml[i] == '-'){
			int x = st.top();
			st.pop();
			st.push(NOT(x));
		}
		else if(fml[i] == '*'){
			int x = st.top(); st.pop();
			int y = st.top(); st.pop();
			st.push(AND(x,y));
		}
		else if(fml[i] == '+'){
			int x = st.top(); st.pop();
			int y = st.top(); st.pop();
			st.push(OR(x,y));
			
		}
	}

	return (st.top() == 2) ? 1 : 0;
}

int main()
{
	string formula;
	while(cin >> formula)
	{
		if(formula == ".") break;

		formula = postfix(formula);

		int ans=0;
		rep(p,3){
			rep(q,3){
				rep(r,3){
					ans += solve(p,q,r,formula);
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1208
#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std ;
#define N 15
int main()
{
    int n,m=1,i,j;
    char x[15];
    long long sum=0,a;
    scanf("%s",x);
    n=strlen(x);
    for(i=0;i<n-1;i++)
    {
        m=m*2;
    }
    for(i=0;i<m;i++)
    {
        a=x[0]-'0';
        for(j=0;j<n;j++)
        {
            if(j==n-1||i&1<<j)
            {
            sum=sum+a;
            a=0;
            if(j==n-1) break;
            }
            a=a*10;
            a=a+x[j+1]-'0';
        }
    }
    printf("%lld",sum);
    return 0;
}



Measured memory_bytes: 128
/*
 * src.cpp
 *
 *  Created on: 2016/08/08
 *      Author: joi
 */

#include <bits/stdc++.h>

using namespace std;

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

const int MAX_N=65000;

typedef long long ll;

int N;
int P[MAX_N];
int J[MAX_N-1];

int main(){
	do{
		scanf("%d",&N);
		if (N){
			ll sum=0;
			REP(i,N){
				scanf("%d",&P[i]);
				sum+=P[i];
			}
			REP(i,N-1){
				scanf("%d",&J[i]);
			}
			sort(J,J+N-1);
			ll ans=sum*N;
			FOR(i,1,N){
				sum+=J[N-i-1];
				ans=max(ans,sum*(N-i));
			}
			printf("%lld\n",ans);
		}
	}while (N);
	return 0;
}

Measured memory_bytes: 1712
n = int(input())
nums = list(map(int, input().split()))

count = 0
for i in range(n):
    for j in range(n - 1, i, -1):
        if nums[j] < nums[j - 1]:
            nums[j - 1], nums[j] = nums[j], nums[j - 1]
            count += 1

print(' '.join(map(str, nums)))
print(count)



Measured memory_bytes: 5600
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <stack>
#include <set>
#include <bitset>
#include <functional>
using namespace std;
#define fast_io ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define MOD (long long int)(1e9+7)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;

ll mpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = mpow(a,b/2); return memo*memo%MOD;}
  else return mpow(a,b-1) * a % MOD;
}
ll lpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = lpow(a,b/2); return memo*memo;}
  else return lpow(a,b-1) * a;
}
ll gcd(ll a, ll b){
  if(b==0) return a;
  else return gcd(b, a%b);
}
vector<ll> kaijo_memo;
ll kaijo(ll n){
  if(kaijo_memo.size() > n) return kaijo_memo[n];
  if(kaijo_memo.size() == 0) kaijo_memo.push_back(1);
  while(kaijo_memo.size() <= n) kaijo_memo.push_back(kaijo_memo[kaijo_memo.size()-1] * kaijo_memo.size() % MOD);
  return kaijo_memo[n];
}
vector<ll> gyaku_kaijo_memo;
ll gyaku_kaijo(ll n){
  if(gyaku_kaijo_memo.size() > n) return gyaku_kaijo_memo[n];
  if(gyaku_kaijo_memo.size() == 0) gyaku_kaijo_memo.push_back(1);
  while(gyaku_kaijo_memo.size() <= n) gyaku_kaijo_memo.push_back(gyaku_kaijo_memo[gyaku_kaijo_memo.size()-1] * mpow(gyaku_kaijo_memo.size(), MOD-2) % MOD);
  return gyaku_kaijo_memo[n];
}

ll nCr(ll n, ll r){
  if(n == r) return 1;//0個の丸と-1個の棒みたいな時に時に効く？不安.
  if(n < r || r < 0) return 0;
  ll ret = 1;
  if(n <= 1e7){
    ret *= kaijo(n); ret %= MOD;
    ret *= gyaku_kaijo(r); ret %= MOD;
    ret *= gyaku_kaijo(n-r); ret %= MOD;
  }else{
    rep(i,r){
      ret *= n-i; ret %= MOD;
      ret *= mpow(r-i, MOD-2); ret %= MOD;
    }
  }
  return ret;
}

int main(void){
  fast_io
  cout<<fixed<<setprecision(15);
  ll a,b,c;cin>>a>>b>>c;
  if(4 * a * b < (c - a - b) * (c - a - b) && c - a - b >= 0){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
}

Measured memory_bytes: 256
var
	n,ans:Longint;
procedure f(x:int64;a,b,c:Boolean);
begin
	if x>n then exit;
	if a and b and c then inc(ans);
	f(x*10+3,True,b,c);
	f(x*10+5,a,True,c);
	f(x*10+7,a,b,True);
end;
begin
	read(n);
	f(0,False,False,False);
	writeln(ans);
end.

Measured memory_bytes: 128
def myfunc(A, B):
    def resfunc(x):
        if A <= sum(map(int,list(str(x)))) <=B:
            return x
        else:
            return 0
    return resfunc

N, A, B = map(int, input().split())
print(sum(map(myfunc(A,B), range(1, N+1))))

Measured memory_bytes: 9044
# 解説PDF
from collections import deque

k = int(input())

que = deque([1, 2, 3, 4, 5, 6, 7, 8, 9])

for i in range(k-1):
    x = que.popleft()
    y = x % 10  
    if y != 0:
        que.append(10*x+y-1)
    que.append(10*x+y)
    if y != 9:
        que.append(10*x+y+1)

ans = que.popleft()
print(ans)

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

int inversion_number(vector<int> &a) {
  int n = a.size();
  if (n <= 1) return 0;

  vector<int> b(a.begin(), a.begin() + n / 2);
  vector<int> c(a.begin() + n / 2, a.end());

  int cont = 0;
  cont += inversion_number(b);
  cont += inversion_number(c);

  int ai = 0, bi = 0, ci = 0;
  while (ai < n) {
    if (bi < b.size() && (ci == c.size() || b[bi] <= c[ci])) {
      a[ai++] = b[bi++];
    } else {
      cont += n / 2 - bi;
      a[ai++] = c[ci++];
    }
  }

  return cont;
}

int calc(string from, string to) {
  int N = from.size();

  queue<int> cidx[26];
  for (int i = 0; i < N; i++) {
    cidx[from[i] - 'a'].push(i);
  }

  vector<int> idx(N);
  for (int i = 0; i < N; i++) {
    idx[i] = cidx[to[i] - 'a'].front();
    cidx[to[i] - 'a'].pop();
  }

  return inversion_number(idx);
}

signed main() {
  string s;
  cin >> s;

  int cnt[26] = {};
  for (int i = 0; i < s.size(); i++) {
    cnt[s[i] - 'a']++;
  }

  int odd = 0;
  for (int i = 0; i < 26; i++) {
    if (cnt[i] % 2) {
      odd++;
    }
  }

  if (odd > 1) {
    cout << -1 << endl;
    return 0;
  }

  int app[30] = {};
  string A;
  for (auto c : s) {
    if (app[c - 'a'] < cnt[c - 'a'] / 2) {
      A.push_back(c);
      app[c - 'a']++;
    }
  }

  string B = A;

  for (int i = 0; i < 26; i++) {
    if (cnt[i] % 2) {
      B.push_back((char)('a' + i));
    }
  }

  reverse(B.begin(), B.end());
  A += B;

  cout << calc(s, A) << endl;
  return 0;
}


Measured memory_bytes: 6016
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
struct point{ double x,y; };
void solve(int n,point left,point right){
  if(n==0) return ;
  double t=M_PI/3;
  point midleft; midleft.x=(right.x+left.x*2)/3; midleft.y=(right.y+left.y*2)/3;
  point midright; midright.x=(right.x*2+left.x)/3; midright.y=(right.y*2+left.y)/3;
  point mid;
  mid.x=(midright.x-midleft.x)*cos(t)-(midright.y-midleft.y)*sin(t)+midleft.x;
  mid.y=(midright.x-midleft.x)*sin(t)+(midright.y-midleft.y)*cos(t)+midleft.y;
  solve(n-1,left,midleft);
  printf("%.6f %.6f\n",midleft.x,midleft.y);
  solve(n-1,midleft,mid);
  printf("%.6f %.6f\n",mid.x,mid.y);
  solve(n-1,mid,midright);
  printf("%.6f %.6f\n",midright.x,midright.y);
  solve(n-1,midright,right);
}
int main(){
  int n; cin>>n;
  point left={0,0},right={100,0};
  printf("%.6f %.6f\n",left.x,left.y);
  solve(n,left,right);
  printf("%.6f %.6f\n",right.x,right.y);
  return 0;
}



Measured memory_bytes: 3228
n = int(input()) 
alllist=[]
for i in range(n):
    s,p = input().split()
    q=i+1
    relist=[]
    relist.append(str(s))
    relist.append(int(p))
    relist.append(int(i+1))
    alllist.append(relist)
alllist.sort(key=lambda x:x[1],reverse=True)
alllist.sort(key=lambda x:x[0])
for i in range(len(alllist)):
    print(alllist[i][2])

Measured memory_bytes: 3064
#include<stdio.h>

void trace(int A[], int N) {
  int i;
  for ( i = 0; i < N; i++ ) {
    if ( i > 0 ) printf(" ");
    printf("%d", A[i]);
  }
  printf("\n");
}

void bubbleSort(int A[], int N){
  int flag, i, j, k, m;
  flag = 1;
  i = 0;
  m = 0;
  while (flag) {
    flag = 0;
    for ( j = N-1; j > i; j-- ){
      if ( A[j] < A[j - 1]){
	k = A[j];
	A[j] = A[j - 1];
	A[j - 1] = k;
	flag = 1;
	m++;
      }
    }
    i++;
  }
  trace(A, N);
  printf("%d\n", m);
}

int main(){
  int N, i, j;
  int A[100];

  scanf("%d", &N);
  for ( i = 0; i < N; i++ ) scanf("%d", &A[i]);

  bubbleSort(A, N);

  return 0;
}



Measured memory_bytes: 2100
#include<bits/stdc++.h>
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>;
*/typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> pl;
typedef pair<int,int> pii;

#define LOCAL 0
#define dbg(x) cout << #x << " is " << x << "\n"
#define gll(x) scanf("%d",&x)
#define gll2(x,y) scanf("%d%d",&x,&y)
#define gll3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define gllarr(arr,n) f(i,n) gll(arr[i]);
#define sz(x) ((int)x.size())
#define s(x) sort(x.begin(),x.end())
#define all(v) v.begin(),v.end()
#define rs(v) { s(v) ; r(v) ; }
#define r(v) {reverse(all(v));}
#define pb push_back
#define f(i,n) for(int i=0;i<n;i++)
#define fr(i,n) for(int i=n-1;i>=0;i--)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)

const ll mod = (ll)1e9 + 7;
const ll inf = (ll)1e16;
const ld eps = 1e-12;
const ll N = (int)1e5 + 5;
const ll LOGN = 19;
const ld PI = 3.14159265358979323846;
inline ll mul(ll a, ll b, ll m = mod) { return (ll)(a * b) % m;}
inline ll add(ll a, ll b, ll m = mod) { a += b; if(a >= m) a -= m; if(a < 0) a += m; return a;}
inline ll power(ll a, ll b, ll m = mod) { if(b == 0) return 1; if(b == 1) return (a % m); ll x = power(a, b / 2, m); x = mul(x, x, m); if(b % 2) x = mul(x, a, m); return x;}

int n;
int a[N], b[N], c[N];
ll dp[N][3];

ll rec(int pos, int prev){
    if(pos >= n) return 0;
    if(prev != -1 && dp[pos][prev] != -1)
        return dp[pos][prev];
    ll A = LLONG_MIN, B = LLONG_MIN, C = LLONG_MIN;
    if(prev != 0) A = rec(pos + 1, 0) + a[pos];
    if(prev != 1) B = rec(pos + 1, 1) + b[pos];
    if(prev != 2) C = rec(pos + 1, 2) + c[pos];
    ll to = max({A, B, C});
    if(prev != -1) dp[pos][prev] = to;
    return to;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    if (LOCAL) {
        freopen("C:\\Users\\Dishant\\Desktop\\Collection-DEV c++\\input.txt", "r", stdin);
        freopen("C:\\Users\\Dishant\\Desktop\\Collection-DEV c++\\output.txt", "w", stdout);
    }
    cin>>n;
    f(i, n) cin>>a[i]>>b[i]>>c[i];
    f(i, n){
        f(j, 3) dp[i][j] = -1;
    }
    cout<<rec(0, -1);
    return 0;
}

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

int main() {
	int n;  cin >> n;
	vector<int> h(n + 1); rep(i, 0, n) cin >> h[i];

	int ans = 0, com = 0;
	rep(i, 0, n - 1) {
		ans += h[i];
		com = h[i];
		rep(j, i + 1, n) {
			if (com >= h[j]) {
				com = h[j];
				h[j] = 0;
			}
			else h[j] -= com;
		}
	}
	
	cout << ans + h[n - 1] << endl;
	
	return 0;
}

Measured memory_bytes: 256
using System;

public class hello
{
    public static void Main()
    {
        var ary = new char[8, 8];
        for (int i = 0; i < 8; i++)
        {
            var s = Console.ReadLine().Trim();
            for (int j = 0; j < 8; j++)
                ary[i, j] = s[j];
        }
        Console.WriteLine(90);
        for (int i = 0; i < 8; i++)
            for (int j = 7; j >= 0; j--)
            {
                Console.Write(ary[j, i]);
                if (j == 0) Console.WriteLine();
            }
        Console.WriteLine(180);
        for (int i = 7; i >= 0; i--)
            for (int j = 7; j >= 0; j--)
            {
                Console.Write(ary[i, j]);
                if (j == 0) Console.WriteLine();
            }
        Console.WriteLine(270);
        for (int i = 7; i >= 0; i--)
            for (int j = 0; j < 8; j++)
            {
                Console.Write(ary[j, i]);
                if (j == 7) Console.WriteLine();
            }
    }
}

Measured memory_bytes: 9092
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define mod 1000000007
#define mod2 1000000000
#define mod1 998244353
#define lol ios_base::sync_with_stdio(false);cin.tie(NULL);
#define all(x) (x).begin(), (x).end()
#define F(i, n) for (ll (i) = 0; (i) < (n); (i)++)
#define pb push_back
#define pf push_front
#define mp make_pair
#define f first
#define ss second

ll vi[1000001]={0};
int main()
{
    ll n;cin >> n;
    ll arr[n];
    map<ll,ll> m1; 
    for(ll i=0;i<n;i++)
    {
        cin >> arr[i];
        m1[arr[i]]++;
    }
    sort(arr,arr+n);
    for(ll i=0;i<n;i++)
    {
        if(i>0 && arr[i]==arr[i-1]) continue;
        for(ll j=2*arr[i];j<=1000000;j=j+arr[i])
        {
            vi[j] = 1;
        }
        if(arr[i]==1) break;
    }
    ll cnt = 0;
    for(ll i=0;i<n;i++)
    {
        if(vi[arr[i]] == 0 && m1[arr[i]]==1)
        {
            cnt++;
        }
    }
    cout << cnt << endl; 
}
    

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

#define rep(i,j,n) for(int i=j;i<n;++i)
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(), i.rend()
#define INF 1e9
#define LINF 1e18
const int mod = 1e9 + 7;

typedef long long i64;
typedef pair<int, int> pi;

template <class T> using vt = vector<T>;
template <class T> using vvt = vector<vector<T>>;

i64 gcd(i64 n, i64 m) {return (m == 0? n : gcd(m, n % m));}
i64 lcd(i64 n, i64 m) {return (n / gcd(n, m) * m);}
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

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

  int n;
  string s;
  cin >> n >> s;

  vt<int> cnt(n + 1, 0);
  rep(i, 0, n) {
    cnt[i + 1] = cnt[i] + (s[i] == '#');
  }
  int ans = cnt[n], white = 0;
  for(int i = n - 1; i >= 0; --i) {
    if(s[i] == '.') white++;
    ans = min(ans, cnt[i] + white);
  }
  cout << ans << endl;
}

Measured memory_bytes: 1428
a,b,n = map(int,input().split())
p = (n+1)//b
c = p*b-1
if c < 0:
  print(a*n//b-a*(n//b))
  exit()
ans = max(a*n//b-a*(n//b),a*c//b-a*(c//b))
print(ans)

Measured memory_bytes: 9184
import java.util.Scanner;

/**
 * Unification
 *
 */
public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    String[] target = scanner.nextLine().split("");
    int numOfZero = 0;
    int numOfOne = 0;
    
    for (String s : target) {
      if ("0".equals(s)) numOfZero++;
      if ("1".equals(s)) numOfOne++;
    }
    
    
    if (numOfOne >= numOfZero) {
      System.out.println(2 * numOfZero);
    } else {
      System.out.println(2 * numOfOne);
    }
  }
}

Measured memory_bytes: 34292
#include<bits/stdc++.h>
using namespace std;
int main(void){
  int a,b,c;
  cin >> a >> b >> c;
  int max = a<b?b:a;
  int min = a<b?a:b;
  if(min < c && c < max){
    cout << "Yes";
  }else{
    cout << "No";
  }
  return 0;
}


Measured memory_bytes: 256
#include "iostream"
#include "vector"
#include "string"
#include "algorithm"
 
using namespace std;
typedef long long ll;
 
int main()
{
  string s;
  cin >> s;
  ll size = s.size();
  ll count = 0;
  ll ans = 0;
  for (ll i = 0; i < size; i++)
  {
    if (s[i] == 'W')
    {
      count++;
      ans += i + 1 - count;
    }
  }
  cout << ans << "\n";
}

Measured memory_bytes: 640
m,d=map(int,input().split())
month = [i for i in range(1,m+1)]
ct=0
if d<10:
  print(0)
  exit()
for i in range(11,d+1):
  a=int(str(i)[0])
  b=int(str(i)[1])
  if a*b in month and a>=2 and b>=2:
    ct+=1
print(ct)


Measured memory_bytes: 3060
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define false 0
#define true 1
int isPrime(int);
int main()
{
  int n,*array,i,count = 0;

  scanf("%d",&n);
  array = (int *)malloc(n * sizeof(int));

  for(i = 0 ; i < n ; i++) scanf("%d",&array[i]);

  for(i = 0 ; i < n ; i++){
    if(isPrime(array[i]) == true) count++; }

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

  return 0;
}

int isPrime(int x){
  int i;
  if(x == 2) return true;

  if(x < 2 || x%2 == 0) return false;

  i = 3;
  while(i <= sqrt(x)){
    if(x%i == 0) return false;
    i = i + 2; }

  return true;
}



Measured memory_bytes: 2060
#include <iostream>
#include <bitset>
#include <string>
#include <vector>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)

int main()
{
    int H,W,k,ans=0;
    cin>>H>>W>>k;
    vector<string> c(H);
    rep(k,H) cin>>c[k];
    rep(bith,1<<H) rep(bitw,1<<W)
    {
        int count=0;
        rep(h,H) rep(w,W)
        {
            if((bith>>h)&1) continue;
            if((bitw>>w)&1) continue;
            if(c[h][w]=='#') count++;
        }
        if(count==k) ans++;
    }
    cout<<ans;
}
    

Measured memory_bytes: 3624
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;

int n;
const int maxn = 200000 + 5;

struct P
{
	int a;
	int b;
	int num;
};

P mem[maxn];

bool cmp(const P x, const P y)
{
	return  x.b < y.b;
}

bool solve()
{
	sort(mem, mem+n, cmp);
	for(int day = 0, p = 0; p < n; p++)
	{
		day += mem[p].a;
		if(day > mem[p].b) return false;
	}
	return true;
}

void Print()
{
	cout << "show" << endl;
	for(int i = 0; i < n; i++)
	{
		printf("%d ", mem[i].num);
	}
	printf("\n");
}

int main()
{
	scanf("%d", &n);
	for(int i = 0; i < n; i++)
	{
		cin >> mem[i].a >> mem[i].b;
		mem[i].num = i+1;
	}
	if(solve()) printf("Yes\n");
	else printf("No\n");
	//Print();
}

Measured memory_bytes: 2688
#include <iostream>
#include <math.h>
using namespace std;

bool isprime(int x){
	if (x == 2)
		return true;

	if (x < 2 || x % 2 == 0)
		return false;

	int	i = 3;
	while (i <= sqrt(x)){
		if (x%i == 0)
			return false;
		i += 2;
	}
	return true;
}

int main(void){
	int N, A, count=0;

	cin >> N;

	for (int i = 0; i < N; i++){
		cin >> A;

		if (isprime(A))
			count++;
	}

	cout << count << "\n";

	return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
using namespace std;
#define SZ(x) ((int)(x).size())

typedef	long long ll;

const int MAXN = 2e5+1;
const ll MOD = 998244353;
int n, p, deb;
ll ways[MAXN];
int seg[4*MAXN];
vector<pair<ll, int> > robots;

void init()
{
	while ((1<<p) < n) ++p;
	deb = (1<<p) - 1;
}

int query(int l, int r)
{
	l += deb;
	r += deb;
	int ans(0);
	while (l < r)
	{
		if (l%2==0)
			ans = max(ans, seg[l]);
		if (r%2)
			ans = max(ans, seg[r]);
		l /= 2;
		r = (r-2)/2;
	}
	if (l == r)
		ans = max(ans, seg[l]);
	return ans;
}	

void update(int pos, int x)
{
	pos += deb;
	seg[pos] = x;
	while (pos > 0)
	{
		pos = (pos-1)/2;
		seg[pos] = max(seg[2*pos+1], seg[2*pos+2]);
	}
}

int main(void)
{
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	
	cin >> n;
	robots.resize(n);

	for (auto &v : robots)
		cin >> v.first >> v.second;
	sort(robots.begin(), robots.end());

	ways[n] = 1;
	robots.emplace_back(1e18, 0);
	vector<int> to(n+1);

	to[n] = n;

	for (int i(n-1); i >= 0; --i)
	{
		int l(i), r(n-1);
		while (l < r)
		{
			int mid = (l+r+1)/2;

			if (robots[i].first + robots[i].second > robots[mid].first)
				l = mid;
			else
				r = mid-1;
		}
		to[i] = max(i, query(i+1,l));
		update(i, to[i]);
		ways[i] = (ways[i+1] + ways[to[i]+1])%MOD;
	}
	cout << ways[0] << endl;
}



Measured memory_bytes: 9544
n,*a=gets.split.map &:to_i
l=(1..n).map{gets.to_i}
m=1e5
[*0..3].repeated_permutation(n){|x|
    s=[q=0,0,0]
    x.each_with_index{|e,i|e<3&&(s[e]+=l[i])>l[i]&&q+=10}
    (0..2).each{|i|q+=(a[i]-s[i]).abs}
    s.all?{|i|i>0}&&q<m&&m=q
}
p m

Measured memory_bytes: 1916
using System;
using System.Collections.Generic;
using System.Linq;

public static class Solution
{
    public static void Main()
    {
        var K = int.Parse(Console.ReadLine());
        var rem = 7;
        var count = 1;
        for (; rem % K != 0 && count < 1e6; count++)
        {
            rem = (rem * 10 + 7) % K;
        }

        Console.WriteLine(count >= 1e6 ? -1 : count);
    }
}

Measured memory_bytes: 27324
n = int(input())
b = list(map(int, input().split()))

if n == 2:
    ans = b[0] * 2
else:
    ans = b[0]
    for i in range(n - 2):
        ans += min(b[i], b[i + 1])
    ans += b[n - 2]
print(ans)

Measured memory_bytes: 3060
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
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 rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> l_l;
typedef pair<int,int> i_i;
const ll mod=1e9+7;
const int inf=1<<30;

int dp[5010][5010];

int main(){
  int n; cin >> n;
  string s; cin >> s;
  for(int i=n-1;i>=0;i--){
    for(int j=n-1;j>=0;j--){
      if(s[i]==s[j]) dp[i][j]=dp[i+1][j+1]+1;
    }
  }
  int ans=0;
  rep(i,n){
    rep(j,n){
      int mx=min(j-i,dp[i][j]);
      chmax(ans,mx);
    }
  }
  cout << ans << endl;
}

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

int main(){
  int N;
  cin>>N;
  vector<string> S(N);
  vector<int> P(N),A(N);
  for(int i=0;i<N;i++){
    cin>>S.at(i)>>P.at(i);
    A.at(i)=i+1;
  }
  for(;;){
    int a=0;
    for(int i=0;i<N-1;i++){
      if(S.at(i)>S.at(i+1)){
        swap(S.at(i),S.at(i+1));
        swap(P.at(i),P.at(i+1));
        swap(A.at(i),A.at(i+1));
        a=1;
      }else if(S.at(i)==S.at(i+1)&&P.at(i)<P.at(i+1)){
        swap(P.at(i),P.at(i+1));
        swap(A.at(i),A.at(i+1));
        a=1;
      }
    }
    if(a==0)break;
  }
  for(int i=0;i<N;i++){
    cout<<A.at(i)<<endl;
  }
    
}

Measured memory_bytes: 256
#include <iostream>
#include <complex>
#include <vector>
#include <algorithm>
#define x real() 
#define y imag()
#define px second
#define py first
using namespace std;
typedef complex<double> vectol;
typedef pair <int,int> P;
P G[100001];
vector <P> stc;

int ccw(vectol a,vectol b,vectol c) {
  vectol ab=b-a, ac =c-a;
  vectol d =ac*conj(ab); 
  if(d.y > 0) return true;
  return false;
}

int mk(int i,int flg) {
  vectol av = vectol(stc[stc.size()-2].px,stc[stc.size()-2].py);
  vectol bv = vectol(stc[stc.size()-1].px,stc[stc.size()-1].py);
  vectol cv = vectol(G[i].px,G[i].py);
  if(ccw(av,bv,cv) && stc.size()!=1)stc.pop_back(),i+=flg;
  else  stc.push_back(G[i]);
  return i;
}

int main() {
  int n;
  cin >> n;
  for(int i=0;i<n;i++)cin >> G[i].px >> G[i].py;
  sort(G,G+n);
  
  stc.push_back(G[0]),stc.push_back(G[1]);
  for(int i=2;i<n;i++) i=mk(i,-1);
  for(int i=n-2;i>=0;i--) i=mk(i,1);
  
  cout <<stc.size()-1<<endl;
  for(int i=stc.size()-1;i>0;i--) cout<<stc[i].px <<" "<<stc[i].py<<endl;
  return 0;
}

Measured memory_bytes: 2836
a, b, k = map(int, input().split())
if a >= k:
    a = a - k
    k = 0
elif a < k:
    k = k - a
    a = 0
if b >= k:
    b = b - k
    k = 0
elif b < k:
    k = k - b
    b = 0
print("{0} {1}".format(a,b))

Measured memory_bytes: 38384
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define PI 3.141592
#define LL_INF 9000000000000000000
#define LL_MINF -9000000000000000000
#define INT_INF 2000000000
#define INT_MINF -2000000000
#define all(a) (a).begin(), (a).end()
#define fi first
#define se second

int main(){
    int N;
    cin >> N;
    bool ok = false;
    for(int i = 0; i <= 25; i++){
        for(int j = 0; j <= 14; j++){
            int count = 4 * i + 7 * j;
            if(count == N) {
                ok = true;
                goto finish;
            }
        }
    }
    finish:
    if(ok) puts("Yes");
    else puts("No");
}


Measured memory_bytes: 3644
import java.io._
import java.util.StringTokenizer
import scala.util.control.Breaks.{breakable,break}

object Main extends App {
  val in = new InputReader(System.in)
  val pw = new PrintWriter(System.out)

  val D, G = in.next().toInt
  val p = new Array[Int](D+1)
  val c = new Array[Int](D+1)

  for(i <- 1 to D) {
    val a, b = in.next().toInt
    p(i) = a; c(i) = b / 100
  }


  //
  val MAX = 150000
  val IM = Int.MaxValue
  val dp = Array.fill[Int](MAX+1)(IM)
  dp(0) = 0
  for(k <- 1 to D) {
    val np = p(k); val nc = c(k)

    for(i <- (1 to MAX).reverse) {
      for (j <- 1 until np) {
        val now = i - (k * j)
        if(now >= 0)
          if(dp(now) != IM) {
            dp(i) = dp(i) min (dp(now) + j)
          }
      }

      val clear = i - (k * np) - nc
      if(clear >= 0)
        if(dp(clear) != IM) {
          dp(i) = dp(i) min (dp(clear) + np)
        }
    }
  }

  var ans = IM
  for (i <- G/100 to MAX)
    ans = ans min dp(i)
  println(ans)
}


class InputReader(stream: InputStream) {
  private val reader = new BufferedReader(new InputStreamReader(stream))
  private var tokenizer: StringTokenizer = new StringTokenizer(reader.readLine())
  def next(): String = {
    while (!tokenizer.hasMoreTokens()) {
      tokenizer = new StringTokenizer(reader.readLine())
    }
    tokenizer.nextToken()
  }
}


Measured memory_bytes: 48196
<?php

fscanf(STDIN, "%s", $str);
fscanf(STDIN, "%d", $k);

$smap = str_split($str);
$count = count($smap) - 1;

$last = "";
$num = 1;
$ans = 0;
if($smap[0] == $smap[$count]){
    $i = 0;
    while($smap[$i] == $smap[0] && $i < $count){
        $i++;
    }
    if($i == $count){
        $ans = intdiv(($count + 1) * $k, 2);
        echo $ans;
        exit;
    }
    $j = $count;
    while($smap[$j] == $smap[0] && $j > 0) {
        $j--;
    }
    $ans += intdiv($i, 2);
    $ans += intdiv($count - $j , 2);
    $ans += intdiv( ($i + $count- $j) , 2) * ($k -1);
    $smap = array_slice($smap, $i , $j - $i + 1);
    $count = count($smap) - 1;
}
for($i=0;$i<=$count;$i++){
    if($smap[$i] == $last){
        $num++;
    }else{
        if($num != 1){
            $ans += intdiv($num , 2) * $k;
            $num = 1;
        }
        $last = $smap[$i];
    }
}

if($num != 1){
    $ans += intdiv($num , 2) * $k;
    $num = 1;
}
echo $ans;

Measured memory_bytes: 4604
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#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 all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const int inf=1e9+7;
const ll INF=1e18;

int main(){
    int n;cin>>n;
    string s;cin>>s;
    int l=0;int r=n-1;bool tmpl,tmpr;
    int ans=0;
    while(l<r){
        tmpl=false;tmpr=false;
        rep2(i,l,r){
            if(s[i]=='W'){
                s[i]='R';
                tmpl=true;
                l=i;
                break;
            }
        }
        for(int i=r;i>l;i--){
            if(s[i]=='R'){
                s[i]='W';
                tmpr=true;
                r=i;
                break;
            }
        }
        //cout<<l<<" "<<r<<endl;
        if(tmpl&&tmpr)ans++;
        else break;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3744
#include <bits/stdc++.h>
#define N 1000005
#define ll long long int 
#define mp make_pair
#define pb push_back
#define ppb pop_back
#define sp " "
#define endl "\n"
#define fi first
#define se second
#define ii pair<int,int>
#define lli pair<ll,ll>
#define fast cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(false)
#define fast2 freopen ("myfile.gir","r",stdin);freopen ("myfile.cik","w",stdout);
#define mod 1000000007
using namespace std;

ll n,ar[N],a,b;


int main()
{
	fast;
	cin>>a>>b;
	if(b%a==0)
		cout<<a+b;
	else
		cout<<b-a;

}

Measured memory_bytes: 256
#include <iostream>
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
using graph = vector<vector<ll>>;


int main() {
	ll k, a, b,mem;
	cin >> k;
	cin >> a >> b;
	mem = a / k;
	if (k * mem == a) {
		cout << "OK" << endl;
	}
	else if (k * (mem + 1) > a && k * (mem + 1) <= b) {
		cout << "OK" << endl;
	}
	else {
		cout << "NG" << endl;
	}
	return 0;
}

Measured memory_bytes: 3624
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
typedef long long ll;

ll levelN(ll n, ll x) {
    if(x == 0)
        return 0;
    if(n == 0)
        return x;
    ll size = 1;
    ll patty = 1;
    for(size_t i = 0; i < n; i++) {
        size = 2 * size + 3;
        patty = 2 * patty + 1;
    }
    ll mid = (size+ll(1))/ll(2);
    if(x < mid)
        return levelN(n-1, x-1);
    else if(x == mid)
        return levelN(n-1, x-2) + 1;
    else if(x >= size-1)
        return patty;
    else
        return (patty-1)/2 + 1 + levelN(n-1, x-mid);
}

int main(){
    ll N, X;
    cin >> N >> X;
    cout << levelN(N, X) << endl;
    return 0;
}

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

int main(void) {
  int a,b;
  cin >> a >> b;
  int count = 0;
  for(int i = a; i <= b; i++){
    int s = i % 10;
    int t = i /10 % 10;
    // if both sides of the third digit are the same.
    int v = i / 1000 % 10;
    int w = i / 10000 % 10;
    if(s == w && t == v){
      count++;
    }
  }
  cout << count << endl;
  return 0;
}



Measured memory_bytes: 256
const input = require('fs').readFileSync('/dev/stdin', 'utf8').split('\n')
const [N, M, X] = input[0].split(' ').map(Number)
const books = []

for (let i=1; i<=N; i++) {
  const [price, ...skills] = input[i].split(' ').map(Number)
  books.push({
    price,
    skills
  })
}

const solver = (n, skills) => {
  const min = skills.reduce((a, c) => Math.min(a, c))
  if (X <= min) {
    return 0
  }
  if (n == N) {
    return Infinity 
  }

  const a = solver(n+1, skills.map((v, i) => v + books[n].skills[i])) + books[n].price
  const b = solver(n+1, skills)

  return Math.min(a, b)
}

const ans = solver(0, new Array(M).fill(0))
console.log(ans !== Infinity? ans : -1)


Measured memory_bytes: 33776
#include <iostream>
#include <vector>
using namespace std;
int main()
{
	int n;
	cin>>n;
	vector<int> v1(9,0);
	vector<int> v2(9,0);
	int brojce=0;
	for(int i=0;i<n;i++)
	{
		int a;
		cin>>a;
		if(a>=1&&a<=399)
			v1[1]++,v2[1]++;
		else if(a>=400&&a<=799)
			v1[2]++,v2[2]++;
		else if(a>=800&&a<=1199)
			v1[3]++,v2[3]++;
		else if(a>=1200&&a<=1599)
			v1[4]++,v2[4]++;
		else if(a>=1600&&a<=1999)
			v1[5]++,v2[5]++;
		else if(a>=2000&&a<=2399)
			v1[6]++,v2[6]++;
		else if(a>=2400&&a<=2799)
			v1[7]++,v2[7]++;
		else if(a>=2800&&a<=3199)
			v1[8]++,v2[8]++;
		else
		{
			bool cc=false;
			for(int j=1;j<=8;j++)
			{
				if(v1[j])
				{
					v1[j]++;
					cc=true;
					break;
				}
			}
			if(!cc)
				v1[8]++;
			brojce++;
		}
	}
		int br1=0,br2=0;
		for(int i=1;i<=8;i++)
		{
			if(v1[i])
				br1++;
			if(v2[i])
				br2++;
		}
		cout<<br1<<" "<<br2+brojce<<endl;
	
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        boolean flg=false;
        int n = sc.nextInt();
        while (n > 3) {
            if (n % 4 == 0 || n >= 28 || n%7==0) {
                flg = true;
                break; 
            }
            n -= 7; 
        }
            if (flg == true) System.out.println("Yes");
            else System.out.println("No");
    }
}


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

const function<int(int, int)> minQ = [](int l, int r) { return min(l, r); };
const function<int(int, int)> maxQ = [](int l, int r) { return max(l, r); };

int data[1 << 23];
int v[1 << 20];

template <typename T>
class SegmentTree2 {
	using func_t = function<T(T, T)>;
	const int h, w;
	const T id;
	func_t merge;
	int size(int n) {
		int res;
		for (res = 1; res < n; res <<= 1);
		return res;
	}
public:
	SegmentTree2(int h_, int w_, T id_, func_t merge_) :
		h(size(h_)), w(size(w_)), id(id_), merge(merge_) {
		fill(data, data + (1 << 23), id);
		for (int i = 0; i < h_; i++)
			for (int j = 0; j < w_; j++)
				data[(h + i) * w * 2 + w + j] = v[i * w_ + j];
		for (int i = h * 2 - 1; i >= h; i--)
			for (int j = w - 1; j > 0; j--)
				data[i * w * 2 + j] = merge(data[i * w * 2 + j * 2], data[i * w * 2 + j * 2 + 1]);
		for (int i = h - 1; i > 0; i--)
			for (int j = 1; j < w * 2; j++)
				data[i * w * 2 + j] = merge(data[i * 2 * w * 2 + j], data[(i * 2 + 1) * w * 2 + j]);
	}
	void Update(int pi, int pj, T val) {
		pi += h;
		pj += w;
		data[pi * w * 2 + pj] = val;
		int tj = pj;
		while (tj >>= 1) {
			data[pi * w * 2 + tj] = merge(data[pi * w * 2 + tj * 2], data[pi * w * 2 + tj * 2 + 1]);
		}
		while (pi >>= 1) {
			data[pi * w * 2 + pj] = merge(data[(pi * 2) * w * 2 + pj], data[(pi * 2 + 1) * w * 2 + pj]);
			tj = pj;
			while (tj >>= 1) {
				data[pi * w * 2 + tj] = merge(data[pi * w * 2 + tj * 2], data[pi * w * 2 + tj * 2 + 1]);
			}
		}
	}
	T Find(int li, int lj, int ri, int rj) {
		li += h, ri += h + 1;
		T res1 = id, res2 = id;
		while (li < ri) {
			if (li & 1) {
				int l = lj + w, r = rj + w + 1;
				T t1 = id, t2 = id;
				while (l < r) {
					if (l & 1) t1 = merge(t1, data[li * w * 2 + l++]);
					if (r & 1) t2 = merge(data[li * w * 2 + --r], t2);
					l >>= 1, r >>= 1;
				}
				res1 = merge(res1, merge(t1, t2));
				li++;
			}
			if (ri & 1) {
				ri--;
				int l = lj + w, r = rj + w + 1;
				T t1 = id, t2 = id;
				while (l < r) {
					if (l & 1) t1 = merge(t1, data[ri * w * 2 + l++]);
					if (r & 1) t2 = merge(data[ri * w * 2 + --r], t2);
					l >>= 1, r >>= 1;
				}
				res2 = merge(merge(t1, t2), res2);
			}
			li >>= 1, ri >>= 1;
		}
		return merge(res1, res2);
	}
};

int main()
{
	cin.sync_with_stdio(false);
	cin.tie(0);
	int r, c, q, r1, r2, c1, c2;
	while (cin >> r >> c >> q, r | c | q) {
		for (int i = 0; i < r; i++) {
			for (int j = 0; j < c; j++) {
				cin >> v[i * c + j];
			}
		}
		SegmentTree2<int> st(r, c, INT_MAX, minQ);
		while (q--) {
			cin >> r1 >> c1 >> r2 >> c2;
			printf("%d\n", st.Find(r1, c1, r2, c2));
		}
	}
	return 0;
}

Measured memory_bytes: 39852
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
int main() {
    // ifstream in("data1.txt");
    // cin.rdbuf(in.rdbuf());
    int N;
    string S;
    cin >> N >> S;
    int ans = 0;

    for (int i = 0; i < N-2; i++){
        if(S[i] == 'A' && S[i + 1] == 'B' && S[i + 2] == 'C') {
            ans++;
        }
    }
    cout << ans << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstdio>

using namespace std;

#define int long long
#define INF (int)1e9 + 7

signed main()
{
    int N;
    cin >> N;
    vector<int> v(N);
    for (int i = 0; i < N; i++)
    {
        scanf("%lld", &v[i]);
    }

    int ans = 0;

    vector<int> n_digit(61, 0);
    // N * 61 = 10^7
    for (int i = 0; i < N; i++)
    {
        for (int j = 0; j < 61; j++)
        {
            if (v[i] & (1ll << j))
            {
                n_digit[j]++;
            }
        }
    }

    // 61 * N^2
    for (int i = 0; i < 61; i++)
    {
        // 1<<i * (N-n_digit)*n_digit
        int sum = (N - n_digit[i]) * n_digit[i];
        sum %= INF;
        int mul = (1ll << i);
        mul %= INF;
        ans += sum * mul;
        ans %= INF;
        //cout << i << " " << sum << endl;
        /*
        for (int j = 0; j < sum; j++)
        {
            ans += (1ll << i);
            ans %= INF;
        }
        */
        //cout << ans << endl;
    }

    cout << ans << endl;
}

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

using namespace std;

int a, b, ans;

int main() {
    int N, x[3];
    cin >> N;

    while (N--) {
        cin >> x[0] >> x[1] >> x[2];
        sort(x, x + 3);
        cout << (x[2] * x[2] == x[0] * x[0] + x[1] * x[1] ? "YES" : "NO") << endl;
    }
}


Measured memory_bytes: 3096
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int mod=1e9+7;
int n,a[200005],bc[200005],ans=0;
signed main(){
	cin>>n;
	for(int i=1;i<=n;i++) cin>>a[i];
	for(int i=n;i>=1;i--) bc[i]=a[i]+bc[i+1],bc[i]%=mod;
	for(int i=1;i<=n;i++){
		ans+=(a[i]*bc[i+1]);
		ans%=mod;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 6712
#include <bits/stdc++.h>
#define pi 3.141592653589793238462643383279
using namespace std;

int main()
{
    double a,b,h,m;
    cin>>a>>b>>h>>m;
    double ah=((h)+(m)/60)*2*pi/12.00;
    double am=((m))*2*pi/60.00;
    double dist=sqrt(a*a+b*b-2*a*b*cos(ah-am));
    cout<<fixed<<setprecision(13)<<dist;
    
    return 0;
}


Measured memory_bytes: 4128
#[allow(unused_imports)]
use std::{cmp::Reverse, collections::*};

#[allow(unused_imports)]
use proconio::{
    fastout, input,
    marker::{Chars, Usize1},
};

#[allow(unused_imports)]
use itertools::Itertools;

#[allow(unused_imports)]
use num::Integer;

#[fastout]
pub fn main() {
    input! {
        n: usize,
        k: i32,
        x: [i32; n],
    }

    println!("{}", x.iter().map(|x| x.min(&(k - x)) * 2).sum::<i32>());
}


Measured memory_bytes: 2148
#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll=long long;
using vi=vector<int>;
using vl=vector<long long>;
using pii=pair<int,int>;
using pll=pair<long long,long long>;
#define ITR(i,c) for(auto i=begin(c);i!=end(c);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##_len=(int)(n);i<i##_len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define REPW(i,n) for(i=0;i<(int)(n);++i)
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)   // c++14
#define SZ(c) ((int)c.size())
#define EXIST(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) (y<0||x<0||y>=h||x>=w)
#define dump(...)
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
#define INF (1001001001)
#define INFLL (1001001001001001001ll)
template<class T> ostream& operator << (ostream &os,const vector<T> &v) {
    ITR(i,v) os << *i << (i==end(v)-1 ? "" : "\n"); return os; }
template<class T> istream& operator >> (istream &is,vector<T> &v) {
    ITR(i,v) is >> * i; return is; }
template<class T> istream& operator >> (istream &is, pair<T,T> &p) {
        is >> p.first >> p.second; return is; }
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
//------------------------------------------------------------------------------
struct before_main_function {
    before_main_function() {
        #ifdef int
            #undef INF
            #define INF INFLL
            #define stoi stoll
        #endif
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
    }
} before_main_function;
//------------------------------------------------------------------------------

signed main() {
    while(1) {
        int n,m,p,a,b;
        cin>>n>>m>>p>>a>>b;
        if(n+m+p+a+b==0) break;
        a--;b--;
        vector<double> ticket(n);
        cin>>ticket;
        vector<vector<double>> d(m,vector<double>(m,INF));
        REP(i,p) {
            int x,y,z;
            cin>>x>>y>>z;
            x--,y--;
            d[x][y]=d[y][x]=z;
        }
        vector<vector<double>> dp((1<<n),vector<double>(m,INF));
        dp[(1<<n)-1][a]=0;
        for(int i=(1<<n)-1;i>=0;--i) {
            REP(j,m) {
                if(dp[i][j]!=INF) {
                    REP(k,m) {
                        if(d[j][k]!=INF) {
                            REP(l,n) {
                                if(i&(1<<l)) {
                                    chmin(dp[i&(~(1<<l))][k],dp[i][j]+(d[j][k]/ticket[l]));
                                }
                            }
                        }
                    }
                }
            }
        }
        double ans=INF;
        REP(i,1<<n) {
            chmin(ans,dp[i][b]);
        }
        if(ans==INF) {
            cout<<"Impossible"<<endl;
        }
        else {
            cout<<ans<<endl;
        }
    }
    return 0;
}

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

#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define MOD 1000000007
#define cey ce("Yes")
#define cen ce("No")
#define ceY ce("YES")
#define ceN ce("NO")

int main()
{

int a, b, c;
	cin >> a >> b >> c;
	if (a+b+c>=22) {
		ce("bust")
	}
	else {
		ce("win")
	}
    return 0;
}



Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    void run() {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] arr = new int[m];
        for (int i = 0; i < m; i++) {
            arr[i] = sc.nextInt();
        }
        long MOD = (long) 1e9 + 7;

        long[] dp = new long[n + 2];
        dp[0] = 1;
        // dp[i] ... i段目にたどり着く数
        int currentIdx = 0;
        for (int i = 0; i < n; i++) {
            if (currentIdx < m && i == arr[currentIdx]) {
                currentIdx++;
                continue;
            }
            dp[i + 1] += dp[i] % MOD;
            dp[i + 2] += dp[i] % MOD;
        }
        System.out.println(dp[n] % MOD);
    }


    void debug(Object... os) {
        System.err.println(Arrays.deepToString(os));
    }

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


Measured memory_bytes: 48568
H, W = map(int, input().split())

l = []

for i in range(H):
    l.append(input())

y = [False] * H
x = [False] * W

for i in range(H):
    flg = True
    for j in range(W):
        if l[i][j] != '.':
            flg = False
            break
    if flg:
        y[i] = True

for i in range(W):
    flg = True
    for j in range(H):
        if l[j][i] != '.':
            flg = False
            break
    if flg:
        x[i] = True

for i in range(H):
    if y[i]:
        continue
    for j in range(W):
        if x[j]:
            continue
        print(l[i][j], end='')
    print()


Measured memory_bytes: 4468