akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using loop = int;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(loop (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(loop (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(loop (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(loop (i)=(n);(i)>=(a);--(i))
#define each(i, a) for(auto &i : a)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause") //comment out this on AOJ.
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
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; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }

VL memo;
ll lucas(int n) {
    if (n == 0)return 2LL;
    if (n == 1)return 1LL;
    if (memo[n] != -1)return memo[n];
    return memo[n] = lucas(n - 1) + lucas(n - 2);
}

int main() {
    init();

    int n; cin >> n;
    memo.resize(n + 1, -1);
    cout << lucas(n) << "\n";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
#define repo(i, n) for(int i=1; i<=n; i++)
#define INF 1001001001

using namespace std;
using ull = unsigned long long;
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;

string minstring(string s1, string s2){
  int s=s1.size();
  rep(i, s){
    int s1i=s1[i]-'a';
    int s2i=s2[i]-'a';
    if(s1i>s2i){
      return s2;
    } else if(s1i<s2i){
      return s1;
    }
  }
  return s2;
}

int main(){
  string s, t;
  cin >> s >> t;
  int ssize=s.size();
  int tsize=t.size();
  if(ssize<tsize){
    cout << "UNRESTORABLE" << endl;
    return 0;
  }
  vector<int> index;
  for(int i=ssize-tsize; i>=0; i--){
    bool flag=false;
    for(int j=i; j<i+tsize; j++){
      if(s[j]!=t[j-i] && s[j]!='?'){
        flag=true;
        break;
      }
    }
    if(!flag){
      index.push_back(i);
      /*
      for(int j=i; j<i+tsize; j++){
        s[j]=t[j-i];
      }
      */
    }
    if(i==0 && index.size()==0){
      cout << "UNRESTORABLE" << endl;
      return 0;
    }
  }
  vector<string> ans;
  rep(i, index.size()){
    string cand=s;
    for(int j=index[i]; j<index[i]+tsize; j++){
      cand[j]=t[j-index[i]];
    }
    rep(i, ssize){
      if(cand[i]=='?'){
        cand[i]='a';
      }
    }
    ans.push_back(cand);
  }
  string S=ans[0];
  repo(i, ans.size()-1){
    S=minstring(S, ans[i]);
  }
  cout << S << endl;
  return 0;
}


Measured memory_bytes: 256
A,B,c,X,Y = map(int,input().split())
ans = 0

if X >= Y:
    x=X ; y=Y ; a=A ; b=B
else:
    x=Y ; y=X ; a=B ; b=A
    
if 2*c < a+b:
    ans += 2*c*y
    if x!=y:
        if 2*c < a:
            ans += 2*c*(x-y)
        else:
            ans += a*(x-y)
else:
    ans += a*x + b*y
    
print(ans)

Measured memory_bytes: 3064
import java.util.Scanner

import scala.collection.mutable

object Main {
  def main(args: Array[String]) {
    if (args.length > 0 && args(0) == "TEST") {
      println(test())
    } else {
      val input = io.Source.stdin.getLines().mkString("\n")
      println(solve(input).trim())
    }
  }

  val mod = 1000000007L


  def solve(input: String): String = {
    val s: Scanner = new Scanner(input)
    val n,m = s.nextInt
    var a: Array[Boolean] = new Array[Boolean](n+1)
    for (_ <- 0 until m) {
      a(s.nextInt) = true
    }
    var (s0, s1) = (1L, 1L)
    var st = 0L
    for (i <- 1 to n) {
      s1 = if (a(i)) 0L else s1
      st = (s0 + s1) % mod
      s0 = s1
      s1 = st
      if (s0 == 0L && s1 == 0L) return 0.toString
    }
    s0.toString
  }

  val tests = List(
    """6 1
      |3
    """.stripMargin -> """4""",
    """10 2
      |4
      |5
    """.stripMargin -> """0""",
    """100 5
      |1
      |23
      |45
      |67
      |89
    """.stripMargin -> """608200469"""
  )

  def test(): String = tests.map { case (i, o) => (i.trim(), o.trim()) }
    .zipWithIndex.map {
    case ((input, outputExpect), i) =>
      val output = solve(input).trim()
      val tnum = i + 1
      s"test$tnum:" + (
        if (output == outputExpect) "Passed"
        else s"Failed\nexpect:\n$outputExpect\noutput:\n$output")
  }
    .mkString("\n")
}

Measured memory_bytes: 54328
//#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define MP make_pair
#define PB push_back
#define MOD 1000000007
#define INF (1LL<<30)
#define LLINF (1LL<<60)
#define PI 3.14159265359
#define EPS 1e-12
//#define int ll

struct edge {int to, cost;};
vector<edge> g[105];
//
int d[105][105], e[105];
signed main(void)
{
    //????????°?????¶????????????????????°
    while(true) {
        int n, m, l, k, a, h;
        cin >> n >> m >> l >> k >> a >> h;
        if(!n && !m && !l && !k && !a && !h) break;
        REP(i, n) e[i] = 0;
        REP(i, l) {
            int ee;
            cin >> ee;
            e[ee] = 1;
        }
        REP(i, n) g[i].erase(ALL(g[i]));
        REP(i, k) {
            int x, y, t;
            cin >> x >> y >> t;
            g[x].PB({y, t});
            g[y].PB({x, t});
        }

        priority_queue<VI, VVI, greater<VI>> que;
        fill(d[0], d[105], INF);
        d[m][a] = 0;
        que.push({m, 0, a});

        while(que.size()) {
            VI v = que.top(); que.pop();
            //cout << v[0] << " " << v[1] << " " << v[2] << endl;
            if(d[v[0]][v[2]] < v[1]) continue;
            //??????????¨??????????
            if(e[v[2]]) {
                REP(i, g[v[2]].size()) {
                    //cout << "i:" << i << " " << g[v[2]][i].to << " " << g[v[2]][i].cost << endl;
                    FOR(j, v[0], m+1) {
                        edge e = g[v[2]][i];
                        if(j-e.cost >= 0 && d[j-e.cost][e.to] > d[v[0]][v[2]] + e.cost + j - v[0]) {
                            d[j-e.cost][e.to] = d[v[0]][v[2]] + e.cost + j - v[0];
                            que.push({(int)j-e.cost, d[j-e.cost][e.to], e.to});
                            //cout << "a:" << j-e.cost << " " << d[j-e.cost][e.to] << " " << e.to << endl;
                        }
                    }
                }
            } else {
                for(edge i: g[v[2]]) {
                    //cout << i.to << ":" << i.cost << " " << d[v[0]-i.cost][i.to] << " " << d[v[0]][v[2]] + i.cost << endl;
                    if(v[0]>=i.cost && d[v[0]-i.cost][i.to] > d[v[0]][v[2]] + i.cost) {
                        d[v[0]-i.cost][i.to] = d[v[0]][v[2]] + i.cost;
                        que.push({v[0]-i.cost, d[v[0]-i.cost][i.to], i.to});
                        //cout << "b:" << v[0] - i.cost << " " << d[v[0]-i.cost][i.to] << " " << i.to << endl; 
                    }
                }
            }
        }

        /*REP(i, n) {
            REP(j, m+1) {
                cout << d[j][i] << " ";
            }
            cout << endl;
        }*/

        int ans = INF;
        REP(i,m+1) ans = min(ans, d[i][h]);
        if(ans!=INF)cout << ans << endl;
        else cout << "Help!" << endl;
    }

	return 0;
}

Measured memory_bytes: 4740
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
const int N=1e5+10;
int a[N],b[N],c[N];
int main(){
    int n;
    cin>>n;
    int ans=0;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        b[i]=__gcd(a[i],b[i-1]);
    }
    ans=0;
    for(int i=n;i>=1;i--){
        c[i]=__gcd(a[i],c[i+1]);
    }
    ans=0;
    for(int i=1;i<=n;i++){
        int x=__gcd(b[i-1],c[i+1]);
        if(ans<x) ans=x;
    }
    printf("%d\n",ans);
    //system("pause");
}


Measured memory_bytes: 1408
c = input()
alp = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]
for i in range(len(alp)):
    if c == alp[i]:
        print(alp[i + 1])

Measured memory_bytes: 38256
#include <iostream>
using namespace std;
string s;
int ans = 0;

int main(){
  	cin >> s;
  	int len = s.length();
  	for (int i = 0; i < len; i++)
      	if (s[i] == '0')
          	ans++;
  	ans = min(ans, len - ans);
  	ans *= 2;
  	cout << ans << endl;
  	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#define rep(i,s,n)for(int i = s;i<n;i++)
#define repe(i,s,n)for(int i = s;i<=n;i++)
using namespace std;
static const int MAX_V = 100000;

//Graph Element
struct E {
	E(int t, int f) {
		to = t;
		from = f;
	}
	E(int t, int f, int c) {
		to = t;
		from = f;
		cost = c;
	}
	int to;
	int from;
	int cost;
	bool visited;
	bool use;
};
struct V {
	vector<E*> edge;
	bool visited;
};
V G[MAX_V];
/////////////////////////////////////////////

//dfs
int ans = 0;
int VS, ES;
void dfs(int n) {
	rep(i, 0, G[n].edge.size()) {
		if (G[n].edge[i]->use && !G[G[n].edge[i]->to].visited) {
			G[G[n].edge[i]->to].visited = true;
			dfs(G[n].edge[i]->to);
		}
	}
}

//
void bfs(int n) {
	int q[1000] = {};
	int s = 0, e = 0;
	q[e++] = n;
	int c = 0;

	while (s < e) {
		c = q[s++];
		G[c].visited = true;

		rep(i, 0, G[c].edge.size()) {
			if (G[c].edge[i]->use && !G[G[c].edge[i]->to].visited) {
				q[e++] = G[c].edge[i]->to;
			}
		}
	}
}

int main() {
	cin >> VS >> ES;

	rep(i, 0, ES)
	{
		int s, t; cin >> s >> t;
		G[s].edge.push_back(new E(t, s));
		G[t].edge.push_back(new E(s, t));
	}

	///////////////////////////////////////////////////////////
	//DFS
	//Edge all false
	repe(i, 1, VS) rep(j, 0, G[i].edge.size()) {
		//Edge all visited false;
		repe(k, 1, VS) rep(l, 0, G[k].edge.size()) G[k].edge[l]->use = true;
		repe(k, 1, VS) G[k].visited = false;

		G[i].edge[j]->use = false;

		//DFS
		G[1].visited = true;
		//dfs(1);
		bfs(1);

		bool ok = true;
		repe(k, 1, VS)  ok &= G[k].visited;
		if (!ok)ans++;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3456
#include<bits/stdc++.h>
using namespace std;
int main(){
    long a,v,b,w,t;
    cin >> a >> v;
    cin >> b >> w;
    cin >> t;
    if(v<=w){
        cout << "NO"<<endl;
    }else{
        if((v-w)*t >= abs(a-b))cout<<"YES"<<endl;
        else cout <<"NO"<<endl;

    }
}

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

int main(){
    int h, w; cin >> h >> w;
    int n; cin >> n;
    int a[n];
    for(int i = 0; i < n; ++i) cin >> a[i];
    int t = 0, y = 0;
    int ans[h][w];
    for(int i = 0; i < n; ++i){
        if(y + a[i] < w){
            for(int j = 0; j < a[i]; ++j){
                ans[t][y + j] = i + 1;
            }
            y += a[i];
        }else{
            for(int j = 0; j + y < w; ++j){
                ans[t][y + j] = i + 1;
                --a[i];
            }
            y = 0;
            ++t;
            int tate = a[i] / w;
            a[i] %= w;
            y += a[i];
            for(int j = 0; j < tate; ++j){
                for(int k = 0; k < w; ++k){
                    ans[t + j][k] = i + 1;
                }
            }
            t += tate;
            for(int j = 0; j < a[i]; ++j){
                ans[t][j] = i + 1;
            }
        }
    }
    for(int i = 0; i < h; ++i){
        if((i & 1)){
            for(int j = 0; j < w; ++j){
                cout << ans[i][j] << " ";
            }
        }else{
            for(int j = w - 1; j >= 0; --j){
                cout << ans[i][j] << " ";
            }
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int main()
{
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    if (s[0] == s[1] && s[2] == s[3] && s[0] != s[2]) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
a,b,c =map(int,input().split())

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    # divisors.sort()
    return divisors

print(len([x for x in make_divisors(c) if a<=x and x<=b]))


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

int main(){
    int n, W; cin >> n >> W;
    int w[n], v[n];
    for(int i=0;i<n;i++)
        cin >> w[i] >> v[i];
    
    ll dp[W+10];
    fill(dp, dp+W+10, -1);
    dp[0] = 0;
    for(int i=0;i<n;i++){
        int val=v[i], wgt=w[i];
        for(int j=W;j>=wgt;j--){
            if (dp[j-wgt] != -1)
                dp[j] = max(dp[j], dp[j-wgt] + val);
        }
    }

    for(int i=0;i<=W;i++)
        cerr << dp[i] << " \n"[i==W];
    ll ans=0;
    for(int i=0;i<=W;i++) ans = max(ans, dp[i]);
    cout<< ans << endl;
}

Measured memory_bytes: 3968
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using uint = unsigned int;
#define rep(i,n) for(int i=0;i<int(n);i++)
#define rep1(i,n) for(int i=1;i<=int(n);i++)
#define per(i,n) for(int i=int(n)-1;i>=0;i--)
#define per1(i,n) for(int i=int(n);i>0;i--)
#define all(c) c.begin(),c.end()
#define si(x) int(x.size())
#define pb emplace_back
#define fs first
#define sc second
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
template<class T,class U> void chmax(T& x, U y){if(x<y) x=y;}
template<class T,class U> void chmin(T& x, U y){if(y<x) x=y;}
template<class T> void mkuni(V<T>& v){sort(all(v));v.erase(unique(all(v)),v.end());}
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

#ifdef LOCAL
#define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl
void dmpr(ostream& os){os<<endl;}
template<class T,class... Args>
void dmpr(ostream&os,const T&t,const Args&... args){
	os<<t<<" ~ ";
	dmpr(os,args...);
}
#define shows(...) cerr << "LINE" << __LINE__ << " : ";dmpr(cerr,##__VA_ARGS__)
#define dump(x) cerr << "LINE" << __LINE__ << " : " << #x << " = {";  \
	for(auto v: x) cerr << v << ","; cerr << "}" << endl;
#else
#define show(x) void(0)
#define dump(x) void(0)
#define shows(...) void(0)
#endif

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);		//DON'T USE scanf/printf/puts !!
	cout << fixed << setprecision(20);

	ll s,c; cin >> s >> c;
	auto can = [&](ll x,ll s,ll c){
		c -= x+x;
		if(c<0) return false;
		return s+c/2 >= x;
	};
	ll ub = 1e12, lb = -1;
	while(ub-lb>1){
		ll m = (lb+ub)/2;
		if(can(m,s,c)) lb = m;
		else ub = m;
	}
	cout << lb << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#define pb push_back
#define IOS                                                                    \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0);cout<<fixed<<setprecision(16);
#define ll long long int
#define ld long double
#define el '\n'
#define El '\n'
#define PI (ld)3.141592653589793238462643383279502884197169399375105820974944
#define inf (ll)1000000000
#define mod (ll)1000000007
#define mod1 (ll)998244353
#define fo(i, n) for (long long i = 0; i < n; i++)
#define pll pair<ll, ll>
#define ml map<ll,ll>
#define vpl vector<pll>
#define vvl vector<vector<ll> >
#define vvpl vector< vector<pll> >
#define ff first
#define ss second
#define pqueue priority_queue< ll >
#define pdqueue priority_queue< ll,vl ,greater< ll > >
#define mem(a,b) memset(a,b,sizeof(a));
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define sz(a) (ll)a.size()
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fd(i,a,b) for(ll i=a;i>=b;i--)
#define all(a) a.begin(),a.end()
#define vl vector<ll>
//#define x ff
//#define y ss
#define pt(a) for(auto it:a)cout<<it<<" ";cout<<endl;
unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
using namespace std;

// vector
template<class T> istream& operator >> (istream &is , vector<T> &v) { for(T &a : v) is >> a; return is; }
template<class T> ostream& operator << (ostream &os , const vector<T> &v) { for(const T &t : v) os << t<<" "; return os << endl; }
// pair
template<class T, class U> ostream& operator << (ostream &os , const pair<T, U> &v) { return os << v.first << " " << v.second ; }

double gcd(double a, double b) { return a < 0.01 ? b : gcd(fmod(b, a), a); }

long long bpow(long long a, long long b, long long m) {
  a %= m;
  long long res = 1;
  while (b > 0) {
    if (b & 1)

      res = res * a % m;
      a = a * a % m;
      b >>= 1;
  }
  return res;
}


ll kv;
ll t,n,x,y,h,k,z,p,q,w;
string s,s1,s2;
//vvl v;
//vl vis,d;

int main() {
    IOS;
    cin>>n;
    vl v(n);cin>>v;
    fo(i,n)v[i]*=2,p+=v[i]*((i%2==0)-(i%2==1));
    vl a(n);a[0]=p/2;
    fo(i,n-1)a[i+1]=v[i]-a[i];
    pt(a);
    return 0;
}


Measured memory_bytes: 2944
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x) cout << #x << ' ' << '=' << ' ' << (x) << endl;
#define fs first
#define sc second
#define pb push_back
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
typedef priority_queue<ll> PQI;
typedef priority_queue<P> PQP;
typedef vector<vector<P>> pvec;
typedef vector<vector<ll>> vvec;
typedef vector<ll> vec;
const vector<int> dx = {0, -1, 0, 1, 1, 1, -1, -1};
const vector<int> dy = {1, 0, -1, 0, 1, -1, 1, -1};
const int MOD = (1000000007);
// const int MOD = (998244353);
// const int INF = (1 << 30);
const int INF = (1LL << 60);
const double EPS = (1 >> 30);
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}



signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);
    //---------------------------------------------
    
    int n; cin>>n;
    vector<string> s(n);
    REP(i,n) cin >> s[i];

    map<string,int> mp;
    rep(i,n){
        mp[s[i]]++;
    }

    ll MAX=0;
    for(auto x : mp){
        chmax(MAX,x.sc);
    }
    for(auto x : mp){
        if(MAX==x.sc){
            cout<<x.fs<<endl;
        }
    }
    
}


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

int main(){
    int n, k;
    cin >> n >> k;

    n -= k;

    if(n == 0){
        cout << 0 << endl;
    }else if(k == 1){
        cout << 0 << endl;
    }else{
        cout << n << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

string s;

int main(void)
{
	cin >> s;
	int i, j;
	for(i = 0; i < s.size(); i++){
		if(s[i] == 'A') break;
	}
	for(j = s.size()-1; j >= 0; j--){
		if(s[j] == 'Z') break;
	}
	
	cout << j - i + 1 << endl;
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)     for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = m; i < (int)(n); i++)
#define MOD 1000000007
#define Graph vector<vector<int>>
#define lint int64_t

int main(){
    lint N,M;
    cin >> N >> M;
    
    vector<pair<lint,lint>> p(N);

    rep(i,N){
        lint ai,bi;
        cin >> ai >> bi;
        p.at(i) = make_pair(ai,bi);
    }

    sort(p.begin(),p.end());

    lint cost = 0;
    lint BuyCnt = 0;
    rep(i,N){
        lint ai,bi;
        tie(ai,bi) = p.at(i);
        
        if(bi > (M - BuyCnt)){
            cost += ai * (M - BuyCnt);
            BuyCnt += (M - BuyCnt);
            break;
        }else{
            cost += ai * bi;
            BuyCnt += bi;
        }
    }

    cout << cost << endl;
    return 0;
}


Measured memory_bytes: 1792
#include <algorithm>
#include<stdio.h>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stack>
#include <queue>
#include <deque>     
#include<map>
#include <set>
#include<math.h>
using namespace std;
#define int long long
#define ll long long
#define ld long double
#define rep(i,n) for(ll i=0;i<n;++i)
#define Rep(i,n) for(ll i=1;i<=n;++i)
#define loop(i,m,n) for(ll i=m;i<n;++i)
#define rev(i,n) for(ll i=n-1;i>=0;--i)
#define ggr getchar(); getchar();return 0;
#define pie 3.141592653589793238462643383279
#define elif else if
#define P pair<ll,ll>
#define prique priority_queue<ll>
#define all(a)  (a).begin(),(a).end()
const int mod = 1000000007;
const int mod2 = 998244353;
int bin(int bina) {
	int ans = 0;
	for (int i = 0; bina > 0; i++)
	{
		ans = ans + (bina % 2) * pow(10, i);
		bina = bina / 2;
	}
	return ans;
}
bool prime(int n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x,y)* mod_pow(kai(y,y), mod - 2, mod) % mod;
}
int per(int n, int r) {
	r = n - r;
	int sum = 1;
	int i;
	for (i = n; i >= r + 1; i--)sum *= i;
	return sum;
}
struct UnionFind {
	vector<int> par;

	UnionFind(int n) : par(n, -1) { }

	int root(int x) {
		if (par[x] < 0) return x;
		else return par[x] = root(par[x]);
	}

	bool issame(int x, int y) {
		return root(x) == root(y);
	}

	bool merge(int x, int y) {
		x = root(x); y = root(y);
		if (x == y) return false;
		if (par[x] > par[y]) swap(x, y);
		par[x] += par[y];
		par[y] = x;
		return true;
	}

	int size(int x) {
		return -par[root(x)];
	}
};
//cout << fixed << setprecision(10) << num << endl;

signed main() {
	int a;
	cin >> a;
	cout << a * a * a << endl;
}

Measured memory_bytes: 256
//#include <fstream>
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <queue>

using namespace std;

//ifstream cin("x.in"); ofstream cout("x.out");

typedef long long i64;
const int nmax = 1e5;
const i64 inf = (1LL << 60);
const int mod = 1e9 + 7;

int n;
vector<pair<int, int>> g[nmax + 1];
bool gata[nmax + 1];
i64 d[ 2 ][nmax + 1];
int c[ 2 ][nmax + 1];

struct muchie {
    int x, y, c;
};
vector< muchie > w;

struct str {
    int x; i64 dst;

    str () {}
    str (int _x, i64 _dst) {
        x = _x, dst = _dst;
    }

    inline bool operator < (const str &shp) const {
        if (dst != shp.dst)
            return (dst > shp.dst);
        return (x > shp.x);
    }
};
priority_queue< str > h;

void extinde (str k, int ind) {
    for (auto i : g[ k.x ]) {
        if (gata[ i.first ] == 1)
            continue;

        if (d[ ind ][ i.first ] > k.dst + i.second) {
            d[ ind ][ i.first ] = k.dst + i.second;
            h.push(str(i.first, d[ ind ][ i.first ]));
        }
    }
}

void afla_c (str k, int ind) {
    for (auto i : g[ k.x ]) {
        if (d[ ind ][ i.first ] + i.second == k.dst) {
            c[ ind ][ k.x ] += c[ ind ][ i.first ];

            if (c[ ind ][ k.x ] >= mod)
                c[ ind ][ k.x ] -= mod;
        }
    }
}

void dijkstra (int sursa, int ind) {
    for (int i = 1; i <= n; ++ i)
        d[ ind ][ i ] = inf;

    memset(gata, 0, sizeof(gata));
    h.push(str(sursa, 0));
    d[ ind ][ sursa ] = 0;
    c[ ind ][ sursa ] = 1;

    while (!h.empty()) {
        str x = h.top();
        h.pop();

        if (gata[ x.x ] == 1)
            continue;

        gata[ x.x ] = 1;
        extinde(x, ind);

        if (x.x != sursa)
            afla_c(x, ind);
    }
}

int main() {
    int m, s, t;
    cin >> n >> m >> s >> t;

    for (int i = 1; i <= m; ++ i) {
        int x, y, cst;
        cin >> x >> y >> cst;

        g[ x ].push_back(make_pair(y, cst));
        g[ y ].push_back(make_pair(x, cst));

        muchie aux;
        aux.x = x; aux.y = y; aux.c = cst;
        w.push_back( aux );
    }

    dijkstra(s, 0);
    dijkstra(t, 1);

    long long ans = 1LL * c[ 0 ][ t ] * c[ 0 ][ t ] % mod;

    for (int i = 1; i <= n; ++ i) {
        /// pp se intalnesc fix in i
        if (d[ 0 ][ i ] == d[ 1 ][ i ] && d[ 0 ][ i ] + d[ 1 ][ i ] == d[ 0 ][ t ]) {
            long long alegi = 1LL * c[ 0 ][ i ] * c[ 1 ][ i ] % mod;

            ans = (ans - alegi * alegi) % mod;
            if (ans < 0)
                ans += mod;
        }
    }

    for (auto i : w) {
        int x = i.x, y = i.y;
        if (d[ 0 ][ x ] > d[ 0 ][ y ])
            swap(x, y);

        if (d[ 0 ][ x ] + i.c + d[ 1 ][ y ] != d[ 0 ][ t ])
            continue;

        if (abs(d[ 0 ][ x ] - d[ 1 ][ y ]) >= i.c) // nu se intalensc pe muchie
            continue;

        long long alegm = 1LL * c[ 0 ][ x ] * c[ 1 ][ y ] % mod;

        ans = (ans - alegm * alegm) % mod;
        if (ans < 0)
            ans += mod;
    }

    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 17068
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int numA = sc.nextInt();
        int numB = sc.nextInt();
        int numC = sc.nextInt();
        List<Integer> numAList = getNums(numA);
        List<Integer> numBList = getNums(numB);

        List<Integer> commonList = new ArrayList<>();
        for (int num : numAList) {
            if (numBList.contains(num)) {
                commonList.add(num);
            }
        }
        commonList.sort(Comparator.reverseOrder());
        System.out.println(commonList.get(numC- 1));
    }

    public static List<Integer> getNums(int num) {
        List<Integer> numList = new LinkedList<>();
        for (int n = 1; n <= num; n++) {
            if (num % n == 0) {
                numList.add(n);
            }
        }
        return numList;
    }
}

Measured memory_bytes: 22736
N = int(input())
D = list(map(int, input().split()))
MOD = 998244353

count = [0] * N
for d in D:
    count[d] += 1

if (D[0] != 0 or count[0] >= 2):
    print(0)
    exit()
ans = 1
for i in range(N):
    if (i > 0):
        ans *= (count[i - 1] ** count[i]) % MOD
        ans %= MOD

print(ans)


Measured memory_bytes: 14396
N, P = map(int, input().split())
A = [int(x) for x in input().split()]

odd = False
for i in range(N):
    if A[i] % 2 == 1:
        odd = True
        break

if odd:
    print(2**(N-1))
else:
    if P == 0:
        print(2**N)
    else:
        print(0)

Measured memory_bytes: 9036
import numpy as np
N = int(input())
a = []
for i in range(N):
  a.append(int(input()))
aa = np.array(a)
max_a = max(aa)
k = np.argmax(aa)
aa[k] = 0
m = max(aa)


for i in range(N):
  if i == k:
    print(m)
  else:
    print(max_a)

Measured memory_bytes: 24904
from collections import deque
import itertools

def bfs(graph, sh, sw):
    td = deque([[sh, sw]])
    graph[sh][sw] = "0"
    while td:
        h, w = td.popleft()
        num = int(graph[h][w])
        for j, k in ([1, 0], [-1, 0], [0, 1], [0, -1]):
            new_h, new_w = h + j, w + k
            if new_h == gy and new_w == gx:
                return num + 1
                break
            
            if new_h < 0 or new_h >= H or new_w < 0 or new_w >= W:
                continue
            elif graph[new_h][new_w] == ".":
                graph[new_h][new_w] = str(num + 1)
                td.append([new_h, new_w])

    return -1

H, W = map(int, input().split())
ls = [[_ for _ in input()] for _ in range(H)]

sy, sx = 0, 0
gy, gx = H - 1, W - 1

bcnt = 0

for s, t in itertools.product(range(H), range(W)):
    if ls[s][t] == "#":
        bcnt += 1

nurazu = bfs(ls, sy, sx)
nurazu = nurazu + 1

if nurazu == 0:
    print(-1)
else:
    print(H * W - (bcnt + nurazu))

Measured memory_bytes: 3436
H,W,K=map(int,input().split())
S=[input() for i in range(H)]
P=0
Q=0
for i in range(1<<H):
  for j in range(1<<W):
    Q=0
    for k in range(H):
      for l in range(W):
        if S[k][l]=='#' and i&(1<<k)!=0 and j&(1<<l)!=0:
          Q+=1
    if Q==K:
      P+=1
print(P)


Measured memory_bytes: 68476
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
#include <map>
#include <cmath>
#include <iostream>
#include <deque>
#include <math.h>
#include <cstdio>
#include <set>
#include <iomanip>
typedef  long long ll;
using namespace std;

int main(void) {
	ll n;
	cin >> n;
	set<ll> a;
	for (int i = 0; i < n; i++)
	{
		ll b;
		cin >> b;
		a.insert(b);
	}

	if(a.size() == n) 	cout << "YES" << endl;
	else cout << "NO" << endl;

	return 0;
}

Measured memory_bytes: 9600
#include <bits/stdc++.h>
#define rep(i, l, r) for (register int i = l; i <= r; i++)
#define per(i, r, l) for (register int i = r; i >= l; i--)
#define srep(i, l, r) for (register int i = l; i < r; i++)
#define sper(i, r, l) for (register int i = r; i > l; i--)
#define erep(i, x) for (register int i = h[x]; i; i = e[i].next)
#define ll long long int 
#define maxn 20000019
#define maxm 20000019
#define pli pair<ll, int>
#define fi first
#define se second
using namespace std;

const int inf = 2000000019;

int n, m, s, t, hehe;

struct edge{
	int to, next, len;
	edge(int next, int to, int len) : next(next), to(to), len(len){}
	edge(){}
}e[maxm];
int cnt = 1, h[maxn];
void Add_Edge(int x, int y, int z){
	e[++cnt] = edge(h[x], y, z);
	h[x] = cnt;
}
void init(int l, int r, int o){
	if (o > 1) Add_Edge(o, o >> 1, 0);
	hehe = max(hehe, o);
	if (l == r) {
		if (l == 1) s = o;
		else if (l == n) t = o;
		return;
	}
	int mid = ((r - l) >> 1) + l;
	init(l, mid, o << 1), init(mid + 1, r, o << 1 | 1);
}
int qx, qy, qd, qnode;
int get(int l, int r, int o){
	if (l == r) return o;
	int mid = ((r - l) >> 1) + l;
	if (qy <= mid) return get(l, mid, o << 1);
	else return get(mid + 1, r, o << 1 | 1);
}
void add(int l, int r, int o){
	if (qx <= l && r <= qy){
		Add_Edge(o, qnode, qd);
		return;
	}
	int mid = ((r - l) >> 1) + l;
	if (qx <= mid) add(l, mid, o << 1);
	if (qy > mid) add(mid + 1, r, o << 1 | 1);
}

ll d[maxn];
bool vis[maxn];
priority_queue<pli> pq;
void Dij(){
	rep(i, 1, hehe) d[i] = (ll)inf * inf;
	d[s] = 0; pq.push(pli(-d[s], s));
	while (!pq.empty()) {
		pli op = pq.top(); pq.pop();
		if (vis[op.se]) continue;
		vis[op.se] = 1;
		int x = op.se;
		erep(i, x){
			int v = e[i].to;
			if (vis[v]) continue;
			if (d[v] > d[x] + e[i].len) {
				d[v] = d[x] + e[i].len;
				pq.push(pli(-d[v], v));
			}
		}
	}
}

/*queue<int> spfa;
ll d[maxn];
bool vis[maxn];
void SPFA(){
	rep(i, 1, hehe) d[i] = (ll)inf * inf;
	d[s] = 0, vis[s] = 1, spfa.push(s);
	while (!spfa.empty()) {
		int x = spfa.front(); spfa.pop();
		erep(i, x){
			int op = e[i].to;
			if (d[op] > d[x] + e[i].len) {
				d[op] = d[x] + e[i].len;
				if (!vis[op]) {
					vis[op] = 1;
					spfa.push(op);
				}
			}
		}
		vis[x] = 0;
	}
}*/

int main(){
	scanf("%d%d", &n, &m);
	init(1, n, 1);
	//printf("%d %d\n", s, t);
	rep(i, 1, m){
		scanf("%d%d%d", &qx, &qy, &qd);
		qnode = get(1, n, 1);
		//printf("%d\n", qnode);
		add(1, n, 1);
	}
	//SPFA();
	//rep(i, 1, t) printf("%d ", d[i]);
	Dij();
	if (d[t] == (ll)inf * inf) printf("-1");
	else printf("%lld", d[t]);
	return 0;
}

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

int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    
    
    int t;
    t=1;

    while(t--){
 		ll X,K,D;

 		cin>>X>>K>>D;

 		if(X<0)
 			X=-X;
 		ll ans = X/D;

 		
 		if(K<=ans){
 			ll ab = X-(D*K);
 			cout<<ab<<endl;
 		}
 		else{
 			K=K-ans;
 			if(K%2==0)
 			{
 				ll ab = X-(D*ans);
 				cout<<ab<<endl;
 			}
 			else{
 				ll ab=abs((X-(D*ans))-D);
 				cout<<ab<<endl;
 			}
 		}
    }
}

Measured memory_bytes: 3536
//import java.awt.*;
import java.io.*;
import java.math.*;
import java.text.*;
import java.util.*;

public class Main {
  public static void main(String[] args) {
    InputStream inputStream;
    if (args.length > 0 && args[0].equals("devTesting")) {
      try {
        inputStream = new FileInputStream(args[1]);
      } catch(FileNotFoundException e) {
        throw new RuntimeException(e);
      }
    } else {
      inputStream = System.in;
    }
    OutputStream outputStream = System.out;
    InputReader in = new InputReader(inputStream);
    PrintWriter out = new PrintWriter(outputStream);
    TaskA solver = new TaskA();
    solver.solve(1, in, out);
    out.close();
  }
  
  static class TaskA {
    char[] s;
    
    void solve(int testNumber, InputReader in, PrintWriter out) {
      s = in.next().toCharArray();
      Arrays.sort(s);
      boolean ans = true;
      if (Arrays.binarySearch(s, 'N') >= 0 != Arrays.binarySearch(s, 'S') >= 0 || Arrays.binarySearch(s, 'W') >= 0 != Arrays.binarySearch(s, 'E') >= 0) {
        ans = false;
      }
      out.println(ans ? "Yes" : "No");
    }

  }
      
  static class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
      reader = new BufferedReader(new InputStreamReader(stream));
      tokenizer = null;
    }

    public String next() {
      while (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          tokenizer = new StringTokenizer(reader.readLine());
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
      return tokenizer.nextToken();
    }
    
    public String nextLine() {
      try {
        return reader.readLine();
      } catch(IOException e) {
        throw new RuntimeException(e);
      }
    }

    public int nextInt() {
      return Integer.parseInt(next());
    }

    public long nextLong() {
      return Long.parseLong(next());
    }
    
    public double nextDouble() {
      return Double.parseDouble(next());
    }

    public boolean hasInput() {
      try {
        if (tokenizer != null && tokenizer.hasMoreTokens()) {
          return true;
        }
        reader.mark(1);
        int ch = reader.read();
        if (ch != -1) {
          reader.reset();
          return true;
        }
        return false;
      } catch(IOException e) {
        throw new RuntimeException(e);
      }
    }
    
  }
}


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

#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define endl '\n'

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;

const ll mod=1000000007;
//head

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

    int n;
    cin >> n;
    vector<ll> h(n+1);
    for(int i = 1; i <= n; i++) {
        cin >> h[i];
    }
    map<ll,ll> m;
    m[1+h[1]] = 1;
    ll ans = 0;
    for(int i = 2; i <= n; i++) {
        if(m.count(i - h[i])) {
            ans += m[i-h[i]];
        }
        if(m.count(i + h[i])) {
            m[i + h[i]]++;
        } else {
            m[i + h[i]] = 1;
        }
    }
    cout << ans << endl;
    return 0;
}


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

int main()
{
    int w, a, b;

    cin >> w >> a >> b;

    if ((a + w >= b && b >= a) || (b + w >= a && a >= b)) {
        cout << 0 << endl;
    } else {
        cout << min(abs((a + w) - b), min(abs(a - b), abs(a - (b + w)))) << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#define DEBUG 0

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

#if DEBUG
// basic debugging macros
int __i__,__j__;
#define printLine(l) for(__i__=0;__i__<l;__i__++){cout<<"-";}cout<<endl
#define printLine2(l,c) for(__i__=0;__i__<l;__i__++){cout<<c;}cout<<endl
#define printVar(n) cout<<#n<<": "<<n<<endl
#define printArr(a,l) cout<<#a<<": ";for(__i__=0;__i__<l;__i__++){cout<<a[__i__]<<" ";}cout<<endl
#define print2dArr(a,r,c) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<a[__i__][__j__]<<" ";}cout<<endl;}
#define print2dArr2(a,r,c,l) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<setw(l)<<setfill(' ')<<a[__i__][__j__]<<" ";}cout<<endl;}

// advanced debugging class
// debug 1,2,'A',"test";
class _Debug {
    public:
        template<typename T>
        _Debug& operator,(T val) {
            cout << val << endl;
            return *this;
        }
};
#define debug _Debug(),
#else
#define printLine(l)
#define printLine2(l,c)
#define printVar(n)
#define printArr(a,l)
#define print2dArr(a,r,c)
#define print2dArr2(a,r,c,l)
#define debug
#endif

// define
#define MAX_VAL 999999999
#define MAX_VAL_2 999999999999999999LL
#define EPS 1e-6
#define mp make_pair
#define pb push_back

// typedef
typedef unsigned int UI;
typedef long long int LLI;
typedef unsigned long long int ULLI;
typedef unsigned short int US;
typedef pair<int,int> pii;
typedef pair<LLI,LLI> plli;
typedef vector<int> vi;
typedef vector<LLI> vlli;
typedef vector<pii> vpii;
typedef vector<plli> vplli;

// ---------- END OF TEMPLATE ----------

int A[200000];
int pos[200001];
int dp[200001];
int nn[200001],nn2[200001];
vi vv;
int visited[200001];
int seen[200001];
int main() {
    int i;
    int N;
    LLI K;
    scanf("%d %lld",&N,&K);
    for (i = 0; i < N; i++) scanf("%d",&A[i]);

    int j;
    memset(pos,-1,sizeof(pos));
    dp[N] = 0;
    for (i = N-1; i >= 0; i--) {
        if (pos[A[i]] == -1) dp[i] = A[i];
        else dp[i] = dp[pos[A[i]]+1];
        pos[A[i]] = i;
    }
    nn[0] = dp[0];
    for (i = 0; i < N; i++) nn[A[i]] = dp[pos[A[i]]+1];
    int u = 0;
    for (i = 0; i < 60; i++) {
        if ((K-1) & (1LL << i)) u = nn[u];
        for (j = 0; j <= 200000; j++) nn2[j] = nn[nn[j]];
        for (j = 0; j <= 200000; j++) nn[j] = nn2[j];
    }
    if (u != 0) {
        for (i = 0; i < N; i++) {
            if (A[i] == u) break;
        }
    }
    else i = -1;
    vi ans;
    for (i++; i < N; i++) {
        if (!seen[A[i]]) ans.pb(A[i]),seen[A[i]] = 1;
        else {
            while (seen[A[i]]) seen[ans.back()] = 0,ans.pop_back();
        }
    }
    for (i = 0; i < ans.size(); i++) printf("%d ",ans[i]);
    printf("\n");

    return 0;
}



Measured memory_bytes: 7156
#include <iostream>
using namespace std;
int main(void){
    int a,b,x;
    cin >> a >> b >> x;
    if(a==x||x<=a+b){
      if(x>=a)
        cout << "YES\n";
      else
        cout << "NO\n";
    }
    else
      cout << "NO\n";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
typedef vector<vector<P>> vvP;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

int main() {
    ll n;
    cin >> n;

    vector<P> red(n);
    rep(i, n) {
        ll a, b;
        cin >> a >> b;
        red[i] = make_pair(b, a);
    }
    sort(rall(red));

    vector<P> blue(n);
    rep(i, n) {
        ll a, b;
        cin >> a >> b;
        blue[i] = make_pair(a, b);
    }
    sort(all(blue));

    ll ans = 0;
    vl used(n);  // used[j] : j番目の赤い点を使用したら1
    rep(i, n) {
        rep(j, n) {
            if(used[j]) {
                continue;
            }
            if(blue[i].first > red[j].second && blue[i].second > red[j].first) {
                ans++;
                used[j] = 1;
                break;
            }
        }
    }

    out(ans);
    re0;
}

Measured memory_bytes: 256
n, k = map(int, input().split())
a = list(map(int, input().split()))
t = 0
l = 0
for i in range(n):
    for j in range(n):
        if a[i] > a[j]:
            l += 1
        if j > i and a[i] > a[j]:
            t += 1

mod = 10**9 + 7
ans = (t * k) % mod + (l * k * (k - 1)) // 2 % mod 
print(ans % mod)

Measured memory_bytes: 3188
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <utility>

using namespace std;
typedef pair<int, int> pii;

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

void mark(const vector<string> &p, int x, int y, vector<string> &chk, char c){
	int w = p[0].size(), h = p.size();
	chk[y][x] = '1';
	for(int i = 0; i < 4; ++i){
		int nx = x + dx[i], ny = y + dy[i];
		if(nx < 0 || nx >= w || ny < 0 || ny >= h){ continue; }
		if(chk[ny][nx] == '1'){ continue; }
		if(p[ny][nx] == c){
			mark(p, nx, ny, chk, c);
		}else if(ny < y && p[ny][nx] != '.'){
			mark(p, nx, ny, chk, p[ny][nx]);
		}
	}
}
pii grand(
	const vector<string> &p, const vector<string> &gnd, int x, int y,
	vector<string> &checked, char c)
{
	int w = p[0].size(), h = p.size();
	checked[y][x] = '1';
	pii answer(10000, 0);
	if(gnd[y + 1][x] == '1'){ answer = pii(x, x + 1); }
	for(int i = 0; i < 4; ++i){
		int nx = x + dx[i], ny = y + dy[i];
		if(nx < 0 || nx >= w || ny < 0 || ny >= h){ continue; }
		if(checked[ny][nx] == '1'){ continue; }
		if(p[ny][nx] == c){
			pii g = grand(p, gnd, nx, ny, checked, c);
			answer.first = min(answer.first, g.first);
			answer.second = max(answer.second, g.second);
		}
	}
	return answer;
}
void modify(
	const vector<string> &p, int x, int y, vector<string> &gnd,
	char c, queue<pii> &next)
{
	int w = p[0].size(), h = p.size();
	gnd[y][x] = '1';
	for(int i = 0; i < 4; ++i){
		int nx = x + dx[i], ny = y + dy[i];
		if(nx < 0 || nx >= w || ny < 0 || ny >= h){ continue; }
		if(gnd[ny][nx] == '1'){ continue; }
		if(p[ny][nx] == c){ modify(p, nx, ny, gnd, c, next); }
	}
	if(y > 0 && p[y - 1][x] != '.'){ next.push(pii(x, y - 1)); }
}

int main(){
	while(true){
		int w, h;
		cin >> w >> h;
		if(w == 0 && h == 0){ break; }
		vector<string> p(h);
		for(int i = 0; i < h; ++i){ cin >> p[i]; }
		p.push_back(string(w, '-'));
		vector<string> gnd(h, string(w, '0'));
		gnd.push_back(string(w, '1'));
		queue<pii> next;
		for(int i = 0; i < w; ++i){
			if(p[h - 1][i] != '.'){ next.push(pii(i, h - 1)); }
		}
		while(!next.empty()){
			int x = next.front().first, y = next.front().second;
			next.pop();
			if(gnd[y][x] == '1'){ continue; }
			vector<string> c1(h + 1, string(w, '0'));
			mark(p, x, y, c1, p[y][x]);
			vector<string> c2(h + 1, string(w, '0'));
			pii g = grand(p, gnd, x, y, c2, p[y][x]);
			double core = 0.0;
			int count = 0;
			for(int i = 0; i < h; ++i){
				for(int j = 0; j < w; ++j){
					if(c1[i][j] == '1'){
						core += j + 0.5;
						++count;
					}
				}
			}
			core /= count;
			if(core <= g.first || core >= g.second){ break; }
			modify(p, x, y, gnd, p[y][x], next);
		}
		bool ok = true;
		for(int i = 0; i < h; ++i){
			for(int j = 0; j < w; ++j){
				if(p[i][j] != '.' && gnd[i][j] == '0'){ ok = false; }
			}
		}
		cout << (ok ? "STABLE" : "UNSTABLE") << endl;
	}
	return 0;
}

Measured memory_bytes: 0
A, B, C = map(int, input().split())
K = int(input())

count=0

for i in range (0, 100):
    if B <= A:
        B = B*2
        count+= 1
    if C <= B:
        C = C*2
        count+=1

if count <= K:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 9188
using System;
class aoj
{
    static void Main()
    {
        int z;
        int g = 0, h = 0 ;
        for( z = 0; z < 100; z++)
        {
            int []a = new int[2];
            string b = Console.ReadLine();
            if (String.IsNullOrEmpty(b)) break;
            string[] c = b.Split(',');
            a[0] = int.Parse(c[0]);
            a[1] = int.Parse(c[1]);
            g += a[ 0] * a[ 1];
            h += a[1];
        }
        decimal k = (decimal)h;
        decimal l = (decimal)z;
        decimal m = Math.Ceiling(k / l);
        Console.WriteLine(g + "\n" + m);
    }
}

Measured memory_bytes: 8924
#include <stdio.h>

int number_num;
int numbers[100];
int search_for;

int main(void) {
	int i;
	int left,right,mid;
	int count;
	while(1) {
		scanf("%d",&number_num);
		if(number_num==0)break;
		for(i=0;i<number_num;i++)scanf("%d",&numbers[i]);
		scanf("%d",&search_for);
		count=0;
		left=0;right=number_num-1;
		while(left<=right) {
			count++;
			mid=(left+right)/2;
			if(numbers[mid]==search_for)break;
			else if(numbers[mid]<search_for)left=mid+1;
			else right=mid-1;
		}
		printf("%d\n",count);
	}
	return 0;
}

Measured memory_bytes: 0
#include<iostream>
using namespace std;
int main(){
  int h,w;
  cin >> h >> w;
  while(h!=0){
    int i,j;
    for(i=0;i<h;i++){
      for(j=0;j<w;j++){
    cout << "#";
      }
      cout << endl;
    }
    cout << endl;
    cin >> h >> w;
  }
  return 0;
}


Measured memory_bytes: 3096
#!/usr/bin/env python3
import sys


def solve(N: int, M: int, A: "List[int]", B: "List[int]", C: "List[int]"):
    a = sorted(A,reverse=True)
    b = sorted([(C[i],B[i]) for i in range(M)],reverse=True)
    sum = 0
    aIndex = 0
    bIndex = 0
    for i in range(N):
        if len(a) == aIndex:
            sum += b[bIndex][0]
            b[bIndex] = (b[bIndex][0],b[bIndex][1]-1)
            if b[bIndex][1] == 0:
                bIndex += 1
            continue
        if len(b) == bIndex:
            sum += a[aIndex]
            aIndex += 1
            continue
        if a[aIndex] > b[bIndex][0]:
            sum += a[aIndex]
            aIndex += 1
        else:
            sum += b[bIndex][0]
            b[bIndex] = (b[bIndex][0],b[bIndex][1]-1)
            if b[bIndex][1] == 0:
                bIndex += 1
    print(sum)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    B = [int()] * (M)  # type: "List[int]"
    C = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        B[i] = int(next(tokens))
        C[i] = int(next(tokens))
    solve(N, M, A, B, C)

if __name__ == '__main__':
    main()


Measured memory_bytes: 24388