akhauriyash/Code-Regression huggingface dataset:
fn main() {
    let s = read::<String>().chars().collect::<Vec<_>>();
    yn(!(s.iter().all(|&c| c == 'A') || s.iter().all(|&c| c == 'B')));
}

#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
#[allow(dead_code)]
fn yn(result: bool) {
    if result {
        println!("Yes");
    } else {
        println!("No");
    }
}


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

int main() {
    int a, b, c, count;
    cin >> a >> b >> c;
    
    for (int i = 0; i < b - a + 1; i++) {
        if (c % (a + i) == 0) {
            count++;
        }
    }
    
    cout << count << endl;
}


Measured memory_bytes: 3136
while True:
 x = raw_input().split()
 a = int(x[0])
 b = int(x[2])
 op = x[1]
 if op == '+' :
  print a + b
 elif op == '-' :
  print a - b
 elif op == '*' :
  print  a * b 
 elif op == '/' :
  print a / b
 elif op == '?' :
  break

Measured memory_bytes: 6380
#include "bits/stdc++.h"

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;

using namespace std;
using ll = long long;

template<typename T=int>
T in(){T x; cin >> x; return (x);}

std::vector<ll> prime_factor(ll n){
	vector<ll> min_factor(n+1);
	iota(min_factor.begin(), min_factor.end(), 0);
	for(ll i=2;i*i<n+1;++i){
		if(min_factor[i]<i) continue;
		for(ll j=i*i;j<n+1;j+=i){
			if(min_factor[j]==j) min_factor[j] = i;
		}
	}

	std::vector<ll> res;
	while(n>1){
		res.push_back(min_factor[n]);
		n /= min_factor[n];
	}
	return res;
}
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);

	int N=in();
	vector<int> E(N,0);
	for(int n=2;n<=N;n++){
		vector<ll> P(prime_factor(n));
		for(int i=0,ei=P.size();i<ei;i++){
			E[P[i]]++;
		}
	}

	auto num_count = [&](int v){
		return count_if(ALL(E),[&](int x){return x>=v;});
	};

	int num3 = num_count(2);
	int num5 = num_count(4);
	int num15 = num_count(14);
	int num25 = num_count(24);
	int num75 = num_count(74);

	cout << (num75+num25*(num3-1)+num15*(num5-1)+(num5)*(num5-1)*(num3-2)/2) << endl;
	return 0;
}


Measured memory_bytes: 256
while True:
    a,op,b=input().split()
    a=int(a)
    b=int(b)
    if op=="+":
        print(int(a+b))
    elif op=="-":
        print(int(a-b))
    elif op=="*":
        print(int(a*b))
    elif op=="/":
        print(int(a/b))
    elif op=="?":
        break
    else:
        continue


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

int main(){

  int n;
  cin>>n;
  vector<int> data(n);

  for(int i=0;i<n;i++)
    cin>>data[i];



  long long int ans = -1;
  for(int sign = -1 ;sign <= 1; sign +=2){
    int sign_=sign;
    long long int ans_=0;
    int sum = 0;
    for(int i=0;i<n;i++){
      sum += data[i];
      if (sum * sign_ <= 0) {
	ans_ += (sum>0)?sum:-sum;
	ans_ ++;
	sum = sign_;
      }
      sign_ *= -1;
    }
    if (ans == -1 || ans_ < ans) {
      ans = ans_;
    }
  }

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


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


int main()
{
    string S;
    int A, B;

    cin >> S;

    
    for (int i = 0; i < S.size(); i++)
    {
        cout << "x";
    }


    system("pause");
    return 0;
}

Measured memory_bytes: 504
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >>n;
  vector<int> a(n);
  vector<int> b(n-1);
  for(int i=0;i<n-1;i++){
    cin >>b[i];
  }
  a[0]=b[0];
  for(int i=1;i<n-1;i++){
    a[i]=min(b[i-1],b[i]);
  }
  a[n-1]=b[n-2];

int ans=0;
for(int i=0;i<n;i++){

  ans+=a[i];
}
cout <<ans<<endl;
}
  

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<vector>
#include<tuple>
using namespace std;
const int N=100005;
int n;
long long m;
int Q;
int fa[N];
int getf(int v)
{
	if(v==fa[v]) return v;
	fa[v]=getf(fa[v]);
	return fa[v];
}
bool merge(int u,int v)
{
	int f1=getf(u),f2=getf(v);
	if(f1!=f2)
	{
		fa[f2]=f1;
		return true;
	}
	else return false;
}
int main()
{
	scanf("%d%lld%d",&n,&m,&Q);
	for(int i=1;i<=n;i++)
		fa[i]=i;
	vector<tuple<int,int,int> >G;
	int num=0;
	for(int i=1;i<=Q;i++)
	{
		int u,v,w;
		scanf("%d%d%d",&u,&v,&w);
		u++,v++;
		if(w==0) num+=merge(u,v);
		else if(w==1) G.push_back(make_tuple(u,v,w));
	}
	for(auto [u,v,w]:G)
		if(getf(u)==getf(v))
		{
			printf("No");
			return 0;
		}
	int cnt=0;
	for(int i=1;i<=n;i++)
		if(getf(i)==i) cnt++;
	if(cnt==2&&!G.empty())
	{
		printf("No");
		return 0;
	}
	long long l=num+cnt,r=num+1LL*cnt*(cnt-1)/2;
	if(cnt==1) l=num,r=num;
	if(G.empty()) l=num-1;
	if(l<=m&&m<=r) printf("Yes");
	else printf("No");
	return 0;
}

Measured memory_bytes: 5284
import bisect
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


def main():
    n = I()
    a = LI()
    b = LI()
    c = LI()
    a.sort()
    b.sort()
    c.sort()
    ans = 0
    for bi in b:
        num_a = bisect.bisect_left(a, bi)
        num_c = n - bisect.bisect_right(c, bi)
        ans += num_a * num_c
    print(ans)


