akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>

using namespace std;

long long int r[200000];

int main(){
	
	long long int X, K, Q;
	cin >> X >> K;
	
	r[0] = 0;
	
	for(int i = 1; i <= K; i++){
		cin >> r[i];
	}
	
	r[K + 1] = 1000000000000LL;
	
	cin >> Q;
	
	int cur = 1;
	long long int cur_v = 0;
	long long int max_v = 0;
	long long int min_v = 0;
	long long int big_v = X;
	long long int sma_v = 0;
	
	for(int i = 0; i < Q; i++){
		long long int t, a;
		cin >> t >> a;
		while(true){
			if(r[cur] > t){
				break;
			}
			if(cur % 2 == 1){
				cur_v -= r[cur] - r[cur - 1];
				min_v = min(min_v, cur_v);
				sma_v = max(0LL, sma_v - (r[cur] - r[cur - 1]));
				big_v = max(0LL, big_v - (r[cur] - r[cur - 1]));
			}else{
				cur_v += r[cur] - r[cur - 1];
				max_v = max(max_v, cur_v);
				sma_v = min(X, sma_v + (r[cur] - r[cur - 1]));
				big_v = min(X, big_v + (r[cur] - r[cur - 1]));
			}
			//cout << max_v << " " << min_v << " " << big_v << " " << sma_v << endl;
			cur++;
		}
		long long int diff = t - r[cur - 1];
		if(a <= -min_v){
			if(cur % 2 == 1){
				cout << max(0LL, sma_v - diff) << endl;
			}else{
				cout << min(X, sma_v + diff) << endl;
			}
		}else if(a <= X - max_v && max_v - min_v < X){
			if(cur % 2 == 1){
				cout << max(0LL, sma_v + (a + min_v) - diff) << endl;
			}else{
				cout << min(X, sma_v + (a + min_v)  + diff) << endl;
			}
		}else{
			if(cur % 2 == 1){
				cout << max(0LL, big_v - diff) << endl;
			}else{
				cout << min(X, big_v + diff) << endl;
			}
		}
	}
	
	return 0;
}



Measured memory_bytes: 2048
import sys


def partition(A, p, r):
    x = A[r]

    i = p - 1

    for j in range(p, r):
        if A[j] <= x:
            i += 1
            A[i], A[j] = A[j], A[i]

    A[i + 1], A[r] = A[r], A[i + 1]

    return i + 1


def main():
    N = int(sys.stdin.readline().rstrip())
    A = [int(x) for x in sys.stdin.readline().split()]

    q = partition(A, 0, N - 1)
    new_A = list(str(x) for x in A)
    new_A[q] = "[" + new_A[q] + "]"
    print(" ".join(new_A))


main()



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

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

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()


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

  int H,W;
  cin>>H>>W;
  string snuke="snuke";
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      string S;
      cin>>S;
      if(S==snuke){
        cout<<(char)('A'+j)<<i+1<<endl;
      }
    }
  }
  return 0;
}


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

using namespace std;

long long value[100001];
long long weight[100001];
long long k[101][100001];

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

	long long n, W;
	cin >> n >> W;

	for(long long i = 1; i <= n; i++){
		cin >> weight[i] >> value[i];
	}

	for(long long i = 0; i <= n; i++){
		for(long long j = 0; j <= W; j++){
			if(!i || !j) k[i][j] = 0;
			else if(weight[i] <= j) k[i][j] = max(k[i-1][j], value[i]+k[i-1][j-weight[i]]);
			else k[i][j] = k[i-1][j];
		}
	}

	cout << k[n][W];

	return 0;
}

Measured memory_bytes: 80128
#include<bits/stdc++.h>
#define f first
#define s second
#define mp make_pair
#define inf 100000000
#define eps (1e-11)
#define equals(a,b) (fabs((a)-(b))<eps)
using namespace std;

class Point{
public:
  double x,y;
  Point(double x=0,double y=0):x(x),y(y){}

  Point operator+(Point p){ return Point(x+p.x,y+p.y);}
  Point operator-(Point p){ return Point(x-p.x,y-p.y);}
  Point operator*(double k){ return Point(x*k,y*k);}
  Point operator/(double k){ return Point(x/k,y/k);}
  bool operator<(Point p)const{ return (x!=p.x ? x<p.x : y<p.y);}
  bool operator==(Point p)const{ return fabs(x-p.x)<eps && fabs(y-p.y)<eps;}

  double abs(){ return sqrt(norm());}
  double norm(){ return (x*x+y*y);}
};
typedef Point Vector;
typedef vector<Point> Polygon;

class Segment{
public:
  Point p1,p2;
  Segment(Point p1,Point p2):p1(p1),p2(p2){}
};
double norm(Vector a){ return (a.x*a.x+a.y*a.y);}
double abs(Vector a){ return sqrt(norm(a));}
double dot(Vector a,Vector b){ return (a.x*b.x+a.y*b.y);}
double cross(Vector a,Vector b){ return (a.x*b.y-a.y*b.x);}

static const int COUNTER_CLOCKWISE=1;
static const int CLOCKWISE=-1;
static const int ONLINE_BACK=2;
static const int ONLINE_FRONT=-2;
static const int ON_SEGMENT=0;

int ccw(Point p0,Point p1,Point p2){
  Vector a=p1-p0;
  Vector b=p2-p0;
  if(cross(a,b)>eps)return COUNTER_CLOCKWISE;
  if(cross(a,b)<-eps)return CLOCKWISE;
  if(dot(a,b)<-eps)return ONLINE_BACK;
  if(a.norm()<b.norm())return ONLINE_FRONT;
  return ON_SEGMENT;
}

bool intersect(Point p1,Point p2,Point p3,Point p4){
  return (ccw(p1,p2,p3)*ccw(p1,p2,p4)<=0 &&
          ccw(p3,p4,p1)*ccw(p3,p4,p2)<=0);
}

bool intersect(Segment s1,Segment s2){
  return intersect(s1.p1,s1.p2,s2.p1,s2.p2);
}

