akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
#include<complex>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 4000001;
const double eps = 1E-18;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

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

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

ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};

class mint {
	long long x;
public:
	mint(long long x = 0) : x((x% MOD + MOD) % MOD) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint& a) {
		if ((x += a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator-=(const mint& a) {
		if ((x += MOD - a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator*=(const  mint& a) {
		(x *= a.x) %= MOD;
		return *this;
	}
	mint operator+(const mint& a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint& a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint& a) const {
		mint res(*this);
		return res *= a;
	}

	mint operator^(const ll& t)const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}
	// for prime MOD
	mint inv() const {
		return pow(MOD - 2);
	}
	mint& operator/=(const mint& a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint& a) const {
		mint res(*this);
		return res /= a;
	}

	friend ostream& operator<<(ostream& os, const mint& m) {
		os << m.x;
		return os;
	}
};

///////////////////////////

bool cmp(pair<ll, ll> x, pair<ll, ll> y) {
	return x.first + x.second < y.first + y.second;
}


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

	vector<pair<ll, ll>> p(N + 1);
	repn(i, N) cin >> p[i].first >> p[i].second;

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

	//repn(i, N) cout << p[i].first << p[i].second << endl;

	vector<vector<ll>> dp(N + 1, vector<ll>(N + 1, INF));
	rep(i, N + 1) dp[i][0] = 0;

	repn(i, N)repn(j, N) {
		if (dp[i - 1][j - 1] <= p[i].first) { dp[i][j] = min(dp[i][j], dp[i - 1][j - 1] + p[i].second); }
		dp[i][j] = min(dp[i][j], dp[i - 1][j]);
	}

	ll ans = 0;
	repn(j, N) {
		if (dp[N][j] < INF) { ans = j; }
	}
	cout << ans << endl;
	
	
	system("PAUSE");
}


Measured memory_bytes: 196096
K, A, B = map(int, input().split())
e = B - A

if e <= 2 or A >= K:
    ans = K + 1
else:
    ans = B
    count = A + 1
    while count < K:
        e_count = min(ans // A, (K - count) // 2)
        if e_count > 0:
            ans += e_count * e
            count += e_count * 2
        else:
            if A > ans:
                count += min(A - ans, K - count)
                ans += min(A - ans, K - count)
            else:
                tataku = K - count
                count += tataku
                ans += tataku
print(ans)


Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
using namespace std;
using llong = long long;

llong N, W;
vector<llong> value[5];
llong w0;

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

    {
        llong v;
        cin >> w0 >> v;
        value[0].push_back(v);
    }

    for (int i = 1; i < N; i++) {
        llong v, w;
        cin >> w >> v;
        value[w - w0].push_back(v);
    }

    for (int i = 0; i < 5; i++) {
        sort(value[i].rbegin(), value[i].rend());
        value[i].push_back(0);
        for (int j = value[i].size() - 1; j > 0; j--) {
            value[i][j - 1] += value[i][j];
        }
    }
    
    llong ans = 0;
    for (int i = 0; i < value[0].size(); i++) {
        for (int j = 0; j < value[1].size(); j++) {
            for (int k = 0; k < value[2].size(); k++) {
                for (int l = 0; l < value[3].size(); l++) {
                    if (w0 * i + (w0 + 1) * j + (w0 + 2) * k + (w0 + 3) * l <= W) {
                        ans = max(ans,
                                  value[0][0] - value[0][i] +
                                  value[1][0] - value[1][j] +
                                  value[2][0] - value[2][k] +
                                  value[3][0] - value[3][l]);
                    }
                }
            }
        }
    }

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


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

using namespace std;
typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define tll tuple<ll, ll, ll>
#define all(c) c.begin(),c.end()

const ll inf = 1000000001;
const ll INF = 1e18;
const ll MOD = 1000000007;

ll h[50];
ll p[50];

ll calc(ll n, ll x){
  if (n == 0) return 1;
  if (x == 1) return 0;
  if (1 < x && x <= h[n-1]+1) return calc(n-1, x-1);
  if (x == h[n-1]+2) return p[n-1] + 1;
  if (h[n-1]+2 < x && x <= 2*h[n-1]+2) return p[n-1] + 1 + calc(n-1, x-h[n-1]-2);
  if (x == 2*h[n-1]+3) return 2*p[n-1] + 1;
  //if (n==0){
  //  if (x <= 0) return 0;
  //  else return 1;
  //}
  //else if (x <= h[n-1]+1) return calc(n-1, x-1);
  //else return p[n-1] + 1 + calc(n-1, x-h[n-1]-2);
}

int main() {
  ll n, x;
  cin >> n >> x;
  h[0] = 1;
  p[0] = 1;
  for(int i=1;i<=50;i++){
    h[i] = 2*h[i-1] + 3;
    p[i] = 2*p[i-1] + 1;
  }
  
  ll ans = calc(n,x);
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
using namespace  std;

const double cos60 = cos(M_PI / 3);
const double sin60 = sin(M_PI / 3);

struct StPnt
{
  double m_nx;
  double m_ny;

  StPnt() :
    m_nx(0), m_ny(0)
  { }

  StPnt(double nx, double ny) :
    m_nx(nx), m_ny(ny)
  { }
};

void fnInput(int &rnRcSiz)
{
  cin >> rnRcSiz;
}

void fnPntGet(const StPnt &cnroPntL, const StPnt &cnroPntR, vector<StPnt> &rvoRtnPnt)
{
  rvoRtnPnt[0].m_nx = (2 * cnroPntL.m_nx + cnroPntR.m_nx) / 3;
  rvoRtnPnt[0].m_ny = (2 * cnroPntL.m_ny + cnroPntR.m_ny) / 3;
  rvoRtnPnt[2].m_nx = (cnroPntL.m_nx + 2 * cnroPntR.m_nx) / 3;
  rvoRtnPnt[2].m_ny = (cnroPntL.m_ny + 2 * cnroPntR.m_ny) / 3;

  rvoRtnPnt[1].m_nx =  (rvoRtnPnt[2].m_nx - rvoRtnPnt[0].m_nx) * cos60 
                     - (rvoRtnPnt[2].m_ny - rvoRtnPnt[0].m_ny) * sin60 + rvoRtnPnt[0].m_nx;
  rvoRtnPnt[1].m_ny =  (rvoRtnPnt[2].m_nx - rvoRtnPnt[0].m_nx) * sin60 
                     + (rvoRtnPnt[2].m_ny - rvoRtnPnt[0].m_ny) * cos60 + rvoRtnPnt[0].m_ny;
}

void fnResult(const StPnt &cnroPnt)
{
  cout << cnroPnt.m_nx << " " << cnroPnt.m_ny << endl;
}

void fnKoch(int nRcSiz, const StPnt &cnroPntL, const StPnt &cnroPntR)
{
  if (!nRcSiz) return;

  vector<StPnt> voRtnPnt(3);
  fnPntGet(cnroPntL, cnroPntR, voRtnPnt); 
  
  nRcSiz--;
  fnKoch(nRcSiz, cnroPntL, voRtnPnt[0]);
  fnResult(voRtnPnt[0]);

  fnKoch(nRcSiz, voRtnPnt[0], voRtnPnt[1]);
  fnResult(voRtnPnt[1]);

  fnKoch(nRcSiz, voRtnPnt[1], voRtnPnt[2]);
  fnResult(voRtnPnt[2]);

  fnKoch(nRcSiz, voRtnPnt[2], cnroPntR);
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(8);

  int nRcSiz;
  vector<StPnt> voPnt;

  fnInput(nRcSiz);
  StPnt oPntL(0, 0);
  StPnt oPntR(100, 0);

  fnResult(oPntL);
  fnKoch(nRcSiz, oPntL, oPntR);
  fnResult(oPntR);
  return 0;
}

Measured memory_bytes: 3288
#![allow(unused_imports)]
use std::io;
use std::cmp::*;
use std::collections::*;
#[allow(dead_code)]
const M: i64 = 1e9 as i64 + 7;

fn read_line() -> String {
    let stdin = io::stdin();
    let mut buf = String::new();
    stdin.read_line(&mut buf).unwrap();
    buf
}
#[allow(dead_code)]
fn read<T>() -> T where T: std::str::FromStr, T::Err : std::fmt::Debug {
    read_line().trim().parse().unwrap()
}
#[allow(dead_code)]
fn readv<T>() -> Vec<T> where T: std::str::FromStr, T::Err : std::fmt::Debug {
    read_line().split(' ').map(|a| a.trim().parse().unwrap()).collect()
}

fn main() {
    let _ = read::<usize>();
    let aa = readv::<usize>();
    let bb = readv::<usize>();
    let x = aa.iter().fold(0, |acc, &a| acc ^ a);
    let (mut aa, bb): (Vec<_>, Vec<_>) = aa.iter().zip(bb.iter()).filter(|&(&a, &b)| a != b).unzip();
    let n = aa.len();
    aa.push(x);
    let mut nums: HashMap<_, i32> = aa.iter()
        .fold(HashMap::new(), |mut acc, &a| { *acc.entry(a).or_insert(0) += 1; acc });
    for &b in &bb {
        *nums.entry(b).or_insert(0) -= 1;
        if nums[&b] < 0 {
            println!("{}", -1);
            return;
        }
    }

    let mut dests = bb.iter().enumerate()
        .fold(HashMap::new(), |mut acc, (a, b)| { (acc.entry(b).or_insert(Vec::new())).push(a); acc });
    let mut q: VecDeque<_> = std::iter::once(n).collect();
    let mut rems: HashSet<_> = (0..n + 1).collect();
    let mut ans = n;
    #[cfg(local)] println!("{}: {:?}", "(aa, bb)", (&aa, &bb));
    while !rems.is_empty() {
        while let Some(s_idx) = q.pop_front() {
            if !rems.remove(&s_idx) { continue; }
            let s_num = aa[s_idx];
            if let Some(destv) = dests.remove(&s_num) {
                for dest in destv {
                    q.push_back(dest);
                }
            }
        }
        if let Some(&rem) = rems.iter().next() {
            q.push_back(rem);
            ans += 1;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 26660
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace 競プロCS {
    class ABC136B {
        static void Main(string[] args) {
            int count = 0;
            int N = int.Parse(Console.ReadLine());
            for (int i = 0; i < N; i++) {
                string s = (i + 1).ToString();
                int len = s.Length;
                if (len % 2 != 0) {
                    count++;
                }
            }
            Console.WriteLine(count);
        }
    }
}


Measured memory_bytes: 13140
n = int(input())
S = list(map(int, input().split()))
q = int(input())
T = list(map(int, input().split()))
ans = 0

for Ti in T:
    left = 0
    right = n
    while left < right:
        mid = int((left + right) / 2)
        if S[mid] == Ti:
            ans += 1
            break
        elif Ti < S[mid]:
            right = mid
        else: #S[mid] < Ti:
            left = mid +1

print(ans)


Measured memory_bytes: 16708
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <math.h>
#include <sstream>
#include <numeric>
#include <string>
#include <cassert>

using namespace std;
typedef long long ll;

int main() {
  int N;
  cin >> N;
  vector<double> x(N);
  vector<double> y(N);
  for (int i = 0; i < N; ++i) {
    cin >> x[i] >> y[i];
  }

  int nsteps = 1000000;
  double maxdist = 0.0;
  vector<int> maxused;
  for (int i = 0; i < nsteps; ++i) {
    vector<int> used;
    double theta = 2.0 * 3.14159265358979323846 * double(i) / double(nsteps);
    double rx = cos(theta);
    double ry = sin(theta);
    double dist = 0.0;
    for (int i = 0; i < N; ++i) {
      double d = x[i] * rx + y[i] * ry;
      if (d > 0.0) {
	dist += d;
	used.push_back(i);
      }
    }
    if (dist > maxdist) {
      maxdist = max(maxdist, dist);
      maxused = used;
    }
  }

  double xx = 0.0;
  double yy = 0.0;
  for (auto i : maxused) {
    xx += x[i];
    yy += y[i];
  }
  double recalc_dist = sqrt(xx * xx + yy * yy);
  cout << setprecision(20) << recalc_dist << endl;
  return 0;
}


Measured memory_bytes: 512
/**
 	Template created by Danel Batyrbek
 	All rights are reserved 2017 (lol)
*/

#include <bits/stdc++.h>

#define speed_up ios_base :: sync_with_stdio(0);cin.tie(0)
#define fr first
#define sc second
#define mkp make_pair
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define debug(x) cerr << x << '\n';
#define YES "YES"
#define NO "NO"
#define skip continue
#define left(x) x << 1
#define rght(x) x << 1 | 1
#define forn(x, y, z) for(int x = y; x <= z; ++ x)
#define for1(x, y, z) for(int x = y; x >= z; -- x)
#define fname ""
using namespace std;

typedef long long ll;
typedef pair <int, int> pii;
typedef double ld;

const int N = 1e5 + 10;
const int mod = 1e9 + 7;
const int N3 = 1e3 + 10;
const int INF = 2e9 + 10;
const ll LINF = 2e18;

ll Q, H, S, D, val1, val2, ans, n;

int main(){
#ifndef DEBUG
	if(fname != ""){
	freopen(fname".in", "r", stdin);
	freopen(fname".out", "w", stdout);
	}
#endif
	cin >> Q >> H >> S >> D;
	cin >> n;
	val1 = min(S, min(Q * 4, H * 2));
	val2 = min(val1 * 2, D);
	if(n & 1){
		ans += val1;
	}
	ans += (n / 2 * val2);
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(j, m) for (int j = 0; i < (int)(n); j++)
using ll = long long;
using namespace std;

int main()
{
    int n;
    cin >> n;
    float s = 0;
    vector<int> v(n);
    rep(i, n)
    {
        cin >> v[i];
    }
    sort(v.begin(), v.end());
    rep(i, n)
    {
        if (i == 0)
        {
            s += v[i];
        }
        else
        {
            s = (float)(s + v[i]) / 2;
        }
    }
    cout << fixed << setprecision(5);
    cout << s << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#include <cstdlib>
#include <deque>
#include <stack>

using namespace std;
const long long P = 1000000007;
const long long INF = 1LL << 60;

double dist(double x1,double y1, double x2, double y2) {
  double res = sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));
  return res;
}

int main() {
  int n;
  cin >> n;
  double x[n],y[n];
  for(int i = 0; i < n; i++) {
    cin >> x[i] >> y[i];
  }
  double sum = 0;
  for(int i = 0; i < n; i++) {
    for(int j = i+1; j < n; j++) {
      sum += dist(x[i],y[i],x[j],y[j])*2/n;
    }
  }
  printf("%.10lf",sum);
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>
#include<numeric>
#include<cassert>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define rep(i,s,n) for(int i=(s); i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define IN(x,s,g) ((x) >= (s) && (x) < (g))
#define ISIN(x,y,w,h) (IN((x),0,(w)) && IN((y),0,(h)))
#define print(x) printf("%d\n",x)

using namespace std;

typedef unsigned int uint;
typedef long long ll;

const int _dx[] = {0,1,0,-1};
const int _dy[] = {-1,0,1,0};

int getInt(){
  int ret = 0,c;
  c = getchar();
  while(!isdigit(c)) c = getchar();
  while(isdigit(c)){
    ret *= 10;
    ret += c - '0';
    c = getchar();
  }
  return ret;
}

bool b[2010][2010];
bool c[2010][2010];

int xsize,ysize;

void check(int x, int y){
  if(!ISIN(x,y,xsize,ysize)) return;
  if(c[y][x]||b[y][x]) return;
  c[y][x] = true;
  REP(i,4) check(x+_dx[i],y+_dy[i]);
}

int main(){
  int w,h;
  while((w = getInt()) + (h = getInt())){
    int n = getInt();
    vector<int> x1(n);
    vector<int> x2(n);
    vector<int> y1(n);
    vector<int> y2(n);

    vector<int> x(n+n+2);
    vector<int> y(n+n+2);

    x[n+n] = 0; x[n+n+1] = w;
    y[n+n] = 0; y[n+n+1] = h;

    REP(i,n){
      x1[i] = getInt();
      y1[i] = getInt();
      x2[i] = getInt();
      y2[i] = getInt();

      x[i+i] = x1[i]; x[i+i+1] = x2[i];
      y[i+i] = y1[i]; y[i+i+1] = y2[i];
    }

    sort(x.begin(), x.end());
    sort(y.begin(), y.end());

    vector<int>::iterator xend = unique(x.begin(), x.end());
    vector<int>::iterator yend = unique(y.begin(), y.end());

    xsize = xend - x.begin() - 1;
    ysize = yend - y.begin() - 1;

    REP(i,ysize) REP(j,xsize) b[i][j] = c[i][j] = false;
    REP(k,n){
#define sch(x,e,v) (lower_bound((x).begin(),(e),(v)) - (x).begin())
      int is = sch(y,yend,y1[k]);
      int ie = sch(y,yend,y2[k]);
      int js = sch(x,xend,x1[k]);
      int je = sch(x,xend,x2[k]);
      for(int i=is; i<ie; i++)
        for(int j=js; j<je; j++)
          b[i][j] = true;
    }

    /*
    printf("x:"); REP(i,xsize) printf("%d ",x[i]); puts("");
    printf("y:"); REP(i,ysize) printf("%d ",y[i]); puts("");
    REP(i,ysize){REP(j,xsize)printf("%c",b[i][j]?'#':'.');puts("");}
    */

    int ans = 0;
    REP(i,ysize) REP(j,xsize) if(!b[i][j] && !c[i][j]){
      ++ans;
      check(j,i);
    }

    print(ans);
  }
  return 0;
}

Measured memory_bytes: 0
sx,sy,tx,ty = map(int,input().split())
ans = ""
r = tx-sx
u = ty-sy

ans += "R"*r+"U"*u+"L"*r+"D"*u
ans += "D"+"R"*(r+1)+"U"*(u+1)+"L"
ans += "U"+"L"*(r+1)+"D"*(u+1)+"R"

print(ans)


Measured memory_bytes: 39796
import sys
from numpy import*
from scipy.sparse import*
f=csgraph.floyd_warshall
def main():
  t=fromstring(sys.stdin.buffer.read(),'i',sep=' ')
  n,m,l=t[:3]
  m=m*3+3
  print('\n'.join((clip(f(f(csr_matrix((t[5:m:3],(t[3:m:3],t[4:m:3])),[n+1]*2),0)<=l)[t[m+1::2],t[m+2::2]],0,n).astype(int)%n-1).astype(str).tolist()))
main()

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

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

	ll i,j,k,l,m,n,t;

	cin >> n;

	string s;

	ll ac = 0,wa = 0,tle = 0,re = 0;

	for(i=0;i<n;i++)
	{
		cin >> s;

		if(s == "AC")
			ac++;
		if(s == "WA")
			wa++;
		if(s == "TLE")
			tle++;
		if(s == "RE")
			re++;
	}

	cout << "AC x " << ac << '\n';
	cout << "WA x " << wa << '\n';
	cout << "TLE x " << tle << '\n';
	cout << "RE x " << re << '\n';

	

}

Measured memory_bytes: 3656
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    let s: Vec<char> = iter.next().unwrap().chars().collect();
    println!("{}", match s[0] {
        'T' => 'A',
        'A' => 'T',
        'G' => 'C',
        'C' => 'G',
        _ => ' ',
    });
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
 
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
typedef long long ll;

int main(){
    int n;
    ll a[100010];
    cin>>n;
    REP(i,n) cin>>a[i];
    int cnt=0;
    int i=0;
    while(i<n){

        if(a[i]==a[i+1]) {
            i++;
            continue;
        }

        if(a[i]<=a[i+1]){
            for(int j=i;j<n;j++){
                if(a[j]>a[j+1]){
                    cnt++;
                    i=j+1;
                    break;
                }
                if(j==n-1){
                    cnt++;
                    i=n;
                }
            }
        }
        else {
            for(int j=i;j<n;j++){
                if(a[j]<a[j+1]){
                    cnt++;
                    i=j+1;
                    break;
                }
                if(j==n-1){
                    cnt++;
                    i=n;
                }
            }
        }
        }

    
    cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

void solve(int h, int w){
    array<int, 4> dx{-1, 1, 0, 0}, dy{0, 0, -1, 1};
    vector<vector<int>> v(h+2, vector<int>(w+2, -1));
    int sy, sx, gy, gx;
    for (int i = 0; i < h; ++i) {
        string s;
        cin >> s;
        for (int j = 0; j < w; ++j) {
            if(s[j] == 'X') v[i+1][j+1] = 1000;
            else if(s[j] == '#' || s[j] == 'S') v[i+1][j+1] = -1;
            else v[i+1][j+1] = 0;
            if(s[j] == 'S') sy = i+1, sx = j+1;
            else if(s[j] == 'G') gy = i+1, gx = j+1;
        }
    }
    vector<int> M{0};
    for (int i = 0, cur = 1; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            if(v[i+1][j+1] == 1000){
                queue<pair<int, int>> Q;
                Q.emplace(i+1, j+1);
                M.emplace_back();
                v[i+1][j+1] = cur;
                while(!Q.empty()){
                    M.back()++;
                    int y, x; tie(y, x) = Q.front(); Q.pop();
                    for (int k = 0; k < 4; ++k) {
                        if(v[y+dy[k]][x+dx[k]] == 1000){
                            v[y+dy[k]][x+dx[k]] = cur;
                            Q.emplace(y+dy[k], x+dx[k]);
                        }
                    }
                }
                M.back() /= 2;
                cur++;
            }
        }
    }
    for (int ans = abs(sx-gx)+abs(sy-gy); ; ++ans) {
        auto G = v;
        vector<int> m(M.size());
        auto dfs = [&](int y, int x, int dep, auto &&f) -> bool {
            if(gy == y && gx == x) return true;
            if(dep+abs(gy-y)+abs(gx-x) > ans) return false;
            for (int k = 0; k < 4; ++k) {
                int p = G[y+dy[k]][x+dx[k]];
                if(p == 0){
                    G[y+dy[k]][x+dx[k]] = -1;
                    if(f(y+dy[k], x+dx[k], dep+1, f)) return true;
                    G[y+dy[k]][x+dx[k]] = 0;
                }else if(p > 0 && m[p]+1 <= M[p]){
                    m[p]++;
                    G[y+dy[k]][x+dx[k]] = -1;
                    if(f(y+dy[k], x+dx[k], dep+1, f)) return true;
                    G[y+dy[k]][x+dx[k]] = p;
                    m[p]--;
                }
            }
            return false;
        };
        if(dfs(sy, sx, 0, dfs)){
            cout << ans << "\n";
            return;
        }
    }


}

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

    }
    return 0;
}


Measured memory_bytes: 3184
import java.util.*;
public class Main {

  public static void main(String[] args) { 
      Scanner sc = new Scanner(System.in);
      int h = sc.nextInt();
      int w = sc.nextInt();
      int k = sc.nextInt();

      char[][] grid = new char[h][w];
      for(int i = 0; i < h; i++)
        grid[i] = sc.next().toCharArray();

      int[] cnt = new int[h];
      for(int i = 0; i < h; i++) {
        for(int j = 0; j < w; j++)
          if(grid[i][j] == '#') cnt[i]++;
      }

      int[][] res = new int[h][w];
      int curK = 1;
      for(int i = 0; i < h; i++) {
        if(cnt[i] == 0) continue;
        int rowCnt = cnt[i];
        for(int j = 0; j < w; j++) {
          if(rowCnt == 0)
            res[i][j] = curK - 1;
          else
            res[i][j] = curK;
          if(grid[i][j] == '#') {
            curK++;
            rowCnt--;
          }
        }
      }
      int nonEmptyRow = h - 1;
      for(; nonEmptyRow >= 0; nonEmptyRow--) {
        if(cnt[nonEmptyRow] > 0) break;
      }
      for(int i = nonEmptyRow; i < h - 1; i++) {
        if(cnt[i+1] > 0) continue;
        for(int j = 0; j < w; j++) {
          res[i+1][j] = res[i][j];
        }
      }
      for(int i = nonEmptyRow; i >= 1; i--) {
        if(cnt[i-1] > 0) continue;
        for(int j = 0; j < w; j++)
          res[i-1][j] = res[i][j];
      }
      for(int i = 0; i < h; i++)
        for(int j = 0; j < w; j++)
            if(j == w - 1)
                System.out.println(res[i][j]);
            else
                System.out.print(res[i][j] + " ");
  }
}

Measured memory_bytes: 47844
int main(void){
    int n,i=0,a,min,max;
    long long sum=0;
    scanf("%d",&n);
    while(1){
    if(i>=n)
 	break;
    scanf("%d",&a);
    if(i==0){
	min=a;
        max=a;
    }if(min>a)
	min=a;
    if(max<a)
	max=a;
    sum+=a;
    i++;
    }
    printf("%d %d %lld\n",min,max,sum);
    return 0;
}

Measured memory_bytes: 600
import sys
input = sys.stdin.buffer.readline

n = int(input())
a = list(map(int,input().split()))

a.append(n+1)
a.append(n+1)

dp = [[-1]*(n+2) for i in range(n+2)]
ma = [-1]*(n+2)

dp[a[0]][a[1]] = 0
ma[a[0]] = 0
ma[a[1]] = 0

after = 0

for i in range(n):
    x,y,z = a[3*i+2],a[3*i+3],a[3*i+4]
    if x == z:
        y,z = z,y
    if y == z:
        x,z = z,x
    
    if x == z:
        after += 1
        continue

    
    tank = []

    if x != y:
        for i in range(n+1):
            tank.append((i,x,ma[i]))
            tank.append((i,y,ma[i]))
            tank.append((i,z,ma[i]))       
        tank.append((x,y,max(max(ma),dp[z][z] + 1)))
        tank.append((x,z,max(max(ma),dp[y][y] + 1)))
        tank.append((y,z,max(max(ma),dp[x][x] + 1)))
    else:
        for i in range(n+1):
            tank.append((i,x,ma[i]))
            tank.append((i,y,ma[i]))
            tmp = ma[i]
            if dp[i][x] != -1:
                tmp = max(tmp,dp[i][x] + 1)
            if dp[x][i] != -1:
                tmp = max(tmp,dp[x][i] + 1)
            tank.append((i,z,tmp))
        tank.append((x,y,max(max(ma),dp[z][z] + 1)))
        tank.append((x,z,max(max(ma),dp[y][y] + 1)))
        tank.append((y,z,max(max(ma),dp[x][x] + 1)))

    for p,q,c in tank:
        dp[p][q] = max(dp[p][q],c)
        ma[p] = max(ma[p],c)
        ma[q] = max(ma[q],c)

res = 0
for i in range(n+2):
    for j in range(n+2):
        res = max(res,dp[i][j])

print(res+after)

Measured memory_bytes: 218320
'use strict';
(function(stdin) { 
  var inputs = stdin.toString();
  (function(x) {console.log(Math.pow(x,3));
    //????????????????????????
  }(parseInt(inputs.trim(),10))); //????°??????????????¶?????????°?????????
}(require('fs').readFileSync('/dev/stdin', 'utf8')));

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

int main() {
    string s;cin>>s;
    int n=s.size();
    int c=0;
    for (int i=0;i<n;i++)
        if (i%2==0&&s[i]=='1'||i%2==1&&s[i]=='0')
            c++;
    cout<<min(c,n-c)<<endl;
    return 0;
}

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

const int BORDER = 1000000;

class myMap
{
public:
	myMap() :mSize( 0 ){}

	void insert( int id, int p, int q ){
		bool find = false;
		long long gross = ( long long )p * q;
		for( int i = 0; i < mSize; ++i ){
			if( mIDList[ i ].first == id ){
				if( mIDList[ i ].second < 1000000 ){
					mIDList[ i ].second += gross;
				}
				find = true;
				break;
			}
		}
		if( !find ){
			mIDList.push_back( pair< int, long long >( id, gross ) );
			++mSize;
		}
	}
	void output(){
		bool finded = false;
		for( int i = 0; i < mSize; ++i ){
			if( mIDList[ i ].second >= BORDER ){
				finded = true;
				cout << mIDList[ i ].first << endl;
			}
		}
		if( !finded ){
			cout << "NA" << endl;
		}
	}

	vector< pair< int, long long > > mIDList;
	int mSize;
};

int main()
{
	int n;

	while( cin >> n && n ){
		myMap db;
		int id, unit, amount;
		for( int i = 0; i < n; ++i ){
			cin >> id >> unit >> amount;
			db.insert( id, unit, amount );
		}
		db.output();
	}

	return 0;
}

Measured memory_bytes: 0
fun main(args: Array<String>) {
    val (n, m) = readLine()!!.split(' ').map(String::toLong)
    val s = readLine()!!
    val t = readLine()!!
    val kobai = n * m / gcd(n, m)
    val xs = mutableMapOf<Long, Char>()
    s.forEachIndexed { index, c ->
        xs[index * kobai / n + 1] = c
    }
    t.forEachIndexed { index, c ->
        if ((xs[index * kobai / m + 1]?.equals(c)?.not() == true)) {
            println(-1)
            return
        }
    }
    println(kobai)


}

fun gcd(a: Long, b: Long): Long {
    return if (b > 0) gcd(b, a % b) else a
}

Measured memory_bytes: 41456
import bisect
n, q = map(int, input().split())
s = input()
ac = 'AC'
args = []
for i in range(len(s) - 1):
    if s[i:i+2] == 'AC':
        args.append(i)
for j in range(q):
    l, r = map(int, input().split())
    i_l = bisect.bisect_left(args, l-1)
    i_r = bisect.bisect_right(args, r-2)
    print(i_r - i_l)

Measured memory_bytes: 5748
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<memory>
#include<functional>

#define rep(i, n) REP(i, 0, n)
#define REP(i, a, n) for(int i = a ; i < (int)n ; i++)
#define ALL(v) v.begin(), v.end()
#define pb push_back
#define mp make_pair
#define eps 1e-14
#define INF 1e9
#define m0(x) memset(x, 0, sizeof(x))

using namespace std;

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

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

signed main(){
  int a, b,c;

  cin >> a >> b >> c;

  cout << (a + b + c) - max(a, max(b, c)) << endl;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline

import numpy as np

MOD = 10**9 + 7

N,M,K = map(int,input().split())

def cumprod(arr):
    L = len(arr); Lsq = int(L**.5+1)
    arr = np.resize(arr,Lsq**2).reshape(Lsq,Lsq)
    for n in range(1,Lsq):
        arr[:,n] *= arr[:,n-1]; arr[:,n] %= MOD
    for n in range(1,Lsq):
        arr[n] *= arr[n-1,-1]; arr[n] %= MOD
    return arr.ravel()[:L]

U = 10**6
x = np.full(U,2,dtype=np.int64); x[0] = 1
pow2 = cumprod(x)
x = np.full(U,3,dtype=np.int64); x[0] = 1
pow3 = cumprod(x)
x = np.full(U,pow(2,MOD-2,MOD),dtype=np.int64); x[0] = 1
pow2_inv = cumprod(x)
x = np.full(U,pow(3,MOD-2,MOD),dtype=np.int64); x[0] = 1
pow3_inv = cumprod(x)
x = np.arange(U,dtype=np.int64); x[0] = 1
fact = cumprod(x)
x = np.arange(U,0,-1,dtype=np.int64); x[0] = pow(int(fact[-1]),MOD-2,MOD)
fact_inv = cumprod(x)[::-1]

L = N+M
A = np.zeros(N+M,dtype=np.int64)
A[1:L] = (-1) * pow2[0:L-1] * pow3_inv[0:L-1] % MOD
A[1:L] *= fact[K+1:K+L] * fact_inv[K] % MOD * fact_inv[1:L] % MOD; A %= MOD
A[1:L] *= pow3_inv[K+1]; A %= MOD
A[0] = 3 * (1 - pow3_inv[K+1]) % MOD * pow2_inv[1] % MOD
np.cumsum(A,out=A); A %= MOD
A *= pow3[:L]; A %= MOD
A *= pow2_inv[:L]; A %= MOD

comb = fact[N-1:N+M] * fact_inv[:M+1] % MOD * fact_inv[N-1] % MOD
answer = (comb * pow3[K+M:K-1:-1] % MOD * A[N-1:N+M] % MOD).sum() % MOD
print(answer)

Measured memory_bytes: 131224
#![allow(unused_imports)]

use text_io::*;
use proconio::*;
use std::collections::*;
use itertools::Itertools;
use std::process::exit;
use std::cmp::*;
use num::*;
use num::integer::Roots;

fn main() {
    input! {
    a:usize,
    }
    for i in 0..100000 {
        if i*108/100==a{
            println!("{}",i);
            exit(0)
        }
    }
    println!(":(")
}

Measured memory_bytes: 2176
#include<stdio.h>
#include<math.h>

int sos(int);

int pri[10000000];

int main(){
  int x;
  while(scanf("%d",&x)!=EOF){
    printf("%d\n",sos(x));
  }  
  return 0;
}

int sos(int a){
  int i,j,c=0,b;
  for(j=2;j<=a;j++){
    b=0;
    if(pri[j]==3)continue;
    if(pri[j]==1){c++;continue;}
    for(i=2;i<=sqrt(j);i++){
      if(j%i==0){pri[j]=3;b=1;break;}
      
    }
    if(b==0){pri[j]=1;c++;}
  }
  return c;
}

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

 using namespace std;
 typedef long long ll;
 #define rep(i, n) for(int i = 0; i < (int)(n); i++)

 ll lcm(ll x, ll y) {
   ll gcd;
   if (x < y) swap(x, y);
   ll X = x, Y = y;
   while (1) {
     ll tmp = Y;
     Y = X % Y;
     X = tmp;
     if (Y == 0) {
       gcd = tmp;
       break;
     }
   }
   return x / gcd * y;
 }

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

   for (int i = 1; i < N; i++) {
     ll t;
     cin >> t;
     ans = lcm(ans, t);
   }

   cout << ans << endl;
 }


Measured memory_bytes: 256
use std::io::prelude::*;

fn input<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    token.parse().ok().unwrap()
}

fn main() {
    let n: usize = input();

    let mut v = vec![];
    for i in 2..55556 {
        if is_prime(i) && i % 5 == 1 {
            v.push(i);
        }
        if v.len() == n {
            break;
        }
    }

    print!("{}", v[0]);
    for i in 1..n {
        print!(" {}", v[i]);
    }
    println!("");
}

fn is_prime(n: i32) -> bool {
    let mut ok = true;
    for i in 2..n {
        if i * i > n {
            break;
        }

        if n % i == 0 {
            ok = false;
            break;
        }
    }
    ok
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr double eps = 1e-9;
constexpr ll MOD = 1000000007LL;
template <typename T> bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T> bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T> ostream &operator<<(ostream &os, vector<T> v) {
    for (int i = 0; i < v.size(); i++) {
        os << v[i] << (i + 1 == v.size() ? "\n" : " ");
    }
    return os;
}
template <typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) {
    t = v;
}
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) {
    for (auto &e : t) {
        fill_v(e, v);
    }
};
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int e, y;
    cin >> e >> y;
    if (e == 0) {
        if (y < 1868 + 44) {
            cout << "M" << y - 1868 + 1 << endl;
        } else if (y < 1868 + 44 + 14) {
            cout << "T" << y - (1868 + 44) + 1 << endl;
        } else if (y < 1868 + 44 + 14 + 63) {
            cout << "S" << y - (1868 + 44 + 14) + 1 << endl;
        } else {
            cout << "H" << y - (1868 + 44 + 14 + 63) + 1 << endl;
        }
    } else if (e == 1) {
        cout << 1868 + y - 1 << endl;
    } else if (e == 2) {
        cout << 1868 + 44 + y - 1 << endl;
    } else if (e == 3) {
        cout << 1868 + 44 + 14 + y - 1 << endl;
    } else {
        cout << 1868 + 44 + 14 + 63 + y - 1 << endl;
    }
}



Measured memory_bytes: 3200
//#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<vector>
using namespace std;
const int INF= 1e8;

int main(){
	
	int n,m,k;
	cin>>n>>m>>k;
	vector<int> c(n);
	vector<vector<int>> a(n,vector<int>(m));
	for(int i=0;i<n;i++){
		cin>>c[i];
		for(int j=0;j<m;j++) cin>>a[i][j];
	}
	int ret =INF;
	for(int i=1;i<(1<<n);i++){
		int cost = 0;
		vector<int> temp(n);
		for(int j=0;j<n;j++){
			if(i&(1<<j)){
				cost+= c[j];
				for(int k=0;k<m;k++) temp[k]+=a[j][k];
			}
		}
		bool found = true;
		for(int j=0;j<m;j++){
			if(temp[j]<k){
				found = false;
				break;
			}
		}
		if(found) ret = min(ret,cost);
	}
	if(ret == INF) cout<<-1<<endl;
	else cout<<ret<<endl;

	return 0;
}



Measured memory_bytes: 3176
#include<iostream>
#include<vector>


using namespace std;

int main(){
    int n,m;
    cin >> n >> m;
    std::vector<int> a(m,0),b(m,0),c(n,0);
    for(int i = 0; i < m; i++){
        cin >> a[i] >> b[i];
        c[a[i]-1]++;
        c[b[i]-1]++;
    }
    
    for(int j = 0; j < n; j++){
        cout << c[j] << endl;
    }

}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a) for (int i = 0; i < (a); ++i)
#define pb push_back
#define all(v) v.begin(),v.end()
#define sort_1(v) sort(v.begin(),v.end())
#define sort_2(v) sort(v.begin(),v.end(),greater<ll>())
typedef long long ll;
typedef long double la;
using namespace std;

int main(){
  ll n;
  cin >> n;
  vector<string> s(n);
  map<string, int> m;
  rep(i,n){
    cin >> s[i];
    m[s[i]] = 0;
  }
  cout << m.size() << endl;

}

Measured memory_bytes: 24992
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <climits>
using namespace std;
#define MOD int(1e9 + 7)
#define INF (long long)(1e18)

int main()
{
    cout.precision(18);

    long long X, Y, A, B, C;
    vector<long long> P, Q, R;

    cin >> X >> Y >> A >> B >> C;
    for (long long i = 0; i < A; i++)
    {
        long long t;
        cin >> t;
        P.push_back(t);
    }
    for (long long i = 0; i < B; i++)
    {
        long long t;
        cin >> t;
        Q.push_back(t);
    }
    for (long long i = 0; i < C; i++)
    {
        long long t;
        cin >> t;
        R.push_back(t);
    }

    sort(P.begin(), P.end(), [](long long &a, long long &b) { return a > b; });
    sort(Q.begin(), Q.end(), [](long long &a, long long &b) { return a > b; });
    sort(R.begin(), R.end(), [](long long &a, long long &b) { return a > b; });

    vector<long long> v;
    for (long long i = 0; i < X; i++)
        v.push_back(P[i]);
    for (long long i = 0; i < Y; i++)
        v.push_back(Q[i]);
    for (long long i = 0; i < C; i++)
        v.push_back(R[i]);

    sort(v.begin(), v.end(), [](long long &a, long long &b) { return a > b; });

    long long t = 0;
    for (long long i = 0; i < X + Y; i++)
        t += v[i];

    cout << t << endl;
}

Measured memory_bytes: 8560
/*
Author : Vidish Joshi
*/

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

//#include<boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;

#define ll long long int
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define mod 1000000007
#define FOR1(i, m, n) for(i=m; i<n; i++)
#define FOR2(i, n, m) for(i=n-1; i>=m; i--)
#define v(v) ll v; cin>>v
#define mod 1000000007
#define mod2 998244353
#define mp make_pair
#define pb push_back
#define fill(a) memset(a, 0, sizeof(a))
#define start ll t; cin>>t; while(t--)

void re() {}
template <typename T, typename... args>
void re(T &x, args &... tail)
{
    cin >> x;
    re(tail...);
}
void pr() {}
template <typename T>
void pr(const T &x)
{
    cout << x;
}
template <typename T, typename... args>
void pr(const T &x, const args &... tail)
{
    cout << x << " ";
    pr(tail...);
}
template <typename... args>
void prln(const args &... tail)
{
    pr(tail...);
    cout << "\n";
}


int main(){
	FIO;
	int n, m;
	cin>>n>>m;
	if(n==m){
		cout<<"Yes\n";
	}
	else{
		cout<<"No\n";
	}


	return 0;
}


Measured memory_bytes: 256
v,e=map(int,raw_input().split())
dist=[[float("inf")]*v for _ in xrange(v)]
for i in xrange(e):
    s,t,d=map(int,raw_input().split())
    dist[s][t]=d

dp=[[float('inf')]*(v) for _ in xrange(1<<v)]
dp[1][0]=0
for i in xrange(1<<v):
    for j in xrange(v):
        if dp[i][j]==float('inf'):continue
        for k in xrange(v):
            if not (i>>k)&1:
                nexti=i|1<<k
                nextdist=dp[i][j]+dist[j][k]
                dp[nexti][k]=min(dp[nexti][k],nextdist)

ans=float('inf')
for i in xrange(v):
    if dp[(1<<v)-1][i]==float('inf'):continue
    ans=min(ans,dp[(1<<v)-1][i]+dist[i][0])
if ans==float('inf'):
    print(-1)
else:
    print(ans)

Measured memory_bytes: 16360
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
#define loop(i,a,b) for(int i = a; i < b; i++)
#define rep(i,a) loop(i,0,a)


int main()
{	
	int n;
	string s,t;
	int cnt=0;
	int max = 0;
	
	cin>>n;
	cin>>s;
	cin>>t;
	
	rep(i,n){
		if(s[i] == t[0]){
			cnt=0;
			rep(j,n-i){
				if(s[i+j] == t[j])
					cnt++;
				else
					break;
			}
		}
		if(max < cnt)
			max = cnt;
			
	}
	
	cout<<n*2-max<<endl;



}

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

int main(){
    int n, z, w;
    cin >> n >> z >> w;
    int a[n];
    for(int i = 0; i < n; i++)  cin >> a[i];
    if(n == 1)  cout << abs(a[0]-w);
    else        cout << max(abs(a[n-1]-w), abs(a[n-2]-a[n-1])) << endl;
    return 0;
}

Measured memory_bytes: 256
/*  ex5_3
    kosaq       */

#include <stdio.h>

int main(void){
    int height, width;//H行W列をそれぞれ定義
    scanf("%d %d", &height, &width);//H,Wを入力

    char square[100][100];//H,Wの上限は100なので二次元配列をそれぞれ要素数100で定義

    for(int i = 0; i < height; i++){
        for(int j = 0; j < width; j++){//二重ループにして行列を網羅する
            scanf(" %c", &square[i][j]);//1行ずつ入力する
        }
    }

    int row[100] = {0};//行に黒が１つでもある時に使うよう定義
    int column[100] = {0};//列に黒が１つでもある時に使うよう定義

    //ここから、各行について中でjをループさせ一つずつ黒があるか確認する。黒があった時には先程定義した配列rowに１を代入する。
    for(int i = 0; i < height; i++){
        for(int j = 0; j < width; j++){
            if(square[i][j] == '#'){
                row[i] = 1;
                break;
            }
        }
    }

    //ここから、各列について中でiをループさせ一つずつ黒があるか確認する。黒があった時には先程定義した配列columnに１を代入する。
    for(int j = 0; j < width; j++){
        for(int i = 0; i < height; i++){
            if(square[i][j] == '#'){
                column[j] = 1;
                break;
            }
        }
    }

    //最後に黒が１つでも存在した行、列について書き出す。
    for(int i = 0; i < height; i++){
        for(int j = 0; j < width; j++){
            if(row[i] == 1 && column[j] == 1){
                printf("%c", square[i][j]);
            }
        }
        printf("\n");//各行を書くごとに改行する
    }

    return 0;
}

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

int main() {
	int h1, h2, m1, m2, k;
	cin >> h1 >> m1 >> h2 >> m2 >> k;
	cout << ((h2 - h1) * 60 + m2 - m1) - k << endl;
	return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i, z, n) for(int i = z; i < n; i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
//const int INF = 1<<29;
//const int MODINF = 1000000007;
using namespace std;

int main(){
    int N, D, X;
    cin >> N >> D >> X;
    vector<int> A(N);
    rep(i, 0, N) cin >> A.at(i);
    rep(i, 0, N){
        X += (D - 1)/A.at(i) + 1;
    }
    cout << X << endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <stdio.h>
#include <string.h>
using ll = long long;

//LLONG_MAX
#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define LOWER_BOUND(v,a) (lower_bound((v).begin(), (v).end(), (a)))
#define UPPER_BOUND(v,a) (upper_bound((v).begin(), (v).end(), (a)))
#define REP(i, n) for (int (i)=0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()

using namespace std;

int _dp0[101][4];
int _dp1[101][4];

char cN[110];
int N[110];
int K;

signed main()
{
	cin >> cN;
	cin >> K;
	int len = strlen(cN);
	REP(i, len) N[i] = cN[i] - '0';

	_dp0[0][1] = 1;
	_dp1[0][1] = N[0] - 1;
	_dp1[0][0] = 1;

	for (int i = 1; i < len; i++)
	{
		for (int j = 1; j <= 3; j++)
		{
			if (N[i] == 0)
			{
				_dp0[i][j] = _dp0[i - 1][j];
			}
			else
			{
				_dp0[i][j + 1] = _dp0[i - 1][j];

				_dp1[i][j] += _dp0[i - 1][j];
				if (j < 3)
				{
					_dp1[i][j + 1] += (N[i] - 1) * _dp0[i - 1][j];
				}
			}
		}

		for (int j = 0; j <= 3; j++)
		{
			_dp1[i][j] += _dp1[i - 1][j];
			if (j > 0)
			{
				_dp1[i][j] += _dp1[i - 1][j - 1] * 9;
			}
		}
	}

	int ans = _dp0[len - 1][K] + _dp1[len - 1][K];
	cout << ans << endl;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
using namespace std;

typedef long long ll;
typedef double db;
typedef long double ldb;

template<class T> inline void checkmin(T &a,const T &b){if(b<a) a=b;}
template<class T> inline void checkmax(T &a,const T &b){if(b>a) a=b;}

ll a,b,c,d;
map<ll,ll> dp;

ll as(ll val){
	return val<0?-val:val;
}

ll solve(ll x) {
    if(x<=1) return d*x;
    if(dp.count(x)) return dp[x];
    ll v2l=(x/2)*2,v2r=((x+1)/2)*2,v3l=(x/3)*3,v3r=((x+2)/3)*3,v5l=(x/5)*5,v5r=((x+4)/5)*5;
    ll val=1e18;
    if(x<val/d) val=x*d;
    val=min(val,a+solve(v2l/2)+as(x-v2l)*d);
    val=min(val,a+solve(v2r/2)+as(x-v2r)*d);
    val=min(val,b+solve(v3l/3)+as(x-v3l)*d);
    val=min(val,b+solve(v3r/3)+as(x-v3r)*d);
	val=min(val,c+solve(v5l/5)+as(x-v5l)*d);
    val=min(val,c+solve(v5r/5)+as(x-v5r)*d);
//  cout<<x<<" "<<val<<endl;
    return dp[x]=val;
}

int main() {
    int t;
    cin>>t;
    for (int test=0;test<t;test++) {
        ll x;
        cin>>x>>a>>b>>c>>d; 
		dp.clear();
        cout<<ll(solve(x))<<"\n";
    }
}


Measured memory_bytes: 4468
#include<stdio.h>
int main()
{
	int cost;
	int seven;
	scanf("%d", &cost);
	if (cost<4)
	{
		printf("No");
		return 0;
	}
	for (seven = 0; seven * 7 <= cost; seven++)
	{
		if ((cost - 7 * seven) % 4 == 0)
		{
			printf("Yes");
			return 0;
		}
	}
	printf("No");
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //GCC5.4.1で配列の範囲外アクセスをエラーにする

//cmdで g++ test.cpp とするとコンパイルできる
//制限1秒なら10^6は余裕 10^7は多分間に合う 10^8はよほど単純でないと厳しい
// https://github.com/atcoder/live_library
// cppdbg: test.exeのterminalに標準入力を打てる

#define ALL(x) x.begin(),x.end()
#define get_tp(t,i) get<i>(t)
#define len(x) (ll)(x.size())
#define ub(a,x) (upper_bound(ALL(a),x)-a.begin())
#define lb(a,x) (lower_bound(ALL(a),x)-a.begin())
typedef long long ll; //long long
typedef pair<int,int> pii; //pair<int,int>
typedef pair<long long,long long> pllll; //pair<ll,ll>
typedef vector<int> vi; //vector<int>
typedef vector<vector<int>> vvi; //vector<vector<int>>
typedef vector<ll> vll; //vector<long long>
typedef vector<vector<ll>> vvll; //vector<vector<long long>>
typedef priority_queue<ll, vector<ll>, greater<ll> > gpq; //逆順priority_queue
typedef priority_queue<ll> pq;

//const int MOD=998244353;
const int MOD=1000000007; //10^9+7
const long double PI=3.1415926535897932;

int main(){
    int N;cin>>N;
    cout<<N*(N+1)/2<<endl;
}

Measured memory_bytes: 3576
import functools

import os

INF = float('inf')


def inp():
    return int(input())


def inpf():
    return float(input())


def inps():
    return input()


def inl():
    return list(map(int, input().split()))


def inlf():
    return list(map(float, input().split()))


def inls():
    return input().split()


def debug(fn):
    if not os.getenv('LOCAL'):
        return fn

    @functools.wraps(fn)
    def wrapper(*args, **kwargs):
        print('DEBUG: {}({}) -> '.format(
            fn.__name__,
            ', '.join(
                list(map(str, args)) +
                ['{}={}'.format(k, str(v)) for k, v in kwargs.items()]
            )
        ), end='')
        ret = fn(*args, **kwargs)
        print(ret)
        return ret

    return wrapper

a, b = inl()
print(max(a+b, a-b, a*b))

Measured memory_bytes: 3572