main()


Measured memory_bytes: 24012
h, w = list(map(int, input().split(' ')))

a = []
for i in range(h):
    line = input()
    aa = []
    for j in range(len(line)):
        aa.append(line[j])
    a.append(aa)

# horizontal
popList = []
for i in range(len(a)):
    isBlack = False
    for j in range(len(a[i])):
        if a[i][j] == "#":
            isBlack = True
    
    if isBlack == False:
        popList.append(i)

for i in range(len(popList)):
    a.pop(popList[i] - i)

# vertical
popList = []
for i in range(len(a[0])):
    isBlack = False
    for j in range(len(a)):
        if a[j][i] == "#":
            isBlack = True

    if isBlack == False:
        popList.append(i)

for i in range(len(popList)):
    for j in range(len(a)):
        a[j].pop(popList[i] - i)

# print
for i in a:
    for j in i:
        print(j, end="")
    print()

Measured memory_bytes: 4596
/*input
3 1
1 5
4 9
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}

//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const ld PI=acos(-1);
const ld eps=1e-9;
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		
		b>>=1;
	}
	return res;
}

pdd operator-(pdd A,pdd B){
	return MP(A.F-B.F,A.S-B.S);
}
double operator*(pdd A,pdd B){
	return A.F*B.F+A.S*B.S;
}

double len(pdd A){
	return hypot(A.F,A.S);
}
pdd a[3];

int main(){
	IOS;
	REP(i,3)cin>>a[i].F>>a[i].S;

	double ans=0;

	REP(i,3){
		double b=(a[0]-a[1])*(a[2]-a[1]);
		b/=len(a[0]-a[1]);
		b/=len(a[2]-a[1]); 

		double c=(a[0]-a[2])*(a[1]-a[2]);
		c/=len(a[0]-a[2]);
		c/=len(a[1]-a[2]); 

		b=(b+1)/sqrt(1-b*b);
		c=(c+1)/sqrt(1-c*c);

		ans=max(ans,len(a[1]-a[2])/(2+b+c));
		{
			pdd tmp=a[0];
			a[0]=a[1];
			a[1]=a[2];
			a[2]=tmp;
		}
	}
	cout<<fixed<<setprecision(12)<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
  int n,k;cin>>n>>k;
  int a[n];int mi =1,ma = -1;
  for (int i=0;i<n;++i){cin>>a[i];ma=max(ma,a[i]);}
  sort(a,a+n);int ans =ma;
  while (mi<=ma){
      int mid = (mi+ma)/2;
      int te = k;
      for (int i=n-1;i>=0;--i){
          if (a[i]<=mid)break;
          te-=((a[i]-1)/mid);
      }
      if (te>=0){ans=mid;ma=mid-1;}
      else mi=mid+1;
  }
  cout<<ans;
  
}

Measured memory_bytes: 4428
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <utility>
using namespace std;

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

int main(){
  int h,w;
  cin >> h >> w;

  int sx,sy;
  vector<vector<char> > map(h+2, vector<char>(w+2, '#'));
  for(int i=1; i<=h; i++){
    for(int j=1; j<=w; j++){
      cin >> map[i][j];
      if(map[i][j]=='%'){
        sy=i;
        sx=j;
      }
    }
  }

  queue<pair<int,pair<int,int> > > q;
  q.push(make_pair(0, make_pair(sy,sx)));
  map[sy][sx]='#';
  int princess=1e9;
  int soldier=1e9;
  while(!q.empty()){
    int step=q.front().first;
    int y=q.front().second.first;
    int x=q.front().second.second;
    q.pop();
    for(int i=0; i<4; i++){
      int nx=x+dx[i];
      int ny=y+dy[i];
      if(map[ny][nx]!='#'){
        if(map[ny][nx]=='@') princess = step;
        if(map[ny][nx]=='$') soldier = min(step, soldier);
        map[ny][nx] = '#';
        q.push(make_pair(step+1, make_pair(ny,nx)));
      }
    }
  }

  if(princess<soldier){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 3164
#include<iostream>
#include<cctype>
#include<cstdio>
using namespace std;
int main(){
    char ch;
    while(1){
        scanf("%c",&ch);
        if(ch == '\n') break;
        else if(isalpha(ch)){
            if(islower(ch)) printf("%c",toupper(ch));
            else printf("%c",tolower(ch));
        }
    
        else printf("%c",ch);
        
    }
    cout << endl;
    
    return 0;
}


Measured memory_bytes: 3244
//omajinai c++ atcoder
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define itn int
typedef long long ll;
constexpr auto mod = 1000000007;
using namespace std;
int main() {

 int n;
  cin>>n;
 long int sum=0;
  for(int i=1;i<=n;i++){
    if(i%3!=0&&i%5!=0){
      sum+=i;
    }
  }
  cout<<sum;
}


Measured memory_bytes: 3596
#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 set0(k,n) for(int nn=0;nn<(n);nn++){ (k).push_back(0); }
#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 vecsize(b,size) vector<int> (b)((size));
#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 pairsl(s) vector<pair<ll,ll>> (s);
#define pairss(s) vector<pair<string,string>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairspl(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsps(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsREV(s) (s).push_back(make_pair(bb,aa));
#define pairslREV(s) (s).push_back(make_pair(bb,aa));
#define pairssREV(s) (s).push_back(make_pair(bb,aa));
#define MOD 1000000007

int main()
{
	int N;
	cin >> N;
	pairs(K);
	fx(N) {
		int a;
		cin >> a;
		pb(K,make_pair(a,x+1))
	}
	sorts(K);
	fx(N) {
		cout << K[x].second;
		if (x==N-1) {
			cout << endl;
		}
		else {
			cout << ' ';
		}
	}
    return 0;
}



Measured memory_bytes: 1780
s = input()
sl = [_ for _ in s]

answers = []
for i in range(2**(len(s)-1)):
    temp = []
    for j in range(len(s)-1):
        if (i >> j) & 1:
            temp.append(j)
    ll = ["*"] * len(s)
    for k in temp:
        ll[k] = "+"
    ans = []
    for sli, lli in zip(sl, ll):
        ans.append(sli)
        ans.append(lli)
    ans = [_ for _ in ans if _ != "*"]
    ans = "".join(ans)
    ans = ans.split("+")
    ans = [int(i) for i in ans]
    ans = sum(ans)
    answers.append(ans)

print(sum(answers))


Measured memory_bytes: 3064
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

n,d=mp()
print(-(-n//(2*d+1)))

Measured memory_bytes: 10412
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
	int N;
	cin >> N;
	vector<int> P(N);
	for (auto& x : P) {
		cin >> x;
	}

	int ans = 1;
	int minval = P[0];
	for (int i = 1; i < N; ++i) {
		if (P[i] <= minval) {
			++ans;
		}
		minval = min(minval, P[i]);
	}
	cout << ans << endl;
}


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

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

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

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; }

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

const ll MOD = 1e9+7;

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

  ll n, m;
  cin >> n >> m;
  vector<ll> x(n), y(m);
  for(int i = 0; i < n; i++) cin >> x[i];
  for(int i = 0; i < m; i++) cin >> y[i];

  ll sumx = 0;
  ll sumy = 0;

  for(int i = 0; i < n-1; i++){

    ll left = i+1;
    ll right = n - left;
    sumx = (sumx + ((x[i+1] - x[i]) * left % MOD * right) % MOD) % MOD;


  }

  for(int i = 0; i < m-1; i++){
    ll left = i+1;
    ll right = m - left;
    sumy = (sumy + ((y[i+1] - y[i]) * left % MOD * right) % MOD) % MOD;
  }

  ll ans = (sumy * sumx) % MOD;
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
#include <deque>
#include <iterator>
#include <map>
#include <queue>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
template<class T> inline bool chmax(T& a, T b) {if (a<b) {a=b; return true;} return false;}
template<class T> inline bool chmin(T& a, T b) {if (a>b) {a=b; return true;} return false;}

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

int main() {
  ll n, m; cin >> n >> m;
  vvll edges(n, vll());
  vll indeg(n, 0);
  REP(i, n+m-1) {
    ll a, b; cin >> a >> b;
    edges[a-1].push_back(b-1);
    indeg[b-1]++;
  }

  queue<ll> q;
  vll parent(n, -1);
  REP(i, n) {
    if (indeg[i]==0) {
      q.push(i); parent[i]=0; break;
    }
  }

  while(!q.empty()) {
    ll i = q.front(); q.pop();
    REP(j, edges[i].size()) {
      indeg[edges[i][j]]--;
      if (indeg[edges[i][j]] == 0) {
        q.push(edges[i][j]); parent[edges[i][j]] = i+1;
      }
    }
  }

  REP(i, n) cout << parent[i] << endl;

  return 0;
}


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

int main()
{
    string s,t;
    cin>>s>>t;
    int c=0;
    int l=s.size();
    for(int i=0;i<l;i++)
    {
        if(s[i]!=t[i])
        {
            c++;
            break;
        }
    }
    if(c>0) cout<<"No"<<endl;

else cout<<"Yes"<<endl;
return 0;
}


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

int main() {
    int A,B,K;cin>>A>>B>>K;
   vector<int>ans(100);
   for(int i = 0; i < 100; i++)
   {
       if(A%(i+1)==0&&B%(i+1)==0)
       {
           ans.at(i)=i+1;
       }
   }
   sort(ans.begin(),ans.end());
   reverse(ans.begin(),ans.end());
   cout<<ans.at(K-1)<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,s,n) for (int i = (s); i < (n); ++i)
#define rrep(i,n,g) for (int i = (n)-1; i >= (g); --i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define len(x) (int)(x).size()
#define dup(x,y) (((x)+(y)-1)/(y))
#define pb push_back
#define Field(T) vector<vector<T>>
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int n;
  cin >> n;
  vector<int> d(n);
  rep(i,0,n) {
    int d1, d2;
    cin >> d1 >> d2;
    d[i] = abs(d1 - d2);
  }
  rep(i,0,n-2) {
    if (d[i] == d[i+1] && d[i] == d[i+2] && d[i] == 0) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> p(n);
  vector<int> q(n);
  for (int i = 0; i < n; i++) {
    cin >> p[i];
    q[i] = p[i];
  }
  int ans = 0;
  sort(q.begin(), q.end());
  for (int i = 0; i < n; i++ ) {
    if (p[i] != q[i]) {
      ans++;
    }
  }
  cout << ((ans == 2 || ans == 0) ? "YES" : "NO") << endl;
}


Measured memory_bytes: 3612
#include<bits/stdc++.h>
#define For(i,x,y) for (register int i=(x);i<=(y);i++)
#define FOR(i,x,y) for (register int i=(x);i<(y);i++)
#define Dow(i,x,y) for (register int i=(x);i>=(y);i--)
#define Debug(v) for (auto i:v) printf("%lld ",i);puts("")
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define ep emplace_back
#define siz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define fil(a,b) memset((a),(b),sizeof(a))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pa;
typedef pair<ll,ll> PA;
typedef vector<int> poly;
inline ll read(){
    ll x=0,f=1;char c=getchar();
    while ((c<'0'||c>'9')&&(c!='-')) c=getchar();
    if (c=='-') f=-1,c=getchar();
    while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
    return x*f;
}

const int N = 1<<18|3, mod = 1e9+7;
int h,cnt,n,p[N];

inline int power(int a,int b){
	int ret=1;
	for (;b;b>>=1,a=1ll*a*a%mod) if (b&1) ret=1ll*ret*a%mod;
	return ret; 
}
inline int Mod(int x){
	return x>=mod?x-mod:x;
}

int Tim,l[N],r[N],f[N],invf[N],inv[N];
poly v[N];
inline void dfs(int u){
	invf[u]=power(f[u],mod-2);
	if (p[u]) return l[u]=r[u]=u,void(0);
	f[u<<1]=1ll*f[u]*(u<<1)%mod;
	f[u<<1^1]=1ll*f[u]*(u<<1^1)%mod;
	dfs(u<<1),dfs(u<<1^1);
	l[u]=l[u<<1],r[u]=r[u<<1^1];
}
int ans,flag[N],ip[N];
inline void dfs2(int u){
	if (p[u]) return v[u].pb(p[u]+cnt-1),void(0);
	dfs2(u<<1),dfs2(u<<1^1);
	v[u]=v[u<<1];
	for (auto i:v[u<<1^1]) v[u].pb(i);
//	printf(" %d:\n",u);
//	for (auto i:v[u]) printf("%d ",i);puts("");
	for (auto i:v[u<<1]){
		int tmp=1ll*f[ip[i]]*invf[u]%mod*u%mod;
		for (int now=i;now;now>>=1){
			tmp=1ll*tmp*now%mod,flag[now]=Mod(flag[now]+tmp);
		}
	}
	for (auto i:v[u<<1^1]){
		int tmp=1ll*f[ip[i]]*invf[u]%mod,tmp2=i;
		for (int las=i,now=i>>1;now;las=now,now>>=1){
			tmp2=1ll*tmp2*now%mod;
			if (now*2==las){
				ans=(ans+1ll*flag[now*2+1]*tmp%mod*tmp2)%mod;
			} else {
				ans=(ans+1ll*flag[now*2]*tmp%mod*tmp2)%mod;
			}
		}
	}
	for (auto i:v[u<<1])
		for (int now=i;now;now>>=1) flag[now]=0;
}

int main(){
	h=read(),cnt=1<<(h-1),n=cnt*2-1;
	For(i,1,cnt) p[cnt+i-1]=read(),ip[p[cnt+i-1]+cnt-1]=cnt+i-1;
	For(i,1,n) inv[i]=power(i,mod-2);
	f[1]=invf[1]=1,dfs(1),dfs2(1),printf("%d\n",ans);
}

Measured memory_bytes: 32284
#include <stdio.h>

int W, H, x, y, r;
int main(){
	scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);
	if (y+r>H){
		printf("No\n");	
	}
		else if (y-r<0){
		printf("No\n");
		}
		else if (x+r>W){
		printf("No\n");
		}
		else if (x-r<0){
		printf("No\n");
		}
	if (x+r<=W && x-r>=0 && y+r<=H && y-r>=0){
		printf("Yes\n");
	}
	return 0;
}


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

using namespace std;
typedef long long ll;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll x,y;
    cin>>x>>y;
    if(x==1)
    {
        if(y==1)
        {
            cout<<1;
            return 0;
        }
        cout<<y-2;
        return 0;
    }
    if(y==1)
    {
        cout<<x-2;
        return 0;
    }
    ll mul=x*y;
    mul-=(x*2);
    mul-=((y-2)*2);
    cout<<mul;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for (int i = a; i <b; i++)
typedef long long ll;
#define int ll
typedef vector<int> vi;
typedef vector<long long> vl;
typedef pair<int,int> pi;
#define trace(x) cout<<#x<<"="<<x<<"\n";
#define sz(x) (int)(x.size())
#define mod 1000000007
#define endl "\n"
template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p ) {
    return os << "(" << p.first << ", " << p.second << ")";
}

template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
    os << "{";
    typename vector< T > :: const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "}";
}

template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
    os << "[";
    typename set< T > :: const_iterator it;
    for ( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "]";
}

template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v ) {
    os << "[";
    typename map< F , S >::const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << it -> first << " = " << it -> second ;
    }
    return os << "]";
}

#define deb(x) cerr << #x << " = " << x << endl;



int32_t main(){
    ios::sync_with_stdio(false);
    int x;
    cin>>x;
    int ans=(1000)*(x/500);
    x=x%500;
    ans+=(5*(x/5));
    cout<<ans<<"\n";    


    return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
ok = 0
even = 0
for i in range(n):
	if a[i]%2 == 0:
		even += 1
		if a[i]%3 == 0 or a[i]%5 ==0:
			ok += 1
if even == ok:
	print('APPROVED')
else:
	print('DENIED')

Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include <algorithm>
using namespace std;
int main(){
	string str, order1, str2,strf;
    int a,b,q;
    cin >> str;
    cin >> q;
    for (int i = 0; i < q; i++){
        cin >> order1 >>a >>b;
        if (order1 == "print"){
            cout << str.substr(a,b-a+1) <<endl;
        }
        else if (order1 == "reverse"){
            str2 = str.substr(a,b-a+1);
            reverse(str2.begin(), str2.end());
            str = str.substr(0,a) + str2 + str.substr(b +1);
           
        }
        else {
            cin >> str2;
            str = str.substr(0,a) + str2 + str.substr(b +1);
        }
    }
	return 0;
}



Measured memory_bytes: 3212
#define  _CRT_SECURE_NO_WARNiINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <fstream>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
using namespace std;
#define eps 0.000000001
#define LONG_INF 10000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 998244353
#define REP(i,n) for(long long i = 0;i < n;++i)
int bad[2000000] = {};
int main() {
#define int long long 
	int n;
	cin >> n;
	vector<pair<int, int>> hoge;
	REP(i, n) {
		int a, b;
		cin >> a >> b;
		hoge.push_back(make_pair(a, b));
	}
	long long ans = 0;
	for (int i = 0; i < 2; ++i) {
		priority_queue<pair<long long, long long>> right;
		priority_queue<pair<long long, long long>, vector<pair<long long, long long>>, greater<pair<long long, long long>>> left;
		for (int q = 0; q < n; ++q) {
			right.push(make_pair(hoge[q].first, q));
			left.push(make_pair(hoge[q].second, q));
			bad[q] = 0;
		}
		long long pre_ans = 0;
		long long now = 0;
		while (right.empty() == false || left.empty() == false) {
			while (right.empty() == false) {
				pair<long long, long long> a = right.top();
				right.pop();
				if (a.first > now) {
					if (bad[a.second] == 0) {
						bad[a.second] = 1;
						pre_ans += a.first - now;
						now = a.first;
						break;
					}
				}
			}
			while (left.empty() == false) {
				pair<long long, long long>b = left.top();
				left.pop();
				if (b.first < now) {
					if (bad[b.second] == 0) {
						bad[b.second] = 1;
						pre_ans += now - b.first;
						now = b.first;
						break;
					}
				}
			}
		}
		for (int q = 0; q < n; ++q) {
			hoge[q].first *= -1;
			hoge[q].second *= -1;
			swap(hoge[q].first, hoge[q].second);
		}
		ans = max(ans, pre_ans+abs(now));
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 7676
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vb = vector<bool>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1E9
#define LINF 1E17
#define EPS 1E-9
#define MOD 1000000007
#define PI 3.1415926535897932384

template<class S, class T>ostream& operator<<(ostream&os, pair<S, T>p) { os << "[" << p.first << ", " << p.second << "]"; return os; };
template<class S>auto&operator<<(ostream&os, vector<S>t) { bool a = 1; for (auto s : t) { os << (a ? "" : " ") << s; a = 0; } return os; }

//int dx[]={1,1,1,0,-1,-1,-1,0},dy[8]={1,0,-1,-1,-1,0,1,1,1};
//
constexpr ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }


int main() {
	int n, m, q;
	int in, inn;
	cin >> n >> m >> q;
	vvi vv(n,vi(n,0));
	rep(i, m) {
		cin >> in >> inn;
		vv[in - 1][inn - 1]++;
	}
	rep(j, n) {
		for (int i = n - 1; i > 0; i--) {
			vv[i - 1][j] = vv[i][j] + vv[i - 1][j];
		}
	}
	rep(i, n) {
		rep(j, n - 1) {
			vv[i][j + 1] = vv[i][j] + vv[i][j + 1];
		}
	}
	rep(i, n) {
		rep(j, n) {
			//printf("%3d", vv[i][j]);
		}
		//cout << endl;
	}


	rep(i, q) {
		cin >> in >> inn;
		cout << vv[in-1][inn-1]<< endl;
	}
}


Measured memory_bytes: 1920
#include <iostream>
#include <unordered_set>


using namespace std;

typedef long long ll;

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

    unordered_set<int> set;
    for (int i = 0; i < N; ++i)
    {
        int n;
        cin >> n;
        set.insert(n);
    }
    cout << set.size() << 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);
		final String s = sc.nextLine().trim();
		final String t = sc.nextLine().trim();
		
		for (int i =0,len = s.length(); i<len; i++) {
			if (strShift(s, i).equals(t)) {
				System.out.println("Yes");
				System.exit(0);
			}
		}
		System.out.println("No");
		sc.close();
	}
	
	private static String strShift(String s, int n) {
		n = n % s.length();
		return s.substring(s.length()-n, s.length()) + s.substring(0,s.length()-n);
	}
	
}


Measured memory_bytes: 21844
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace NotFounds
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve();
        }

        public void Solve()
        {
            var cin = new MyInputStream();
            var n = cin.ReadInt() - 1;
            var x = cin.ReadLong();
            for (int i = 0; i < n; ++i)
            {
                var t = cin.ReadLong();
                x = Lcm(x, t);
            }
            WriteLine(x);
        }

        private static void PrintYN(bool b)
        {
            //WriteLine(b ? "YES" : "NO");
            WriteLine(b ? "Yes" : "No");
        }

        private static string Reverse(string s)
        {
            return string.Join("", s.Reverse());
        }

        /// <summary>最大公約数</summary>
        public static long Gcd(long m, long n)
        {
            if (n == 0) return m;
            return Gcd(n, m % n);
        }

        /// <summary>最小公倍数</summary>
        public static long Lcm(long m, long n)
        {
            return m / Gcd(m, n) * n;
        }
    }

    public class MyInputStream
    {
        private char separator = ' ';
        private Queue<string> inputStream;
        public MyInputStream(char separator = ' ')
        {
            this.separator = separator;
            inputStream = new Queue<string>();
        }

        public string Read()
        {
            if (inputStream.Count != 0) return inputStream.Dequeue();
            string[] tmp = Console.ReadLine().Split(separator);
            for (int i = 0; i < tmp.Length; ++i)
                inputStream.Enqueue(tmp[i]);
            return inputStream.Dequeue();
        }
        public string ReadLine() { return Console.ReadLine(); }
        public int ReadInt() { return int.Parse(Read()); }
        public long ReadLong() { return long.Parse(Read()); }
        public double ReadDouble() { return double.Parse(Read()); }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read(); return ret;}
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt(); return ret;}
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong(); return ret;}
    }
}


Measured memory_bytes: 11220
import java.util.*;
// warm-up
// Solution Ripped from Editorial for self reference
// Cant get a clever brute force solution than this
public class Main {

	static void solve() {
		Scanner sc = new Scanner(System.in);
		StringBuilder path = new StringBuilder();
		int sx=sc.nextInt(), sy=sc.nextInt(), tx=sc.nextInt(), ty=sc.nextInt();
		int dx=tx-sx, dy=ty-sy;
		// Path 1
		path.append("U".repeat(dy)).append("R".repeat(dx));
		// Path 2
		path.append("D".repeat(dy)).append("L".repeat(dx));
		// Path 3
		path.append("L").append("U".repeat(dy+1)).append("R".repeat(dx+1)).append("D");
		// Path 4
		path.append("R").append("D".repeat(dy+1)).append("L".repeat(dx+1)).append("U");
		System.out.println(path);
		sc.close();			
	}

	public static void main(String args[]) {
		solve();
	}

}


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

typedef long long ll;
typedef unsigned long long ull;
//typedef long double ld;

typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef pair<double,double> pdd;
typedef set<int> si;
typedef set<ll> sll;
typedef vector<int> vi;
typedef vector<pair<int, int > > vii;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef vector<vll> vvll;

constexpr ll MOD = 1e9+7;
constexpr int INF = 1<<30;
constexpr ll  LINF = 1LL<<60;

#define Sort(x) sort(x.begin(),x.end())
#define Reverse(x) reverse(x.begin(),x.end())
#define ABS(a,b) ((a)<(b)?(b)-(a):(a)-(b))
#define nbit(n) (1ll<<(n))

// sort(begin(x), end(x), greater<ll>());
// lower_bound(a.begin(), a.end(), val): a[i] ≥ valである最左の位置
// upper_bound(a.begin(), a.end(), val): a[i] > valである最左の位置

// Returns minimum of a and b.
// If a is less b, a is set to b.
template<typename T>
T chmin(T& a, T b) {
  if (a > b) {
    a = b;
  }
  return a;
}

// Returns maximum of a and b.
// If a is less b, a is set to b.
template<typename T>
T chmax(T& a, T b) {
  if (a < b) {
    a = b;
  }
  return a;
}

// a = (a+b)%MOD;
void addmod(ll& a, ll b) {
  a = (a+b)%MOD;
}

template <typename T>
void dumpContents(const T& v, const string& msg)
{
  cerr << "### " << msg << " ###\n";
  for (const auto& x : v) {
    cerr << x << " ";
  }
  cerr << endl;
}

struct before_main_function {
  before_main_function() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<setprecision(20)<<fixed;
    #define endl "\n"
  }
} before_main_function;

// ========== end of template ==========

int main(int argc, char** argv) {
  int N,K;
  cin >> N >> K;
  cout << N - K + 1 << endl;

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

typedef long long ll;
typedef int keytype;

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

/* a[0], ..., a[n-1] の数の最大公約数 */
int ngcd(int n, int a[])
{
    int i, d;

    d = a[0];
    for (i = 1; i < n && d != 1; i++)
        d = gcd(a[i], d);
    return d;
}