int main()
{
  int n;
  int a,b,c,d,e,f,sx,sy,gx,gy;
  Point p[3];

  cin>>n;
  for(int i=0;i<n;i++){
    cin>>p[0].x>>p[0].y>>p[1].x>>p[1].y>>p[2].x>>p[2].y;
    cin>>sx>>sy>>gx>>gy;
    Segment s(Point(sx,sy),Point(gx,gy));
    int c=0;
    for(int i=0;i<3;i++){
      if(intersect(s,Segment(p[i],p[(i+1)%3])))c++;
    }
    if(c==1)cout<<"OK"<<endl;
    else cout<<"NG"<<endl;
  }
  return 0;
}

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

int main()
{
    int N;
    int a[100002] = {0};

    cin >> N;
    for (int i = 0; i < N; i++)
    {
        int x;
        cin >> x;
        if (x == 0)
        {
            a[0]++;
            a[1]++;
        }
        else
        {
            a[x - 1]++;
            a[x]++;
            a[x + 1]++;
        }
    }

    int ans = 0;
    for (int i = 0; i <= sizeof(a)/sizeof(a[0]); i++)
    {
        if (a[i] > ans)
        {
            ans = a[i];
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 640
N, X = map(int, input().split())
L_i = list(map(int, input().split()))

Bounds = [0]

for i in range(N):
    Bounds.append(Bounds[i] + L_i[i])

count = 0

for i in Bounds:
    if i <= X:
        count += 1

print(count)


Measured memory_bytes: 3060
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <iterator>
#include <numeric>
#include <vector>

int main(void)
{
    int n;
    std::cin >> n;
    std::vector<int> w(n);
    for (int i = 0; i < n; i++)
    {
        std::cin >> w[i];
    }
    std::vector<int> x(n);
    for (int i = 0; i < n; i++)
    {
        auto wi = w.begin();
        std::advance(wi, i);
        x[i] = std::abs(std::accumulate(w.begin(), wi, 0) - std::accumulate(wi, w.end(), 0));
    }
    auto min = std::min_element(x.begin(), x.end());
    std::cout << *min << std::endl;
    return 0;
}

Measured memory_bytes: 256
import collections
import math
def main():
    N = int(input())

    def isPrime(i):
        for j in range(2, int(math.sqrt(i))+1):
            if i % j == 0:
                return False
        return True

    primes = []
    for i in range(2, N+1):
        if isPrime(i):
            primes.append(i)

    d = collections.defaultdict(int)
    for i in range(2, N+1):
        for p in primes:
            while i > 0 and i % p == 0:
                d[p] += 1
                i = i // p
            if i <= 1: break
    p74 = []
    p24 = []
    p14 = []
    p4 = []
    p2 = []

    # 75= 3*5*5, [74], [24, 2], [14, 4], [4, 4, 2]
    for p in d:
        if d[p] >= 74: p74.append(p)
        if d[p] >= 24: p24.append(p)
        if d[p] >= 14: p14.append(p)
        if d[p] >= 4: p4.append(p)
        if d[p] >= 2: p2.append(p)

    # print(p4)
    # print(p2)
    count = 0
    count += len(p74)
    for p in p24:
        if p in p2: count += len(p2)-1
        else: count += len(p2)
    for p in p14:
        if p in p4: count += len(p4)-1
        else: count += len(p4)
    for p in p2:
        # print(count, p)
        if p in p4: count += (len(p4)-1)*(len(p4)-2) // 2
        else: count += (len(p4))*(len(p4)-1) // 2
        # print(count)
    return count

if __name__ == '__main__':
    print(main())

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

#define MAX_N 100010

struct point {int id, coor;};
point p[4][2 * MAX_N];

int r, c, n;
stack <int> s;

int boundary(int x, int y)
{
    if (x == 0) return 0;
    else if (y == c) return 1;
    else if (x == r) return 2;
    else if (y == 0) return 3;
    else return -1;
}

bool cmp_inc(point a, point b)
{
    return a.coor < b.coor;
}

bool cmp_dec(point a, point b)
{
    return a.coor > b.coor;
}

int main(void)
{
    scanf("%d%d%d", &r, &c, &n);
    int cnt[4] = {0};
    for (int i = 1; i <= n; i++) {
        int x[2], y[2];
        scanf("%d%d%d%d", &x[0], &y[0], &x[1], &y[1]);
        if ((x[0] % r == 0 || y[0] % c == 0) && (x[1] % r == 0 || y[1] % c == 0)) {
            for (int j = 0; j <2; j++) {
                int t = boundary(x[j], y[j]);
                p[t][cnt[t]].id = i;
                p[t][cnt[t]].coor = t % 2? x[j]: y[j];
                cnt[t]++;
            }
        }
    }
    for (int i = 0; i < 4; i++) {
        if (i < 2) sort(p[i], p[i] + cnt[i], cmp_inc);
        else sort(p[i], p[i] + cnt[i], cmp_dec);
        for (int j = 0; j < cnt[i]; j++) {
            if (s.size() && s.top() == p[i][j].id)
                s.pop();
            else
                s.push(p[i][j].id);
        }
    }
    if (s.empty()) printf("YES\n");
    else printf("NO\n");
    return 0;
}


Measured memory_bytes: 5632
<?php
for($i=0;$i<4;$i++){
$n[] = trim(fgets(STDIN));
}
if ($n[0]>=$n[1]){
  $price = $n[1];
  }else{
  $price = $n[0];
}
if ($n[2]>=$n[3]){
  $price += $n[3];
  }else{
  $price += $n[2];
}
echo $price;

Measured memory_bytes: 3700
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int n, a, b, c, d;
  cin >> n >> a >> b >> c >> d;
  a--; b--; c--; d--;
  string s;
  cin >> s;
  rep2(i, a, max(c, d)){
    if(s.at(i) == '#' && s.at(i+1) == '#'){
      cout << "No" << endl;
      return 0;
    }
  }
  if(c < d){
    cout << "Yes" << endl;
    return 0;
  }

  rep2(i, b, d+1){
    if(s.at(i-1) == '.' && s.at(i) == '.' && s.at(i+1) == '.'){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3752
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    int R,G,B,N;
    cin >> R >> G >> B >> N;
    int ans = 0;
    for(int i=0;i<=N;i++) {
        for(int j=0;j<=N;j++) {
            int a = N - R*i - G*j;
            if(a%B == 0 && a >= 0) ans++; 
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
from collections import  deque

n, m = map(int, input().split())
g = [[] for _ in range(n)]
for _ in range(m):
    u, v = map(lambda x : int(x) - 1, input().split())
    g[u].append(v)
s, t = map(lambda x : int(x) - 1, input().split())
d = [[-1, -1, -1] for _ in range(n)]

m = 0
p = 0
d[s][0] = 0

queue = deque([(s, 0)])
while queue:
    i, p0 = queue.popleft()
    p1 = (p0 + 1) % 3
    for j in g[i]:
        if d[j][p1] >= 0:
            continue
        d[j][p1] = d[i][p0] + 1
        if j == t and p1 == 0:
            print(d[j][p1] // 3)
            quit()
        queue.append((j, p1))
print(-1) 

Measured memory_bytes: 102576
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>

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

using namespace std;

int main() {

	int a;
	cin >>a;
	cout << a+a*a+a*a*a;
	return 0;
}

Measured memory_bytes: 3564
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using st=string;
using ch=char;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<ch> vc;
typedef vector<vc> vvc;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
#define ROF(i,a,b) for(ll i=a;i>=b;i--)
#define per(i,a) ROF(i,a,0)
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld PI=acos(-1);
const ll INF=1e18;
st abc="abcdefghijklmnopqrstuvwxyz";
st ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
struct edge{ll to,cost;};

int main() {
  ll H,W;
  ll ans=INF;
  cin >> H >> W;
  if(H*W%3==0){
    cout << 0 << endl;
  }
  else{
    ll w=W/3,h=H/3;
    ans=min(H,W);
    ans=min(ans,(W-w)*((H+1)/2)-min(w*H,(W-w)*(H/2)));
    w++;
    ans=min(ans,max(w*H,(W-w)*((H+1)/2))-(W-w)*(H/2));
    ans=min(ans,(H-h)*((W+1)/2)-min(h*W,(H-h)*(W/2)));
    h++;
    ans=min(ans,max(W*h,(H-h)*((W+1)/2))-(H-h)*(W/2));
    cout << ans << endl;
  }
}

Measured memory_bytes: 256
#include <stdio.h>
 #include <string.h>
  int main(void){
      char s[100]={};
      char p[100]={};
      char s1[100]={};
 
      int len,i,j,a,cmp;
 
      scanf("%s",s);
      scanf("%s",p);

      len=strlen(p);
 
      for(i=0;i<100;i++){
          if(s[i]==p[0]){
              a=i;
              for(j=0;j<len;j++){
                  if(s[a]==0)
                      a=0;
                  s1[j]=s[a];
                  a++;
              }
              cmp=strcmp(p,s1);
              if(cmp==0){
                  puts("Yes");
                  break;
              }
          }
      }
 
      if(cmp!=0)
          puts("No");
 
      return 0;
}


Measured memory_bytes: 2108
s = gets.chomp
a = s.split('').map(&:to_i)
p = Array.new(a.length - 1){ |i| i + 1 }

tmp = [a.map(&:to_i)]
(1..(a.length - 1)).each do |i|
  p.combination(i).to_a.map { |i| i.reverse }.each do |i|
    k = a.dup
    i.each do |pi|
      k.insert(pi, '+').join
    end
    tmp << k
  end
end

sum = 0
tmp.map(&:join).map{ |i| "#{i}" }.each do |i|
  sum += (eval i).to_i
end
puts sum


Measured memory_bytes: 2684
#include<bits/stdc++.h>
using namespace std;
#define arep(i,x,n) for(int i=int(x);i<(int)(n);i++)
#define rep(i,n) for(long long i = 0;i < n;++i)
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9+7  
using ll = long long; 
using P=pair<int,int>;
using lP=pair<ll,ll>;
using fP=pair<double,double>;


int main(){
    int n;
    cin>>n;
    multiset<ll>ans;
    vector<int>a(n);
    rep(i,n)cin>>a[i];
    ll c=1;
    for(int i=n-1;i>=0;--i){
        if(i==n-1){
            ans.insert(a[i]);
            i--;
        }
        auto it=ans.upper_bound(a[i]);
        if(it!=ans.end())ans.erase(it);
        else c++;
        ans.insert(a[i]);
    }
    cout<<c<<endl;

    return 0;
}

Measured memory_bytes: 5376
s = input()
n = len(s) - 1

ans = 0
for i in range(2**n):
    op = ['-'] * n + ['-']
    for j in range(n):
        if (i >> j & 1):
            op[j] = '+'
    formula = ''
    for j in range(n+1):
        if op[j] == '+':
            formula += s[j] + '+'
        else:
            formula += s[j]
    ans += eval(formula)

print(ans)


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




int main() {
	
    
   long int K,n;
    cin>>K>>n;
  
   long int A[n],i,j,B[n];
  for(i=0;i<n;++i)
  {
    cin>>A[i];
    
  }
  
  for(i=0;i<n;++i)
  {
    if(i==0)
    {
    B[i]=(K-A[n-1])+(A[i]);
    }
    else
    {
      B[i]=A[i]-A[i-1];
    }
  }
  
  sort(B,B+n);
  long int tot=0;
  for(i=0;i<(n-1);++i)
  {
    tot+=B[i];
  }
    
  cout<<tot<<endl;
    
	return 0;
}


Measured memory_bytes: 3328
/**
 *    author:  FromDihPout
 *    created: 2020-08-01
**/

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


const int N = 1e5 + 10;
int n, f1, f2;
vector<vector<int>> adj;
bool seen[N];

int first(int u, int dist) {
    seen[u] = true;
    if (u == n - 1) {
        if (dist <= 2) f1 = u;
        return dist;
    }
    for (int v : adj[u]) {
        if (seen[v]) continue;
        int d = first(v, dist + 1);
        if (d > 0) {
            if (dist == d / 2 + 1) f1 = u;
            else if (dist == d / 2) f2 = u;
            return d;
        }
    }
    return -1;
}

int dfs(int u) {
    seen[u] = true;
    int cnt = 1;
    for (int v : adj[u]) {
        if (seen[v]) continue;
        cnt += dfs(v);
    }
    return cnt;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    cin >> n;
    adj.resize(n);
    for (int i = 0; i < n-1; i++) {
        int u, v;
        cin >> u >> v;
        u--; v--;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    
    memset(seen, false, n);
    first(0, 0);
    
    int cnt1 = 0;
    memset(seen, false, n);
    seen[f1] = true;
    cnt1 += dfs(0) - 1;
    
    int cnt2 = 0;
    memset(seen, false, n);
    seen[f2] = true;
    cnt2 += dfs(n-1) - 1;
    
    if (cnt1 > cnt2) {
        cout << "Fennec" << '\n';
    }
    else {
        cout << "Snuke" << '\n';
    }
    return 0;
}


Measured memory_bytes: 15036
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define RFOR(i, begin, end) for(int i=(end)-1, i##_begin_=(begin);i>=i##_begin_;i--)
#define rep(i, N) FOR(i, 0, N)
#define rrep(i, N) RFOR(i, 0, N)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
using namespace std;
using ll = long long int;
using V = vector<ll>;
using P = pair<ll, ll>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
constexpr int mod = 1e9+7;
ll gcd(ll a, ll b) { return b? gcd(b, a%b) : a;}
ll lcm(ll a, ll b) { return a/gcd(a, b)*b;}

ll n, q;
string s;

int main() {
    cin >> n >> q >> s;
    V l(q), r(q);
    rep(i, q) cin >> l[i] >> r[i];

    V cnt(n+1, 0);
    FOR(i, 1, n) {
        cnt[i+1] = cnt[i];
        if(s[i-1] == 'A' && s[i] == 'C') cnt[i+1]++;
    }

    //0 1 2 3 4 5 6
    // A C A C A C
    // 
    rep(i, q) {
        ll ret = cnt[r[i]] - cnt[l[i]];
        cout << ret << endl;
    }

    return 0;
}


Measured memory_bytes: 3408
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

ll N,A;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>A;
	
	ll mi=N;
	// once;
	ll X;
	for(X=1;X*(X-1)<=N;X++) mi=min(mi,X+A+(N+(X-1))/X);
	// morethan 1
	for(X=2;X*(X-1)*(X-2)<=N;X++) {
		FOR(x,40) {
			ll pace=1;
			ll tot=0;
			ll t=X;
			FOR(y,40) {
				if(y<x) {
					pace=pace*X;
					tot+=X+A;
				}
				else {
					pace=pace*(X-1);
					tot+=(X-1)+A;
				}
				mi=min(mi,tot+(N+(pace-1))/pace);
				if(pace>N) break;
			}
		}
		
	}
	
	cout<<mi<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}


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

int main(void)
{
  int n;
  cin >> n;
  vector<int> data(n);
  rep(i,n) cin >> data[i];
  int minv = data[0];
  int res = -2000000000;
  for(int i = 1; i < n; i++)
  {
    res = max(res, data[i] - minv);
    minv = min(minv, data[i]);
  }
  cout << res << endl;
  return (0);
} 


Measured memory_bytes: 3588
#include <ios>
#include <iomanip>
#include <iostream>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>

using namespace std;
typedef long long int ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1e9)
#define PI (acos(-1))
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl

ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
typedef pair <ll,ll> P;

int main()
{
    ll N;
    cin >> N;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];
    ll count = 0;
    bool flag = false;
    while(true) {
        rep(i, N) {
            if (A[i] % 2 == 1) {
                flag = true;
                break;
            } else {
                A[i] /= 2;
            }
        }
        if (flag) {
            print(count);
            return 0;
        } else {
            count++;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multi_array.hpp>
#define rep(i,n) for (int i=0; i< (n); ++i)
using namespace std;
typedef long long ll;

int main() {
  string n, ans;
  cin >> n;
  if (n=="Sunny") ans = "Cloudy";
  if (n=="Cloudy") ans = "Rainy";
  if (n=="Rainy") ans = "Sunny";

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


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

var (
	n, k int
	h    Ints
	ans  int
)

type Ints []int

func (s Ints) Len() int {
	return len(s)
}

func (s Ints) Less(i, j int) bool {
	return s[i] > s[j]
}

func (s Ints) Swap(i, j int) {
	s[i], s[j] = s[j], s[i]
}

func main() {
	n = nextInt()
	k = nextInt()
	h = make([]int, n)
	for i := 0; i < n; i++ {
		h[i] = nextInt()
	}
	sort.Sort(h)
	for i := k; i < n; i++ {
		ans += h[i]
	}
	fmt.Println(ans)
}

var scanner *bufio.Scanner

func init() {
	scanner = bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
}
func nextInt() int {
	if !scanner.Scan() {
		panic("No more token.")
	}
	num, err := strconv.Atoi(scanner.Text())
	if err != nil {
		panic("nextInt(): cannot convert to int: " + scanner.Text())
	}
	return num
}


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

using namespace std;


int main() {
    string s;
    cin >> s;
    if(s.size() > 9) {
        puts("NO");
        return 0;
    }
    for(int i = 0; i < s.size()- 1; i++) {
        if(s[i] == s[i+1]) {
            puts("NO");
            return 0;
        }
    }
    string x = "";
    for(int i = 0; i < s.size(); i++) {
        if(s[i] != 'A') {
            x += s[i];
        }
    }
    for(int i = 0; i < s.size(); i++) {
        if(s[i] == 'K') {
            if(s[i+1] != 'I') {
                puts("NO");
                return 0;
            }
        }
        if(s[i] == 'I') {
            if(s[i+1] != 'H') {
                puts("NO");
                return 0;
            }
        }
    }
    if(x == "KIHBR") {
        puts("YES");
    } else {
        puts("NO");
    }
    return 0;
}

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

long solve(long a, long b, long c, long k)
{
  if (k <= a) return k;
  if (a + b >= k) return a;
  return a * 2 + b - k;
}

int main()
{
  long a, b, c, k;
  std::cin >> a >> b >> c >> k;

  std::cout << std::setprecision(20);
  std::cout << solve(a, b, c, k) << std::endl;
}


Measured memory_bytes: 3580
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
input:
2 1 1
2
0 1 4 1
3 0 3 3

output:
1.00000000 1.00000000 3.00000000 1.00000000
3.00000000 1.00000000 3.00000000 1.00000000
"""

import math
import sys
from operator import attrgetter
from collections import namedtuple


def dot(a, b):
    return a.real * b.real + a.imag * b.imag


def project(s, p):
    base_vector = s.target - s.source
    prj_ratio = dot(p - s.source, base_vector) / pow(abs(base_vector), 2)
    return s.source + base_vector * prj_ratio


def get_cross_point(c, l):
    prj_vector = project(l, c.centre)
    line_unit_vector = (l.target - l.source) / (abs(l.target - l.source))
    base = math.sqrt(pow(c.radius, 2) - pow(abs(prj_vector - c.centre), 2))
    ans = [prj_vector + line_unit_vector * base, prj_vector - line_unit_vector * base]

    ans.sort(key=attrgetter('real', 'imag'))
    return ans


def solve(_lines):
    for line in _lines:
        line_axis = tuple(map(int, line))
        p0, p1 = (x + y * 1j for x, y in zip(line_axis[::2], line_axis[1::2]))
        l = Segment(source=p0, target=p1)
        cp1, cp2 = get_cross_point(circle, l)
        print('{0:.8f} {1:.8f} {2:.8f} {3:.8f}'.format(cp1.real, cp1.imag, cp2.real, cp2.imag))

    return None


if __name__ == '__main__':
    _input = sys.stdin.readlines()

    cx, cy, r = map(int, _input[0].split())
    q_num = int(_input[1])
    lines = map(lambda x: x.split(), _input[2:])

    Circle = namedtuple('Circle', ('centre', 'radius'))
    Segment = namedtuple('Segment', ('source', 'target'))

    circle = Circle(centre=cx + cy * 1j, radius=r)
    solve(lines)

Measured memory_bytes: 8232
import java.util.Scanner;
public class Main {
	static Scanner scan=new Scanner(System.in);
	static int gcd (int a, int b) {return b>0?gcd(b,a%b):a;}
	static long lcm (int a, int b) {return a*b/gcd(a,b);}
	static int max(int a,int b) {return a>b?a:b;}
	static int min(int a,int b) {return a<b?a:b;}
	static long factorial(int i) {return i==1?1:i*factorial(i-1);}
	static int lower_bound(int a[],int key) {
		int low=0,high=a.length;
		while(low<high) {
			int mid=((high-low)/2)+low;
			if(a[mid]<=key)low=mid+1;
			else high=mid;
		}
		return high;
		}
	static int upper_bound(int a[],int key) {
		int low=0,high=a.length;
		while(low<high) {
			int mid=((high-low)/2)+low;
			if(a[mid]<key)low=mid+1;
			else high=mid;
		}
		return high;
		}
	static boolean isPrime (int n) {
		if (n==2) return true;
		if (n<2 || n%2==0) return false;
		double d = Math.sqrt(n);
		for (int i=3; i<=d; i+=2)if(n%i==0){return false;}
		return true;
	}
		public static void main(String[] args) {
			int a=scan.nextInt();
			int cnt=0;
			for(int i=0;i<a;i++) {
				int b=scan.nextInt();
				if(b!=i+1) {
					cnt++;
				}
			}
			if(cnt==2||cnt==0) {
				System.out.println("YES");
			}
			else {
				System.out.println("NO");
			}
			
		}
}


Measured memory_bytes: 22356
/*
 * c.cc: 
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

/* typedef */

/* global variables */

/* subroutines */

/* main */

int main() {
  for (;;) {
    int a, b;
    char op;
    cin >> a >> op >> b;
    if (op == '?') break;

    int ans;
    switch (op) {
    case '+': ans = a + b; break;
    case '-': ans = a - b; break;
    case '*': ans = a * b; break;
    case '/': ans = a / b; break;
    }
    printf("%d\n", ans);
  }

  return 0;
}

Measured memory_bytes: 1148
import sys
N = input()
x = list(map(int,input().split()))
 
z = 1
if 0 in x:
  print(0)
  sys.exit()
  
for a in x:
  z = a*z
  if z > 10**18:
    print(-1)
    sys.exit()
  
print(z)

Measured memory_bytes: 21768
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

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

    bool dp1[N][10];
    bool dp2[N][10];
    fill(dp1[0], dp1[N], false);
    fill(dp2[0], dp2[N], false);

    for(int i = 1; i < N; i++){
        for(int j = 0; j < 10; j++){
            dp1[i][j] = dp1[i - 1][j];
        }

        int num = (int)(s[i - 1] - '0');
        dp1[i][num] = true;
    }

    for(int i = N - 2; i >= 0; i--){
        for(int j = 0; j < 10; j++){
            dp2[i][j] = dp2[i + 1][j];
        }

        int num = (int)(s[i + 1] - '0');
        dp2[i][num] = true;
    }

    /*
    for(int i = 0; i < N; i++){
        for(int j = 0; j < 10; j++){
            cout << dp1[i][j] << " ";
        }
        cout << endl;
    }*/

    bool exist[1000];
    fill(exist, exist + 1000, false);
    for(int i = 0; i < N; i++){
        for(int j = 0; j < 10; j++){
            for(int k = 0; k < 10; k++){
                if(dp1[i][j] && dp2[i][k]){
                    int num = 100 * j + 10 * (int)(s[i] - '0') + k;
                    exist[num] = true;
                }
            }
        }
    }

    int ans = 0;
    for(int i = 0; i < 1000; i++){
        if(exist[i]) ans++;
    }

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

Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;

int main() {
    string s;
    cin >> s;
    int l=s.length();
    bool ok=true;
    for(int i=0;i<l;++i) {
        if(i%2==0) {
            if(s[i]=='L') ok=false;
        }
        else {
            if(s[i]=='R') ok=false;
        }
    }
    if(ok) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    
}



Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) {

		//?????£?????????
		String line;

		int numN = 0;
		int numMin = 0;
		int numMax = 0;
		long numAdd = 0;

		String[] NumWork;
		int[]   NumList;
		try {
			//??\????????????
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			line = br.readLine();

			//???????????£?¨?
			numN    = Integer.parseInt(line);
			NumList = new int[numN];

			//System.out.println(numN);
			while (true) {
				//?????????????????????
				line = br.readLine();
				if(line != null){

					//??°??£?????´??°?????????
					NumWork = line.split(" ", 0);

					//??´??°?????°??????
					for (int i = 0; i < NumWork.length; i++) {
						NumList[i] = Integer.parseInt(NumWork[i]);
					}
					//System.out.println(NumList[0] + "+" +  NumList[1]);

					numMin = NumList[0];
					numMax = NumList[0];
					//??´??°?????????
					for (int i = 1; i < NumList.length; i++) {

							numMin = Math.min(NumList[i], numMin);
							numMax = Math.max(NumList[i], numMax);
					}
					//??´??°???????¨?
					for (int i = 0; i < NumList.length; i++) {
						numAdd = numAdd + NumList[i];
					}
					//???????????????
					System.out.println(numMin + " " + numMax + " " + numAdd);
				}else{
					break;
				}
			}
		}catch (NumberFormatException e) {
			System.out.println(e);
		} catch (IOException e) {
			System.out.println(e);
		}
	}

}

Measured memory_bytes: 28572
import java.util.*;

class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		int N = Integer.parseInt(sc.next());
		int R = Integer.parseInt(sc.next());
	
		if(N >= 10) {
			System.out.println(R);
		} else {
			System.out.println(R+(100*(10-N)));
		}
	}

}

Measured memory_bytes: 20820
#coding=UTF-8

mozir=input()
hyo=mozir.split(' ')
N=int(hyo[0])
T=int(hyo[1])

mozir=input()
hyo=mozir.split(' ')
t=[ int(mono) for mono in hyo]

X=0

hazimetime=None
owaritime=None
for hito in t:
    #時間清算
    if owaritime != None:
        if owaritime > hito:
            X=X+(hito-hazimetime)
        else:
            X=X+T
        
    #押す処理
    hazimetime=hito
    owaritime=hito+T


#最後の人の処理
X=X+T
print(X)


Measured memory_bytes: 27792
#include<cstdio>
using namespace std;

int n, m, s1[100], s2[100], sum1, sum2;

int main() {
  while (1) {
    scanf("%d%d", &n, &m);
    if (n == 0) break;
    sum1 = sum2 = 0;
    for (int i = 0; i < n; i++) scanf("%d", &s1[i]), sum1 += s1[i];
    for (int i = 0; i < m; i++) scanf("%d", &s2[i]), sum2 += s2[i];
    bool flag = false;
    int x, y;
    x = y = 10000;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        if (sum1 - s1[i] + s2[j] == sum2 - s2[j] + s1[i]) {
          flag = true;
          if (x + y > s1[i] + s2[j]) x = s1[i], y = s2[j];
        }
      }
    }
    if (flag) printf("%d %d\n", x, y);
    else printf("-1\n");
  }
}



Measured memory_bytes: 2700
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define _repargs(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template

vector<vector<int>> C;
int H, W, K;

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

void dfs(int h, int w){
    rep(i, 4){
        if(h + dy[i] >= 0 && h + dy[i] < H && w + dx[i] >= 0 && w + dx[i] < W){
            if(C[h + dy[i]][w + dx[i]] < 0){
                C[h + dy[i]][w + dx[i]] = C[h][w] + 1;
                dfs(h + dy[i], w + dx[i]);
            }
        }
    }
}


int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    
    cin >> H >> W >> K;
    vector<string> A(H);
    rep(i, H) cin >> A[i];
    
    pair<int, int> s;
    rep(i, H) rep(j, W){
        if(A[i][j] == 'S') s = mp(i, j);
    }
    C.resize(H);
    rep(i, H){
        vector<int> c(W);
        rep(j, W){
            if(A[i][j] == 'S' || A[i][j] == '.'){
                c[j] = -1;
            }
            else{
                c[j] = inf;
            }
        }
        C[i] = c;
    }
    C[s.first][s.second] = 0;
    queue<pair<int, int>> q;
    q.push(mp(s.first, s.second));
    while(!q.empty()){
        auto t = q.front();
        int h = t.first, w = t.second;
        q.pop();
        rep(i, 4){
            if(h + dy[i] >= 0 && h + dy[i] < H && w + dx[i] >= 0 && w + dx[i] < W){
                if(C[h + dy[i]][w + dx[i]] < 0){
                    q.push(mp(h + dy[i], w + dx[i]));
                    C[h + dy[i]][w + dx[i]] = C[h][w] + 1;
                }
            }
        }
    }
//    dfs(s.first, s.second);
    
//    bool ok = false;
//    rep(i, H){
//        if(C[i][0] <= K || C[i][W - 1] <= K) ok = true;
//    }
//    rep(i, W){
//        if(C[0][i] <= K || C[H - 1][i] <= K) ok = true;
//    }
//    if(ok) {
//        output(1);
//        return 0;
//    }
    
    int mi = inf;
    rep(i, H) rep(j, W){
        if(C[i][j] <= K && C[i][j] >= 0){
            mi = min(mi, i);
            mi = min(mi, H - 1 - i);
            mi = min(mi, j);
            mi = min(mi, W - 1 - j);
        }
    }
    output(1 + (mi + K - 1) / K);
    
    
    return 0;
}

Measured memory_bytes: 3456
#include<stdio.h>
int main(void){
  int n,i;
  scanf("%d",&n);
  double a[n],sum;
  for(i=0;i<n;i++){
    scanf("%lf",&a[i]);
    a[i]=1/a[i];
    sum+=a[i];
  }
  printf("%f",1/sum);
  return 0;
}

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

typedef vector<int> vi;
typedef vector<vi> vvi;

template<int um> class UF {
public:
	vector<int> par, rank;
	UF() { rank = vector<int>(um, 0); for (int i = 0; i<um; i++) par.push_back(i); }
	int operator[](int x) { return (par[x] == x) ? (x) : (par[x] = operator[](par[x])); }
	int operator()(int x, int y) {
		if ((x = operator[](x)) == (y = operator[](y))) return x;
		if (rank[x]>rank[y]) return par[x] = y;
		rank[x] += rank[x] == rank[y]; return par[y] = x;
	}
};

int main()
{
	while (1)
	{
		int N, C; cin >> N >> C;
		if (N == 0) return 0;

		vvi S(N, vi(N, -1));
		rep(y, 0, N) rep(x, 0, y + 1) cin >> S[y][x];

		/*rep(y, 0, N)
		{
			rep(x, 0, N) printf("%d\t", S[y][x]);
			cout << endl;
		}*/

		UF<1 << 10> uf;

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

		rep(y, 0, N) rep(x, 0, N) if(0 < S[y][x])
		{
			rep(i, 0, 6)
			{
				int xx = x + dx[i];
				int yy = y + dy[i];
				if (xx < 0 || N <= xx) continue;
				if (yy < 0 || N <= yy) continue;
				if (S[yy][xx] < 0) continue;
				
				if (S[y][x] == S[yy][xx]) uf(y*N+x, yy*N+xx);
			}
		}

		/*rep(y, 0, N)
		{
			rep(x, 0, N) printf("%d\t", uf[y*N+x]);
			cout << endl;
		}
		cout << endl;*/

		map<int, int> cnt;
		rep(y, 0, N) rep(x, 0, N) if (0 < S[y][x]) cnt[uf[y*N+x]]++;

		map<int, set<int> > zerocnt;
		rep(y, 0, N) rep(x, 0, N) if (0 < S[y][x])
		{
			rep(i, 0, 6)
			{
				int xx = x + dx[i];
				int yy = y + dy[i];
				if (xx < 0 || N <= xx) continue;
				if (yy < 0 || N <= yy) continue;
				if (S[yy][xx] < 0) continue;

				if (S[yy][xx] == 0) zerocnt[uf[y*N + x]].insert(yy*N+xx);
			}
		}

		/*for (auto p : cnt)
		{
			printf("%d %d\n", p.first, p.second);
		}*/

		int ans = -100000;
		rep(y, 0, N) rep(x, 0, N) if (S[y][x] == 0)
		{
			int point = 0;

			set<int> mine, other;
			bool zero = false;
			rep(i, 0, 6)
			{
				int xx = x + dx[i];
				int yy = y + dy[i];
				if (xx < 0 || N <= xx) continue;
				if (yy < 0 || N <= yy) continue;
				if (S[yy][xx] < 0) continue;
				if (S[yy][xx] == 0)
				{
					zero = true;
					continue;
				}

				//if (1 < zerocnt[uf[yy*N + xx]].size()) continue;

				if (S[yy][xx] == C)
					mine.insert(uf[yy*N + xx]);
				else
					other.insert(uf[yy*N + xx]);
			}

			if (!zero)
			{
				bool ok = true;
				for (int a : mine) if (1 < zerocnt[a].size()) ok = false;
				if (ok)
				{
					for (int a : mine) point -= cnt[a];
					point--;
				}
			}
			for (int a : other)
			{
				if(zerocnt[a].size() == 1) point += cnt[a];
			}

			ans = max(ans, point);
		}

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

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

using namespace std;

int a, b, c, d;
int main() {
    scanf("%d%d%d%d", &a, &b, &c, &d);
    if (((a + d - 1) / d) >= ((c + b - 1) / b)) printf("Yes\n");
    else printf("No\n");
    return 0;
}


Measured memory_bytes: 3660
import bisect
a=[-int(input()) for _ in [0]*int(input())]
dp=[]
for x in a:
    i = bisect.bisect(dp,x)
    if i == len(dp):
        dp.append(x)    
    else:            
        dp[i] = min(dp[i],x)
print(len(dp))

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

int main(){
  int64_t N, W;
  cin >> N >> W;
  int64_t vec[N][2];
  for(int i=0; i<N; i++){
    for(int j=0; j<2; j++){
      cin >> vec[i][j];
    }
  }
  
  const int64_t W_MAX = 3*N+1;
  const int64_t W_START = vec[0][0];
  
  int64_t dp[N][W_MAX][N+1];
  for(int i=0; i<N; i++){
    for(int j=0; j<W_MAX; j++){
      for(int k=0; k<N+1; k++){
        dp[i][j][k] = 0;
      }
    }
  }
  
  for(int i=0; i<N; i++){
    int64_t x = vec[i][0] - W_START;
    int64_t y = vec[i][1];
    if(i == 0){
      dp[i][x][1] = y;
    }
    else{
      dp[i][x][1] = max(dp[i][x][1], y);
      for(int j=0; j<W_MAX; j++){
        for(int k=0; k<N+1; k++){
          if(dp[i-1][j][k] != 0){
            dp[i][j][k] = max(dp[i][j][k], dp[i-1][j][k]);
            dp[i][j+x][k+1] = max(dp[i][j+x][k+1], dp[i-1][j][k] + y);
          }
        }
      }
    }
  }
  
  int64_t ans = 0;
  for(int i=0; i<W_MAX; i++){
    for(int j=0; j<N+1; j++){
      if(i + j*W_START <= W && dp[N-1][i][j] != 0){
        ans = max(ans,dp[N-1][i][j]);
      }
    }
  }
  cout << ans << endl; 
}  

Measured memory_bytes: 23936
#include<stdio.h>

typedef struct{
  int r;
  int left;
  int right;
}Tree;

Tree tree[100];
int n;

void preorder(int r){
  if(r==-1) return;
  printf(" %d",r);
  preorder(tree[r].left);
  preorder(tree[r].right);
}

void inorder(int r){
  if(r==-1) return;
  inorder(tree[r].left);
  printf(" %d",r);
  inorder(tree[r].right);
}

void postorder(int r){
  if(r==-1) return;
  postorder(tree[r].left);
  postorder(tree[r].right);
  printf(" %d",r);
}

int main(){
  int i,root,r,left,right;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    tree[i].r=-1;
  }
  for(i=0;i<n;i++){
    scanf("%d%d%d",&r,&left,&right);
    tree[r].left=left;
    tree[r].right=right;
    if(left != -1) tree[left].r=r;
    if(right!=-1) tree[right].r=r;
  }
  for(i=0;i<n;i++){
    if(tree[i].r == -1)root = i;
  }
  printf("Preorder\n");
  preorder(root);
  printf("\nInorder\n");
  inorder(root);
  printf("\nPostorder\n");
  postorder(root);
  printf("\n");
  return 0;
}

Measured memory_bytes: 616
#include <iostream>

using namespace std;

#define int long long

const int mod = 1e9 + 7;

int a[200001];

int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);    
  int n;
  cin >> n;
  int ans = 0, cur = 0;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    cur += a[i];
    cur %= mod;
  }
  for (int i = 0; i < n; ++i) {
    cur -= a[i];
    cur %= mod;
    cur += mod;
    cur %= mod;
    ans += a[i] * cur;
    ans %= mod;
  }
  cout << ans;
  return 0;
}


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

namespace aizu
{
    class OnlineJudge
    {
        static void Main()
        {
            int input;
            while((input = int.Parse(Console.ReadLine())) != 0) {
                List<int> taro = new List<int>(Enumerable.Range(1, input).Select(p => int.Parse(Console.ReadLine())).OrderBy(p => p));
                List<int> hanako = new List<int>(Enumerable.Range(1, input * 2).Where(p => !taro.Contains(p)));
                List<List<int>> list = new List<List<int>> { taro, hanako };
                int now = 0;
                int index = 1;
                while(list[index].Count != 0) {
                    now = Check(list[(index ^= 1)], now);
                }
                Console.WriteLine(hanako.Count);
                Console.WriteLine(taro.Count);
            }
        }
        static int Check(List<int> player, int now)
        {
            int index = player.FindIndex(p => p > now);
            if(index == -1) {
                return 0;
            }
            now = player[index];
            player.RemoveAt(index);
            return now;
        }
    }
}

Measured memory_bytes: 6548
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1003;
const int mod = 1e9 + 7;

int dx[] = { 0, 0, 1, -1 };
int dy[] = { 1, -1, 0, 0 };
string s;
int f[30];
int main() {
//	freopen("input.txt", "r", stdin);
cin>>s;
ll n=s.size();
ll ans=n*(n-1)/2+1;
for(int i=0;i<n;i++){
	ans-=f[s[i]-'a'];
	f[s[i]-'a']++;
}
cout<<ans;
}



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

typedef long long ll;
typedef unsigned long long ull;
typedef string st;
typedef double db;
typedef vector<long long> vecll;
typedef vector<char> vechar;

int main(){
    ll N, X;
    cin >> N >> X;
    vecll m(N);
    for(auto& i : m) cin >> i;
    
    ll sum = 0;
    ll minn = m.at(0);
    for(auto& i : m) sum += i;
    for(auto& i : m) minn = min(minn, i);
    cout << (X - sum) / minn + N << endl;
}

Measured memory_bytes: 256
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <cstring>
#include <deque>
#include <cstdio>
#include <cmath>
#include <complex>
#include <iostream>
#include <iterator>

using namespace std;

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

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

const double EPS = 1e-8;

int main()
{
	int m;
	while(scanf("%d", &m), m){
		double sm1 = 0.0;
		int arg = 0;
		rep(i, m-1){
			int deg;
			scanf("%d", &deg);
			arg += deg;
			sm1 += sin(deg*M_PI/180.0);
		}
		sm1 += sin((360-arg)*M_PI/180.0);
		
		int n;
		scanf("%d", &n);
		
		double sm2 = 0.0; 
		arg = 0;
		rep(i, n-1){
			int deg;
			scanf("%d", &deg);
			arg += deg;
			sm2 += sin(deg*M_PI/180.0);
		}
		sm2 += sin((360-arg)*M_PI/180.0);
		
		if(fabs(sm1 - sm2) < EPS)
			puts("0");
		else
			puts(sm1>sm2 ? "1" : "2");
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
  
using namespace std;
  
template<class T> void ckmin(T &a, T b) { a = min(a, b); }
template<class T> void ckmax(T &a, T b) { a = max(a, b); }
  
#define pb push_back
#define mp make_pair
#define cotu cout
#define itn int
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repr(i,n) for(int i = n - 1; i >= 0; --i)
#define Rep(i, a, n) for(int i = (a); i <=(n); ++i)
#define repst(i, n) for(auto it = n.begin(); it != n.end(); ++it)
#define Repr(i, a, n) for(int i = (n); i >= (a); --i)
#define sp(x) fixed << setprecision(x)
#define ordered_set tree<int , null_type,less<int >, rb_tree_tag,tree_order_statistics_node_update> 
  
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
  
const int inf = int(1e9);
const int mod = inf + 7;
const int N = 1e6 + 555; // TL MB
const double PI = acos(-1.0);
void mul(ll &x, ll y){
	x *= y;
	if(x >= mod) x %= mod;
}
 
void add(ll &x, ll y){
	x += y;
	if(x >= mod) x -= mod;
	if(x < 0) x += mod;
}
ll bp(ll a, ll n){
	ll r = 1;
	while(n){
		if(n & 1) mul(r, a);
		mul(a, a);
		n >>= 1;
	}
 
}



void solve()
{
	vector<int> v;
	int n;
	cin >> n;
	int x = 0, y = 0, z = 0;
	rep(i, n){
		ll a, cnt = 0;
		cin >> a;
		while(a % 2 == 0) a /= 2, ++cnt;
		if(cnt >= 2) ++x;
		else if(cnt == 0) ++y;
		else ++z;
	}
	if(x + !z >= y) cout << "Yes";
	else cout << "No";

}

 
int main()
{
	// freopen("crosses.in", "r", stdin);
	// freopen("crosses.out", "w", stdout);
    Red;
  	int T = 1;
  	// cin >> T;
  	for(int i = 1; i <= T; ++i){
  		solve();
  	}
  	return 0;

}

Measured memory_bytes: 3584
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
#define infinity 1000000010;
int n,cnt=0;
int A[500010],L[250010],R[250010];
 
void merge(int left,int mid,int right){
	for(int i=0;i<mid-left;i++) L[i]=A[left+i];
	for(int i=0;i<right-mid;i++) R[i]=A[mid+i];
	L[mid-left]=infinity;R[right-mid]=infinity;
	int i=0,j=0;
	for(int k=left;k<right;k++){
		cnt++;
		if(L[i]>R[j]) A[k]=R[j++];
		else A[k]=L[i++];
	}
	return ;
}
 
void merge_sort(int left,int right){
	if(left+1<right){
	int mid=(left+right)/2;
	merge_sort(left,mid);
	merge_sort(mid,right);
	merge(left,mid,right);
	return ;
	}
}
 
int main (){
	cin>>n;
	for(int i=0;i<n;i++) cin>>A[i];
	merge_sort(0,n);
	for(int i=0;i<n;i++) {
		if(i) cout<<" ";
		cout<<A[i];
	}
	cout<<endl<<cnt<<endl;
	return 0;
}



Measured memory_bytes: 7004
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace ABC107A
{
    class Program
    {
        static void Main(string[] args)
        {
            int a, b, x;
            var word = Console.ReadLine().Split(' ');
 
            a = int.Parse(word[0]);
            b = int.Parse(word[1]);
 
            x = a - b+1;
 
            Console.WriteLine(x);
            Console.ReadKey();
        }
    }
}

Measured memory_bytes: 11092