void quicksort(keytype a[], int first, int last)
{
    int i, j;
    keytype x, t;

    x = a[(first + last) / 2];
    i = first;  j = last;
    for ( ; ; ) {
        while (a[i] < x) i++;
        while (x < a[j]) j--;
        if (i >= j) break;
        t = a[i];  a[i] = a[j];  a[j] = t;
        i++;  j--;
    }
    if (first  < i - 1) quicksort(a, first , i - 1);
    if (j + 1 < last) quicksort(a, j + 1, last);
}

int is_prime(int x){
    if(x <= 1) return 0;
    for(int i = 2; i * i <= x; i++){
        if(x % i == 0) return 0;
    }
    return 1;
}

int is_substr(char s[], char t[], int i){
    int flag = 1;

    if(s[i] == '\0') flag = 0;

    for(int j = 0; j < strlen(t); ++j, ++i){
        if(s[i] != t[j]){
            flag = 0;
            break;
        }
    }
    return flag;
}

// factor list, number of factors, natural number
void factorize(int ftr[], int *num, int n){
    int a = 2, cnt = 0;

    while(n >= a){
        if(n % a == 0){
            n = n / a;
            ftr[cnt++] = a;
        }else{
            a++;
        }
    }
    *num = cnt;
}

//#define N 5
//int p[N + 1];
int nextperm(int p[], int N)  /* 辞書式順序で次の順列 */
{
    int i, j, t;

    i = N - 1;
    p[0] = 0;  /* 番人 */
    while (p[i] >= p[i + 1]) i--;
    if (i == 0) return 0;  /* 完了 */
    j = N;
    while (p[i] >= p[j]) j--;
    t = p[i];  p[i] = p[j];  p[j] = t;
    i++;  j = N;
    while (i < j) {
        t = p[i];  p[i] = p[j];  p[j] = t;  i++;  j--;
    }
    return 1;  /* 未了 */
}

void comb(int size1, int size2, int v[size1][size2]){
  for(int i = 0; i < size1; i++){
    v[i][0] = 1;
    v[i][i] = 1;
  }
  for(int k = 1; k < size1; k++){
    for(int j = 1; j < k; j++){
      v[k][j] = (v[k-1][j-1] + v[k-1][j]);
    }
  }
}

int abs_val(int a, int b){
    if(a > b) return a - b;
    else return b - a;
}

int min(int a, int b){
    if(a > b) return b;
    else return a;
}

int max(int a, int b){
    if(a < b) return b;
    else return a;
}

const int inf = 1012345678;
int main(){
    int a, b, k;

    scanf("%d %d %d", &a, &b, &k);

    for(int i = a; i <= min(b, a + k - 1); ++i){
        printf("%d\n", i);
    }
    for(int i = max(b - k + 1, a + k); i <= b; ++i){
        printf("%d\n", i);
    }

#if 0
    int i = a;
    for(i = a; i < a + k && i <= b; ++i){
        printf("%d\n", i);
    }
    if(i < b - k){
        for(i = (b - k + 1); i <= b; ++i){
            printf("%d\n", i);
        }
    }else{
        for(i = a + k; i <= b; ++i){
            printf("%d\n", i);
        }
    }
#endif

    return 0;
}


Measured memory_bytes: 1700
#include<bits/stdc++.h>
using namespace std;
inline int minn(int a,int b)
{
    if(a>b)return b;
    else return a;
}
int main()
{
    long long int n,m,ans;
    cin>>n>>m;
    if(n>=m/2)ans=m/2;
    else ans=(n*2+m)/4;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define call(var) cout<<#var<<"="<<var<<endl;
#define dup(x,y) (((x)+(y)-1)/(y))
using ll=long long;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using Graph = vector<vi>;
using P = pair<int,int>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;
const int INTMAX = 2147483647;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}

int main(){
    map<int,int> mp;
    int n;cin >> n;
    rep(i,n){
        int a;cin >> a;
        ++mp[a];
    }
    int ret = 0;
    for(auto t : mp) if(t.second&1) ++ret;
    cout << ret << endl;
}

Measured memory_bytes: 4992
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();

        int count = 0;
        for (int i = a; i <= b; i++) {
            String s = String.valueOf(i);
            if (new StringBuilder(s).reverse().toString().equals(s)) {
                count++;
            }
        }

        System.out.println(count);
    }
}


Measured memory_bytes: 38868
n, m = map(int, input().split())
broken = {int(input()) for _ in range(m)}

mod = 10 ** 9 + 7

dp = [0] * (n + 1)
dp[0] = 1
if 1 not in broken:
    dp[1] = 1

for i in range(2, n + 1):
    if i -1 not in broken:
        dp[i] = dp[i] + dp[i - 1]
    if i - 2 not in broken:
        dp[i] = dp[i] + dp[i - 2]
    
    dp[i] %= 1000000007
    
print(dp[n])

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

#define ll long long
#define INF_LL 1LL << 60
#define INF 99999999
#define MOD (ll)1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, a, n) for(int i = a; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

void put_double(double obj){printf("%.12f\n",obj);};

template < typename T > std::string to_string( const T& n )
{
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}

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; }


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

    cout << "ABC" << N << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int p[10]={0,2,5,5,4,5,6,3,7,6},a[10],n,m,i,j,tmp,f[10002],v[10];
int main(){
	scanf("%d%d",&n,&m);
	for (i=1;i<=m;i++) scanf("%d",&a[i]),v[a[i]]=1;
	memset(f,-1,sizeof(f));
	f[0]=0;
	for (i=1;i<=m;i++)
		for (j=p[a[i]];j<=n;j++) f[j]=max(f[j],f[j-p[a[i]]]+1);
	tmp=f[n];
	for (i=1;i<=tmp;i++)
		for (j=9;j>=1;j--)
			if (v[j] && p[j]<=n && f[n-p[j]]==f[n]-1){
				printf("%d",j),n-=p[j];
				break;
			}
}

Measured memory_bytes: 256
import sys

def main():
  input = sys.stdin.readline
  H, W = map(int, input().split())
  A = [[0 for _ in range(W+2)] for _ in range(H+2)]
  for i in range(H):
    a = [0] + [int(c == '#') for c in input().strip()] + [0]
    A[i+1] = a
  
  ans = 'Yes'
  for i in range(H):
    for j in range(W):
      if A[i+1][j+1] == 1:
        u, d, r, l = A[i][j+1], A[i+2][j+1], A[i+1][j+2], A[i+1][j]
        if any([a == 1 for a in [u, d, r, l]]):
          continue
        else:
          ans = 'No'
          break
  print(ans)


if __name__ == '__main__':
  main()

Measured memory_bytes: 3064
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cassert>
using namespace std;

#define REP(i,n) for (int i = 0; i < n; i++)
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
typedef long long ll;

ll N;
string S;
ll Q;
ll accD[1000010];
ll accM[1000010];
ll accDM[1000010];

ll get_ans (ll k)
{
    fill (accDM, accDM + 1000010, 0);
    ll cntD = 0;
    ll cntM = 0;
    ll cntDM = 0;
    ll ret = 0;
    for (int i = 0; i < N; i++) {
        if (i >= k) {
            if (S[i - k] == 'D') {
                cntD--;
                cntDM -= cntM;
            }
            if (S[i - k] == 'M') {
                cntM--;
            }
        }
        if (S[i] == 'C') {
            ret += cntDM;
        } else if (S[i] == 'D') {
            cntD++;
        } else if (S[i] == 'M') {
            cntM++;
            cntDM += cntD;
        }
    }
    return ret;
}

int main ()
{
    cin >> N >> S >> Q;
    vector < ll > k(Q);
    REP(i,Q) cin >> k[i];
    
    REP(i,S.size()) {
        if (S[i] == 'D') accD[i + 1]++;
        accD[i + 1] = accD[i + 1] + accD[i];
    }

    REP(i,S.size()) {
        if (S[i] == 'M') accM[i + 1]++;
        accM[i + 1] = accM[i + 1] + accM[i];
    }

    REP(i,Q) cout << get_ans(k[i]) << endl;

    return 0;
}


Measured memory_bytes: 24836
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;

#define ll long long
#define P pair<int, int>
#define FOR(i, N) for (int i = 0; i < (int)N; i++)
#define FORIN(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define LAST(x) (x)[(x).size() - 1]
#define GI(name) \
  int(name);     \
  scanf("%d", &(name))
#define GI2(name1, name2) \
  int(name1), (name2);    \
  scanf("%d %d", &(name1), &(name2))
#define GI3(name1, name2, name3) \
  int(name1), (name2), (name3);  \
  scanf("%d %d %d", &(name1), &(name2), &(name3))
#define GVI(name, size)    \
  vector<int>(name)(size); \
  FOR(i, (size)) scanf("%d", &(name)[i])
#define GS(name) \
  string(name);  \
  cin >> (name);
#define MOD 1000000007
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

string to_string(string s) {
  return s;
}

template <class T>
string to_string(vector<T> v) {
  string ret = "{";
  FOR(i, v.size() - 1) { ret += to_string(v[i]) + ","; }
  if (v.size() > 0) {
    ret += to_string(LAST(v));
  }
  ret += "}";
  return ret;
}

void debug() {
  cerr << endl;
}

template <class Head, class... Tail>
void debug(Head head, Tail... tail) {
  cerr << to_string(head) << " ";
  debug(tail...);
}

void print() {
  cout << endl;
}

template <class Head, class... Tail>
void print(Head head, Tail... tail) {
  cout << to_string(head);
  print(tail...);
}

int main() {
  GI2(M, K);
  int s = 1 << M;
  s--;
  if (M == 0 && K == 0) {
    cout << "0 0" << endl;
    return 0;
  }
  if (M == 1 && K == 0) {
    cout << "0 0 1 1" << endl;
    return 0;
  }
  if (K <= s && (M > 1 || K > 1)) {
    FOR(i, (s + 1) * 2) {
      if (i < s) {
        cout << i + (i >= K) << " ";
      } else if (i == s) {
        cout << K << " ";
      } else if (i < (s + 1) * 2 - 1) {
        debug(i, (s + 1) * 2 - 1 - i);
        cout << s - (i - s - 1) - ((s + 1) * 2 - 1 - i <= K) << " ";
      } else {
        cout << K << endl;
      }
    }
  } else {
    print(-1);
  }
  return 0;
}

Measured memory_bytes: 1920
import java.util.*;

public class Main
{
	public static void main(String[] args)
	{
		try
		{
			Scanner sc = new Scanner(System.in);
			int n, s, min, max, ave;

			while(true)
			{
				min = 0;
				max = 0;
				ave = 0;

				n = sc.nextInt();
				if(n == 0)
				{
					break;
				}

				for(int i = 0; i < n; i++)
				{
					s = sc.nextInt();
					ave += s;

					if(i == 0)
					{
						min = s;
						max = s;
					}
					else if(i == 1)
					{
						if(s <= min)
						{
							min = s;
						}
						else
						{
							max = s;
						}
					}

					if(s <= min)
					{
						min = s;
					}
					if(s >= max)
					{
						max = s;
					}
				}
				ave -= min;
				ave -= max;
				ave /= (n - 2);

				System.out.println(ave);
			}
		}
		catch(InputMismatchException e)
		{
			System.out.println(e);
		}
	}
}

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

#define ll long long
#define mp make_pair
#define pb push_back

int n;
pair <int, pair <int, int> > v[5005];
ll f[5005][5005];

int main() {
	ios :: sync_with_stdio(0);
	cin >> n;
	for (int i = 0; i < n; ++ i) {
		cin >> v[i].second.first >> v[i].second.second;
		v[i].first = v[i].second.first + v[i].second.second;
	}
	sort(v, v + n);
	memset(f, 0x3f, sizeof(f));
	f[0][0] = 0;
	for (int i = 0; i < n; ++ i) {
		int h = v[i].second.first;
		int p = v[i].second.second;
		for (int j = 0; j <= i; ++ j) {
			//
			if (f[i][j] <= h)
				f[i + 1][j + 1] = min(f[i + 1][j + 1], f[i][j] + p);
			//
			f[i + 1][j] = min(f[i + 1][j], f[i][j]);
		}
	}
	int ans = 0;
	for (int i = 0; i <= n; ++ i)
		if (f[n][i] < 0x3f3f3f3f3f3f3f3f)
			ans = i;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 195968
#include<stdio.h>
#define LEN 100
void swap(int *a,int *b){
  int temp = *a;
  *a = *b;
  *b = temp;
}
void print(int N,int A[]){
  for(int i = 0; i < N; i++){
    if(i < (N - 1) ){
      printf("%d ",A[i]);
    }else{
      printf("%d",A[i]);
    }
  }
  putchar('\n');
}

int selection(int N,int A[]){
  int cnt = 0;
  for(int i = 0; i < N; i++){
    int minj = i;
    for(int j = i; j < N; j++){
      if(A[j] < A[minj]){
        minj = j;
      }
    }
    swap(&A[i],&A[minj]);
    if(i != minj) cnt++;
  }
  return cnt;
}


int main(){
  int N;
  scanf("%d",&N);
  int A[LEN];
  for(int i = 0; i < N; i++){
    scanf("%d",&A[i]);
  }

  int cnt = selection(N,A);
  print(N,A);
  printf("%d\n",cnt);
}



Measured memory_bytes: 2048
// 1192_TaxRateChanged.cpp
// 税率がx%の価格でループを回すのではなく、税抜き価格でループを回すのがポイント
#include <bits/stdc++.h>
using namespace std;
const int MAX_S = 1010;
int x, y, s;
int p[MAX_S];
void solve() {
  memset(p, 0, sizeof(p));
  for(int i = 1; i < s; ++i)
    for(int j = 1; j < s; ++j)
      if(i*(100+x)/100 + j*(100+x)/100 == s) p[i] = i*(100+y)/100 + j*(100+y)/100;

  cout << *max_element(p, p + s) << endl;
}
int main() {
  while(cin >> x >> y >> s) {
    if(x == 0 && y == 0 && s == 0) break;
    solve();
  }
  return 0;
}



Measured memory_bytes: 3056
#include <iostream>
#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#include <algorithm>
#include <bits/stdc++.h>
#define MOD 1000000007
#define ll long long
#define mm(arr) memset(arr, 1, sizeof(arr))
#define scanArray(a,n) for(int i = 0; i < n; i++){cin >> a[i];}
using namespace std;

int main(){
    FAST
    string s; cin >> s;
    ll sum=0;
    for(int i=0; i<s.size(); i++){
        sum+=s[i]-'0';
    }
    if(sum%9 == 0){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }






    return 0;
}


Measured memory_bytes: 3692
A, B = gets.split.map{|i|i.to_i}
minA = (A * 100 / 8.0).ceil
maxA = (A + 1) * 100 / 8 - 1 
minB = (B * 100 / 10.0).ceil
maxB = (B + 1) * 100 / 10 - 1
warn "%d-%d %d-%d" % [minA, maxA, minB, maxB]
if maxA < minB or maxB < minA
    puts -1
else
    puts [minA, minB].max
end


Measured memory_bytes: 1788