akhauriyash/Code-Regression huggingface dataset:
from datetime import date,timedelta
a=date(2012,12,21)
while 1:
    try:s=list(map(int,input().split('.')))
    except:break
    d=0
    if len(s)<4:    
        while s[0]>3000:d+=365*400+97;s[0]-=400
        d+=(date(s[0],s[1],s[2])-a).days
        d,k=divmod(d,20)
        d,w=divmod(d,18)
        d,t=divmod(d,20)
        d,_k=divmod(d,20)
        d%=13
        print('.'.join(map(str,[d,_k,t,w,k])))
    else:
        for i in range(len(s)-1):
            d+=s[i]
            d*=18 if i==2 else 20
        d+=s[4]
        d=a+timedelta(days=d)
        print('.'.join(map(str,[d.year,d.month,d.day])))

Measured memory_bytes: 8112
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string>
using namespace std;

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

void insertSort(int A[], int N) {
	int j, i, v;
	for (int i = 1; i < N; i++) {
		v = A[i];
		j = i - 1;
		while (j >= 0 && A[j] > v) {
			A[j + 1] = A[j];
			j--;
		}
		A[j + 1] = v;
		trace(A, N);
	}
}
int main() {
	int j, i, N;
	int A[100];

	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	trace(A, N);
	insertSort(A, N);
}

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

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

    int n;
    cin >> n;
    vector<long long> A(n + 1), B(n);
    for(int i = 0; i < n + 1; i++){
        cin >> A[i];
    }
    for(int i = 0; i < n; i++){
        cin >> B[i];
    }

    long long ans = 0, bef = 0;
    for(int i = 0; i < n; i++){
        // ans += max(A[i], B[i]);
        if(A[i] >= B[i]){
            ans += B[i];
            B[i] = 0;
        }else{
            ans += A[i];
            B[i] -= A[i];
        }

        if(A[i + 1] >= B[i]){
            ans += B[i];
            A[i + 1] -= B[i];
        }else{
            ans += A[i + 1];
            A[i + 1] = 0;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
typedef long long ll;
typedef double dd;
#define pb push_back
#define mp make_pair
#define endl "\n"
ll const M = 1000000007;
dd const pi = acos(-1);
ll const inf = 2e18;
ll const N = 200001;
int main()
{
    fast;
    ll i,j,t,no,n,x;
    cin >> x >> n;
    vector<bool> visited(102,false);
    for(i = 0; i < n; i++)
    {
    	cin >> no;
    	visited[no] = true;
    }
    i = j = x;
    while(visited[i] && visited[j])
    	i--,j++;
    if(!visited[i])
    	cout<<i<<endl;
    else
    	cout<<j<<endl;
    return 0;
}    

Measured memory_bytes: 3616
// Template from https://techracho.bpsinc.jp/jhonda/2019_08_05/78537

// input macro for competive-programming from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };

    ($iter:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, bytes) => {
        read_value!($iter, String).into_bytes()
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    use std::io::Read;
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();

    println!("{}", solve(&s));
}

macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input), $output);
            )*
        }
    };
}

test! {
r#"3
2 3 1"# => r#"3 1 2"#,
}

fn solve(src: &str) -> String {
    input! {
        source = src,
        n: usize,
        a: [usize; n],
    }

    let mut an:Vec<(usize, &usize)> = a.iter().enumerate().collect();

    an.sort_by(|a, b| a.1.partial_cmp(b.1).unwrap());

    let mut ans = "".to_string();
    for i in 0..n {
        ans.push_str(&(an[i].0 + 1).to_string());
        if i != n - 1 {
            ans.push_str(&" ".to_string());
        }
    }

    ans.to_string()
}

Measured memory_bytes: 10492
#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 <tuple>
#include <deque>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <utility>
#include <complex>
#include <functional>
using namespace std;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
int n;
vector<int> w;
vector<ll> v;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll W;
    cin >> n>>W;
    for (int i = 0; i < n; i++)
    {
        int tempw;
        ll tempv;
        cin >> tempw>>tempv;
        w.push_back(tempw);
        v.push_back(tempv);
    }
    ll dp[n+1][W+1];
    for(int j=0;j<=W;j++){
        dp[0][j]=0;
    }
    for(int i=1;i<=n;i++){
        for(int j=0;j<=W;j++){
            if(j-w[i-1]>=0){
                dp[i][j]=max(dp[i-1][j],dp[i-1][j-w[i-1]]+v[i-1]);
            }
            else{
                dp[i][j]=dp[i-1][j];
            }
        }
    }
    ll ans=0;
    for(int i=0;i<=W;i++){
        ans=max(ans,dp[n][i]);
    }
    cout <<  ans<< "\n";
}


Measured memory_bytes: 79232
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &&x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define INSEG(l,x,r) ((l)<=(x)&&(x)<(r))
#define dump(...)
#define pb push_back
#define _ 0
const signed INF_=1001001001; const long long INF=1001001001001001001LL;
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v))os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T, class U> bool chmax(T &a,const U &b){return a<b?a=b,1:0;}
template<class T, class U> bool chmin(T &a,const U &b){return a>b?a=b,1:0;}
template <class T> void PSUM(T& c) {partial_sum(begin(c), end(c), begin(c));}
template<class T> using heap=priority_queue<T,vector<T>,greater<T>>;
struct before_main_function {
    before_main_function() {
        cin.tie(0); ios::sync_with_stdio(false);
        cout << setprecision(15) << fixed;
        // #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    int N, A, B;
    cin >> N >> A >> B;
    vector<int> P(N);
    cin >> P;
    sort(ALL(P));
    int x = 0, y = 0, z = 0;
    FORE(d, P) {
        if (d <= A) x++;
        else if (A + 1 <= d && d <= B) y++;
        else z++;
    }
    cout << min({x, y, z}) << endl;
    return (0^_^0);
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
bool can;

int dfs(const Graph &G, int v, vector<bool> &seen)
{
    bool can = true;
    for (auto t : seen)
    {
        if (!t)
            can = false;
    }
    if (can)
        return 1;

    int ans = 0;
    for (auto t : G[v])
    {
        if (seen[t])
            continue;
        seen[t] = true;
        ans += dfs(G, t, seen);
        seen[t] = false;
    }
    return ans;
}

int main()
{
    int n, m; //頂点、辺
    cin >> n >> m;
    Graph G(n);
    vector<bool> seen(n, false);
    for (int i = 0; i < m; i++)
    {
        int a, b;
        cin >> a >> b;
        a--, b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    seen[0] = true;

    cout << dfs(G, 0, seen) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1000000007;
const ld PI = acos(-1);  
const ld EPS = 0.0000000001;


int main(){
    int n;
    string s;   cin >> n >> s;
    ll bc=0, wc=0;
    for(int i=0; i<s.size(); i++){
        if(s[i]=='#') bc += 1;
        else wc += 1;
    }
    ll ans=bc;
    bc = 0;
    for(int i=0; i<n; i++){
        ans = min(ans, bc+wc);
        if(s[i]=='#') bc += 1;
        else wc -= 1;
    }
    
 
    cout << ans << endl;
}



Measured memory_bytes: 640
#include <stdio.h>

int main(){

  /*
  1 selectionSort(A, N) // N個の要素を含む0-オリジンの配列A
2   for i が 0 から N-1 まで
3     minj = i
4     for j が i から N-1 まで
5       if A[j] < A[minj]
6         minj = j
7     A[i] と A[minj] を交換
  */

  int n ,i, min ,j,c=0;
  scanf("%d" ,&n);
  int arr[n];
  for ( i = 0; i < n; i++){
    scanf("%d",&arr[i]);
  }

  for ( i = 0; i < n ;i++){
    min = i;
    for ( j = i; j < n; j++){
      if ( arr[j] < arr[min]){ min = j;}
    }
    if ( arr [i] != arr[min] ){
      c++;
    j = arr[i]; arr[i] = arr [min]; arr[min] = j;
    }
  }

  for ( i = 0; i < n; i++){
    printf("%d",arr[i]);
    if ( i == n-1){printf("\n%d\n",c);}
    else {printf(" ");}
  }
  
  return 0;
}



Measured memory_bytes: 2140
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <queue>
#include <stack>

using namespace std;

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

const ll mod = 1000000007;

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

  ll h;
  cin >> h;

  ll now = h;
  ll count = 1;
  ll ans = 0;
  while (now > 0) {
    ans += count;
    count *= 2;
    now /= 2;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <queue>
#include <cmath>
#include <vector>
#include <algorithm>

using namespace std;
/*
long long cnt[1000005];
void init()
{
    memset(cnt, 0, sizeof(cnt));
    for(int i = 1; i <= 1000; ++i)
        for(int j = 1; j <= 1000; ++j)
            ++cnt[i*i+j*j];
}
int main()
{
   // init();
    int a, b;
    cin >> a >> b;
    pair<int, int> pointA[1010], pointB[1010];

    int pos1 = 0, pos2 = 0;
    for(int i = 1; i <= 1000; ++i)
        for(int j = 1; j <= 1000; ++j)
        {
            if(i*i+j*j==a*a) {pointA[pos1].first = i;pointA[pos1++].second = j;}
            if(i*i+j*j==b*b) {pointB[pos2].first = -i;pointB[pos2++].second = j;}
        }
    for(int i = 0; i < pos1; ++i)
        for(int j = 0; j < pos2; ++j)
        {
            if(pointA[i].first*pointB[j].first + pointA[i].second*pointB[j].second == 0 && pointA[i].second!= pointB[j].second)
            {
                printf("YES\n");
                printf("0 0\n%d %d\n%d %d\n",pointA[i].first,pointA[i].second,pointB[j].first,pointB[j].second);
                return 0;
            }
        }

    cout << "NO" << endl;
    return 0;
}
*/
/*
bool check(long long x)
{
    x = abs(x);

    while(x > 0 && x <= 8888888888)
    {
        //cout << "abs "<< x << endl;
        long long temp = x%10;
        if(temp == 8) return true;
        x /= 10;
    }
    return false;
}
int main()
{
    long long a;
    while(cin >> a)
    {
        int pos = 0;
        for(int i = 1; i <= 20; ++i)
        {
            if(check(a+i))
            {
                pos = i; break;
            }
        }
        cout << pos << endl;
    }
}*/

int main()
{
    char s[10];
    int num[4];
    scanf(" %s", s);
    for(int i = 0; i < 4; ++i)
        num[i] = s[i]-'0';
    int re = 0;
    for(int i = 0; i < 2; ++i)
        for(int j = 0; j < 2; ++j)
            for(int k = 0; k < 2; ++k){

                re = num[0];
                if(i == 0) re += num[1];
                else re -= num[1];

                if(j == 0) re += num[2];
                else re -= num[2];

                if(k == 0) re += num[3];
                else re -= num[3];

                if(re == 7)
                {
                    cout << num[0] << (i?'-':'+') << num[1] << (j?'-':'+') << num[2] << (k?'-':'+') << num[3] << "=7" << endl;
                    return 0;
                }
            }

}


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

int main(){
    int N, M;
    cin >> N >> M;
    string S;
    cin >> S;
  
    int count = N;
    int res[N + 1];
    int res2 = 0;
  
    while (true){
        int a = count;
        for(int i = M; i >= 1; i--){
            if(count < i) continue;
            if(S[count - i] == '0') {
                count -= i;
                res[res2] = i;
                res2++;
                break;
            }
        }
        if (a == count){
            res2 = -1;
            break;
        }
        if (count == 0) break;
    }
  
    if (res2 == -1) cout << res2;
    for (int i = res2 - 1; i >= 0; i--){
        cout << res[i] << ' ';
    }
    cout << endl;
}

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

int main(){
	int h,w;
	while(1){
		cin>>h>>w;
		if(h==0&&w==0) return 0;
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				cout<<'#';
			}
			cout<<endl;
		}
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 3068
#include<cstdio>
#include<vector>
#include<queue>
#include<utility>
#define INF (1<<30)
using namespace std;

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

bool canmove(int x,int y){
  return (0 <= x && x < w && 0 <= y && y < h);  
}

int main(){
  scanf("%d %d %d",&h,&w,&n);
  (void)getchar();
  vector<int> data(n+1);
  vector<vector<char> > map(h,vector<char>(w));

  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      scanf("%c",&map[i][j]);
      if(map[i][j]=='S') map[i][j]='0';
      if('0' <= map[i][j] && map[i][j] <= '9') data[map[i][j]-'0']=i*2048+j;
    }
    (void)getchar();
  }
  
  vector<vector<int> > cost(n+1,vector<int>(n+1,0));
  for(int i=0;i<=n;i++){
    queue<pair<int,int> > q;
    pair<int,int> pii;
    vector<vector<int> > temp(h,vector<int>(w,-1));
    q.push(make_pair(data[i],0));
    while(!q.empty()){
      pii=q.front();
      int y=pii.first/2048;
      int x=pii.first%2048;
      q.pop();
      if(temp[y][x] != -1) continue;
      temp[y][x]=pii.second;

      for(int k=0;k<4;k++){
	if(canmove(x+dx[k],y+dy[k]) && map[y+dy[k]][x+dx[k]]!='X'){
	  q.push(make_pair((y+dy[k])*2048+x+dx[k],pii.second+1));
	}
      }
    }
    for(int j=0;j<=n;j++){
      cost[i][j]=temp[data[j]/2048][data[j]%2048];
    }
  }

  int _m=0;
  for(int i=0;i<n;i++){
    _m += cost[i+1][i];
  }
  printf("%d\n",_m);
  return 0;
}

Measured memory_bytes: 5844
N = int(input())
S = list(input())
S = list(map(lambda x: int(x), S))

ans = 0

for i in range(10):
  for j in range(10):
    for k in range(10):
      if i in S:
        a = S.index(i)
        if j in S[a+1:]:
          b = S[a+1:].index(j) + a + 1
          if k in S[b+1:]:
            ans += 1
          else:
            continue
        else:
          continue
      else:
        continue

print(ans)


Measured memory_bytes: 167840
#include<map>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#define LL long long
using namespace std;
LL A[200020],sum[200020],N;
map <LL ,int > MP;
int main()
{
	int i,j,k;
	LL ans=0;
	scanf("%d",&N);
	for(i=1;i<=N;i++)	scanf("%lld",&A[i]),sum[i]=sum[i-1]+A[i];
	for(i=0;i<=N;i++){
		
		ans+=MP[sum[i]];
		MP[sum[i]]++;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 15872
#include <bits/stdc++.h>
typedef long long int lli;
using namespace std;
#pragma region DEBUG
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
#pragma endregion DEBUG
#define MOD 1000000007
#define MAX 5000005
#define endl "\n"
lli arr[MAX];
int st[MAX];
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);    
    lli t;
    t = 1;
    while(t--){
        lli n;
        cin>>n;
        string s;
        cin>>s;
        lli r = 0;
        for(lli i = 0; i<n; i++)
            if(s[i] == 'R')
                r++;
        lli ans = 0;
        for(lli i = 0; i<r; i++){
            if(s[i] == 'W')
                ans++;
        }
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 3780
#include <iostream>
#include <map>
#include <string>
using namespace std;

int main(){
  map<string, int> card;
  int N,M;
  cin >> N;
  string name;
  for(int i = 0; i < N; i++){
    cin >> name;
    card[name]++;
  }
  cin >> M;
  for(int i = 0; i < M; i++){
    cin >> name;
    card[name]--;
  }
  int max = 0;
  for(auto ans: card){
    if(max < ans.second) max = ans.second;
  }

  if(max > 0) printf("%d",max);
  else printf("%d",0);


}


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

int main()
{
    long long int a=0;
    long long int e=0;
    long long int n=0;
    long long int k=0;
    long long int m=0;
    long long int j=0;
    long long int c=0;
    long long int d=0;
    long long int b=0;
    cin>>a;
    cin>>b;
    cin>>c;
    cin>>n;
    cin>>m;
    e=min(n,m);
    j=2*c*max(n,m);
    k=e*2*c;
    if(n-m>0)
    {
        k=k+(n-m)*a;
    }
    else
    {
        k=k+(m-n)*b;
    }
    e=a*n+b*m;
    if(k<e && k<j)
    {
        cout<<k;
    }
    else if(e<k && e<j)
    {
        cout<<e;
    }
    else
    {
        cout<<j;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <bitset>
using namespace std;

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int H, W;
	cin >> H >> W;
  	vector<vector<string>> A(H+2, vector<string>(W+2));
  	struct pos
    {
      int x;
      int y;
    };
  	vector<pos> black;
  	int row = 0;
  	int col = 0;
  	//cerr << H << ":" << W << endl;
  	string str;
  	// 黒: '#' 白: '.'
  	while(cin >> str)
    {
      for(int i=0;i<W;i++)
      {
        A[col+1][i+1] = str[i];
        //cerr << A[col][i] << " ";
        if(A[col+1][i+1] == "#")
        {
          //cerr << col << ":" << i << endl;
          pos p = {col+1, i+1};
          black.push_back(p);
        }
      }
      //cerr << endl;
      col++;
    }
  	//各マスの黒からの距離が求まったらその最大値を計算する
  	//全ての白マスについて計算すると最大 (1000*1000)^2 ?
  	//簡単に求める方法があるはず
    //黒色の場所(X,Y)を知っていれば白の場所(x,y)の距離(abs(X-x)+abs(Y-y))が求まる
  	//どれと比べたらよい？全部？間に合う？　→　全部だと間に合わない
  	//cerr << black.size() << endl;
  	/* 白を見る必要がない？
  	int max_distance = 0;
  	int distance,minimum_distance2black;
	int prev_index=-1;
  	for(int col=0;col<H;col++)
    {
      for(int row=0;row<W;row++)
      {
        if(A[col][row] == "#") continue;
        //前回比較した黒を記憶しておく？その時の黒より距離が離れたら最短の黒を探索？
        //それでも間に合わない。　→　なんらかの基準でsortするべきか
        if(prev_index != -1)
        {
          distance=abs(black[prev_index].x-col) + abs(black[prev_index].y-row);
          if(max_distance > distance) continue;
        }
        minimum_distance2black = H+W;
        for(int i=0;i<black.size();i++)
        {
          distance=abs(black[i].x-col) + abs(black[i].y-row);
          if(minimum_distance2black > distance)
          {
            prev_index = i;
            minimum_distance2black = distance;
          }
        }
        if(max_distance < minimum_distance2black) max_distance = minimum_distance2black;
        
      }
    }
    
 	cout << max_distance << endl;
    */
  	int t= 0;
  	int dx[]={-1,0,1,0},dy[]={0,-1,0,1};
  	while(!black.empty())
	{
		int len=black.size();
		t++;
		for(int i=0;i<len;i++)
		{
			pos p=black[i];
			for(int d=0;d<4;d++)
			{
				int xx=p.x+dx[d],yy=p.y+dy[d];
				if(A[xx][yy]==".")
                {
                  	pos new_p = {xx, yy};
					black.push_back(new_p);
                }
				A[xx][yy]="#";
			}
		}
      	black.erase(black.begin(), black.begin()+len);
	}
	cout<<t-1;
	return 0;
}


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

int main()
{
	int h,m,s;
	while(cin >> h >> m >> s){
		if(h<0 && m<0 && s<0)
			break;
		int tape = 7200;
		tape = tape - h*3600;
		tape = tape - m*60;
		tape = tape - s;

		int tmp = tape;
		h = tape/3600;
		tape = tape%3600;
		m = tape/60;
		tape = tape%60;
		s = tape;
		if(h<10)
			cout << 0;
		cout << h << ":";
		if(m<10)
			cout << 0;
		cout << m << ":";
		if(s<10)
			cout << 0;
		cout << s << endl;

		tape = tmp*3;
		h = tape/3600;
		tape = tape%3600;
		m = tape/60;
		tape = tape%60;
		s = tape;
		if(h<10)
			cout << 0;
		cout << h << ":";
		if(m<10)
			cout << 0;
		cout << m << ":";
		if(s<10)
			cout << 0;
		cout << s << endl;
	}
	return 0;
}

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

    divisors.sort()
    return divisors

import math

def trial_division(target):
    dest = int(math.sqrt(target)) + 1

    for i in range(2, dest):
        if target % i == 0:
            return 0
    return 1

a, b = map(int, input().split())

a_set = set(make_divisors(a))
b_set = set(make_divisors(b))

ab_set = a_set & b_set

c = 0
for ab in list(ab_set):
    c += trial_division(ab)

print(c)

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


int main(void){
	int count;
	while(cin >> count){
		if (count == 0) break;
		else{

		int da[3];
		da[0] =1,da[1] =2,da[2] = 3;
		int ans=1,b=0;
		string str;
		int i;
			for(i=0;i<count;i++){
				cin >> str;
				if(str == "North"){
					b = da[1];
					da[1] = 7-da[0];
					da[0] = b;
					ans += da[0];
				}
				if(str == "East"){
					b = da[2];
					da[2] = da[0];
					da[0] = 7-b;
					ans += da[0];
				}
				if(str == "West"){
					b = da[0];
					da[0] = da[2];
					da[2] = 7-b;
					ans += da[0];
				}
				if(str == "South"){
					b = da[1];
					da[1] = da[0];
					da[0] = 7-b;
					ans += da[0];
				}
				if(str == "Right"){
					b = da[1];
					da[1] =da[2];
					da[2] = 7-b;
					ans += da[0];
				}
				if(str == "Left"){
					b = da[1];
					da[1] = 7-da[2];
					da[2] = b;
					ans += da[0];
				}
			}cout << ans << endl;
		}
       }
}

Measured memory_bytes: 1212
#include<bits/stdc++.h>
#define MAX_N 100001
#define INF_INT 2147483647
#define INF_LL 9223372036854775807
#define REP(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
void init(int n);
int find(int n);
void unite(int x,int y);
bool same(int x, int y);
ll bpow(ll,ll,ll);
typedef vector<int> vec;
typedef vector<vec> mat;
mat mul(mat &A,mat &B);
mat pow(mat A,ll n);
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
const int MOD = 1000000007;

bool cmp_P(const P &a,const P &b){
  return a.second < b.second;
}
ll dp[41][404][404];
int main()
{
  ll N,Ma,Mb,a[50],b[50],c[50],res=INF_INT;
  cin >> N >> Ma >> Mb;
  REP(i,N)cin >> a[i] >> b[i] >> c[i];
  REP(i,41)REP(j,401)REP(k,401)dp[i][j][k] = INF_INT;
  dp[0][0][0] = 0;
  REP(i,N)REP(j,401)REP(k,401){
    if(j-a[i] >= 0 && k-b[i] >= 0)
      dp[i+1][j][k] = min(min(dp[i+1][j][k],dp[i][j][k]),dp[i][j-a[i]][k-b[i]] + c[i]);
    else
      dp[i+1][j][k] = min(dp[i+1][j][k],dp[i][j][k]);
  }
  for(int i=1;Ma*i <= 400 && Mb*i <= 400;i++){
    res = min(res,dp[N][Ma*i][Mb*i]);
  }
  cout << (res >= INF_INT ? -1 : res) << endl;
  return 0;
}



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

int main() {
  int M;
  cin >> M;
  int count = 0;
  
  for (int i = 1; i <= 9; i++) {
    for (int j = 1; j <= 9; j++) {
      if (i*j == M) {
        count++;
      }
    }
  }
  
  if (count == 0) {
    cout << "No" <<endl;
  }
  else {
    cout << "Yes" <<endl;
  }
  
  
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
int n,m,ans;
int a[201010];
bool br[202020];
int main()
{
	scanf("%d%d",&n,&m);
	for (int i=1;i<=n;++i)
		a[i]=1;
	br[1]=1;
	int x,y;
	for (int i=1;i<=m;++i)
	{
		scanf("%d %d",&x,&y);
		if (br[x]) br[y]=1;
		--a[x]; ++a[y];
		if (a[x]==0) br[x]=0;
	}
	for (int i=1;i<=n;++i)
		if (br[i]) ++ans;
	printf("%d\n",ans);
	return 0;
}

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

using namespace std;

int main(int argc, char *argv[])
{
	ios::sync_with_stdio(false); cin.tie(0);
	int n, m;
	cin >> n >> m;
	vector<int> h(n);
	for (int i = 0; i < n; i++) cin >> h[i];
	set<int> s, z;
	for (int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		if (h[b] > h[a]) swap(a, b);
		if (h[a] > h[b]) {
			if (z.count(a) == 0) s.insert(a);
			z.insert(b);
			if (s.count(b)) s.erase(b);
		} else if (h[a] == h[b]) {
			z.insert(a);
			z.insert(b);
			if (s.count(a)) s.erase(a);
			if (s.count(b)) s.erase(b);
		}
	}
	for (int i = 0; i < n; i++)
		if (z.count(i) == 0) s.insert(i);

	cout << s.size() << endl;

	return 0;
}


Measured memory_bytes: 8336
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define ll long long
#define MOD 1000000007
#define max(x,y) ((x)>(y)?(x):(y))
#define min(x,y) ((x)<(y)?(x):(y))
#define rep(i,n) for(i=0;i<n;i++)
int cmp(const void *a,const void*b){return *(int*)a-*(int*)b;}
int main(){
    int n,r;
    scanf("%d%d",&n,&r);
    int ans;
    if(n>=10){
        ans=r;
    }
    else{
        ans=r+100*(10-n);
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 128
s = input()

s1 = s[0:2]
s2 = s[2:4]
l = []

flg = 0
if 1 <= int(s1) <= 12:
    flg += 10

if 1<= int(s2) <= 12:
    flg += 1
    

if flg == 0:
    print('NA')
elif flg == 1:
    print('YYMM')
elif flg == 10:
    print('MMYY')
else:
    print('AMBIGUOUS')

Measured memory_bytes: 3064
// Last Change: 04/09/2019 22:59:05.
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

namespace NS {
void LoopUntilZeroInpput() {
  int hogegegege = 0;
  while (cin >> hogegegege && hogegegege != 0) {
  }
}
} // namespace NS

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

  int odd, even;
  even = K / 2;
  odd = K - even;

  cout << even * odd << endl;

  //NS::LoopUntilZeroInpput();
}


Measured memory_bytes: 256
a[181],m1[1000000],m2[1000000],T;
int s(p,n,c,f){
	int *m=p,d=180;
	if(!n)return 0;
	if(m[n]<1000000)return m[n];
	for(;d;d--){
		if(a[d]>n||(f&&!(a[d]&1)))continue;
		T=s(p,n-a[d],c+1,f)+1;
		if(m[n]>T)m[n]=T;
	}
	return m[n];
}

main(n){
	for(n=1;n<181;n++)a[n]=n*(n+1)*(n+2)/6;
	memset(m1,99,sizeof(m1));
	memset(m2,99,sizeof(m2));
	for(;scanf("%d",&n),n;)printf("%d %d\n",s(m1,n,0,0),s(m2,n,0,1));
	exit(0);
}

Measured memory_bytes: 8224
#include <stdio.h>
#include <math.h>
 
using namespace std;
 
int main(){
    double x1,y1,x2,y2;
    scanf("%lf %lf %lf %lf",&x1,&y1,&x2,&y2);
    printf("%.8lf\n",sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)));
}


Measured memory_bytes: 2764
#include <cstdio>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>

using namespace std;

int dp[65536][16];
int edge[16][16];
int sum[65536];
int n,m;

int main()
{
	scanf("%d%d",&n,&m);
	int Sum = 0;
	for(int i = 1;i <= m; ++ i)
	{
		int u,v,w; scanf("%d%d%d",&u,&v,&w);
		Sum += w; edge[u][v] = edge[v][u] = w;
	}
	int all = (1 << n) - 1;
	for(int i = 0;i <= all; ++ i)
		for(int j = 1;j <= n; ++ j)
			if(!(i & 1 << j - 1) && !(sum[i | 1 << j - 1]))
			{
				sum[i | 1 << j - 1] = sum[i];
				for(int k = 1;k <= n; ++ k)
					if(i & 1 << k - 1) sum[i | 1 << j - 1] += edge[j][k];
			}
	memset(dp,-1,sizeof(dp));
	dp[1][1] = 0;
	for(int i = 1;i <= all; ++ i)
		for(int j = 1;j <= n; ++ j)
			if(dp[i][j] != -1 && (i & 1 << j - 1))
			{
				for(int k = 1;k <= n; ++ k)
					if(!(i & 1 << k - 1) && edge[j][k])
						dp[i | 1 << k - 1][k] = max(dp[i | 1 << k - 1][k],dp[i][j] + edge[j][k]);
				int S = (all ^ i) | 1 << j - 1;
				for(int k = S;k;k = (k - 1) & S)
					if(k & 1 << j - 1)
						dp[i | k][j] = max(dp[i | k][j],dp[i][j] + sum[k]);
			}
	printf("%d\n",Sum - dp[all][n]);		
}

Measured memory_bytes: 4480
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(x) ((x).begin()),((x).end())
#define usecppio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
vector <pair <int, int>> v;
int main()
{
    int n; 
    cin >> n; 
    for (int i = 1; i<=n; i++)
    {
        int t;
        cin >> t;
        v.push_back({t, i});
    }
    sort(all(v));
    for (auto it:v)
    {
        cout << it.second << ' ';
    }
    cout << '\n';
}

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

int main()
{
    int N; cin>>N;
    for(int X=1;X<=N;X++){
        int t=X*1.08;
        if(t==N){
            cout<<X<<endl;
            return 0;
        }
    }
    cout<<":("<<endl;
    return 0;
}

Measured memory_bytes: 256
//int a = stoi(c); 文字列をintへ
//小文字から大文字
//transform(a.begin(), a.end(), a.begin(), ::toupper);
//途中の出力をそのまま残さない
//数値計算 個数以外はdouble
//map<キー,値> p は辞書。p[キー] = 値
//map 全探索
//auto begin = p.begin(), end = p.end();
//for (auto it = begin; it != end; it++) {}
//mapのキー：it->first mapのバリュー：it->second
//絶対値 abs()
//入力は空白で切れる
//大文字判定 isupper(文字) 小文字判定 islower(文字)
//do{}while(next_permutation(ALL(配列)))
//while(N)で回すとき、Nはコピーを作っておく
//小文字に対応する文字コード：S[i] - 'a'
//文字コード→小文字：(char)(数字+'a')
//グラフの距離:隣接行列で扱う
//等価なものに変換する思考
//bool型　初期値はTrue
//島渡りの問題：中間ノードに着目
//配列はvector<>を使う：意味わからないエラーがなくなる。
//背反な事象にちゃんとわける
//チェックリストはマップを使う
//数が大きい時の比較はstring型で行う
//全て0になったか調べたい->0になるたびにcntする
//またはかかつか
//例外処理は最初にする
//x = p^m + q^n...の約数の個数:(n+1)*(m+1)....
//N!のどの素因数で何回割れるか
//⇔1~Nまでの数がそれぞれどの素因数で何回割り切れるかの和
//パズルの問題->一般化して全探索
//数が大きい時のせぐふぉはコードテストで試してみる
//スペルミスに注意
//stack<ll> s;
//s.push(要素);s.top();s.pop();
//queue<ll> q;
//q.push(要素);q.front();q.pop();
//同じ作業繰り返す系の問題：収束先を見つける
//関係性は隣接行列で記録
//過半数：N/2.0で判定
//ある量からある量を引く系の問題：端から定義してやる
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N;i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
using namespace std;

//円周率
const double PI = 3.14159265358979323846;
//割るやつ
const ll MOD = (pow(10, 9) + 7);

// K進数でのNの桁数
ll dig(ll N, ll K) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= K;
	}
	return dig;
}
// a,bの最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}

//a,bの最小公倍数
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

//階乗計算
ll f(ll n) {
	if (n == 0 || n == 1) return 1;
	else return (n * f(n - 1));
}

//Nのd桁目の数
ll dignum(ll N, ll d) {
	ll x = pow(10, d);
	N %= x;
	ll y = pow(10, d - 1);
	N /= y;
	return N;
}

//Nをdで何回割れるか
ll divcnt(ll N, ll d) {
	ll ans = 0;
	while (1) {
		if (N%d == 0) {
			ans++;
			N /= d;
		}
		else break;
	}

	return ans;
}

//素数判定
bool prime(ll num) {
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false;
	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2) {
		if (num % i == 0) return false;
	}
	return true;
}

//フィボナッチ数列
vector<ll> memo(pow(10, 6) + 1);
ll fibo(ll n) {
	if (n == 1) return 1;
	else if (n == 2) return 1;
	else if (memo[n] != 0) return memo[n];
	else return memo[n] = fibo(n - 1) + f(n - 2);
}

int main() {
	vector<ll> a(3); rep(i, 3)cin >> a[i];

	ll o = 0, e = 0;
	rep(i, 3) {
		if (a[i] % 2 == 0) e++;
		else o++;
	}

	if (e == 3) {
		sort(ALL(a));
		cout << (2 * a[2] - a[1] - a[0])/2 << endl;
	}
	else if (e == 2) {
		rep(i, 3) if (a[i] % 2 == 0) a[i]++;
		sort(ALL(a));
		cout << (2 * a[2] - a[1] - a[0])/2 + 1<< endl;
	} 
	else if(e == 1){
		rep(i, 3) if (a[i] % 2 == 1) a[i]++;
		sort(ALL(a));
		cout << (2 * a[2] - a[1] - a[0])/2 + 1 << endl;
	}
	else {
		sort(ALL(a));
		cout << (2 * a[2] - a[1] - a[0])/2 << endl;
	}

	return 0;
}

Measured memory_bytes: 8064
#include <bits/stdc++.h>
#define range(i, l, r) for(int (i) = (l); (i) < (r); (i)++)
#define reversed_range(i, l, r) for (int (i) = (r) - 1; (i) >= l; (i)--)
using namespace std;
template <typename T>
using vec = vector<T>;
using lint = long long;
using ulint = unsigned long long;
using pint = pair<int, int>;
using plint = pair<lint, lint>;

template <typename S, typename T>
ostream& operator <<(ostream& os, pair<S, T> p) {
    os << "(";
    os << p.first << ", " << p.second;
    return os << ")";
}

template <typename T>
ostream& operator <<(ostream& os, vec<T> v) {
    os << "[";
    for (int i = 0; i < v.size() - 1; i++) {
        os << v.at(i) << ", ";
    }
    return os << v.at(v.size() - 1) << "]";
}

template <typename T>
ostream& operator <<(ostream& os, set<T>& s) {
    os << "{";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename T>
ostream& operator <<(ostream& os, unordered_set<T>& s) {
    os << "{";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, map<K, V> m) {
    os << "{";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, unordered_map<K, V> m) {
    os << "{";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

int main() {
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    lint N, K;
    cin >> N >> K;
    if (K == 0) {
        cout << N * N << "\n";
        return 0;
    }
    lint res = 0;
    range(b, K + 1, N + 1) {
        lint ub = (N - b + 1) / b;
        res += (ub + 1) * (b - K);
        lint rest = max(N - ((ub + 1) * b + K) + 1, 0LL);
        res += rest;
    }
    cout << res << "\n";
    return 0;
}


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

// Data structure for Max Heap
struct PriorityQueue 
{
private:
	// vector to store heap elements
	vector<int> A;

	// return parent of A[i]
	// don't call this function if i is already a root node
	int PARENT(int i) 
	{ 
		return (i - 1) / 2; 
	}

	// return left child of A[i]	
	int LEFT(int i) 
	{ 
		return (2 * i + 1); 
	}

	// return right child of A[i]	
	int RIGHT(int i) 
	{ 
		return (2 * i + 2); 
	}

	// Recursive Heapify-down algorithm
	// the node at index i and its two direct children
	// violates the heap property
	void heapify_down(int i)
	{
		// get left and right child of node at index i
		int left = LEFT(i);
		int right = RIGHT(i);

		int largest = i;

		// compare A[i] with its left and right child
		// and find largest value
		if (left < size() && A[left] > A[i])
			largest = left;

		if (right < size() && A[right] > A[largest])
			largest = right;

		// swap with child having greater value and 
		// call heapify-down on the child
		if (largest != i) {
			swap(A[i], A[largest]);
			heapify_down(largest);
		}
	}

	// Recursive Heapify-up algorithm
	void heapify_up(int i)
	{
		// check if node at index i and its parent violates 
		// the heap property
		if (i && A[PARENT(i)] < A[i]) 
		{
			// swap the two if heap property is violated
			swap(A[i], A[PARENT(i)]);
			
			// call Heapify-up on the parent
			heapify_up(PARENT(i));
		}
	}
	
public:
	// return size of the heap
	unsigned int size()
	{
		return A.size();
	}

	// function to check if heap is empty or not
	bool empty()
	{
		return size() == 0;
	}
	
	// insert key into the heap
	void push(int key)
	{
		// insert the new element to the end of the vector
		A.push_back(key);

		// get element index and call heapify-up procedure
		int index = size() - 1;
		heapify_up(index);
	}

	// function to remove element with highest priority (present at root)
	void pop()
	{
		try {
			// if heap has no elements, throw an exception
			if (size() == 0)
				throw out_of_range("Vector<X>::at() : "
						"index is out of range(Heap underflow)");

			// replace the root of the heap with the last element
			// of the vector
			A[0] = A.back();
			A.pop_back();

			// call heapify-down on root node
			heapify_down(0);
		}
		// catch and print the exception
		catch (const out_of_range& oor) {
			cout << "\n" << oor.what();
		}
	}

	// function to return element with highest priority (present at root)
	int top()
	{
		try {
			// if heap has no elements, throw an exception
			if (size() == 0)
				throw out_of_range("Vector<X>::at() : "
						"index is out of range(Heap underflow)");

			// else return the top (first) element
			return A.at(0);	// or return A[0];
		}
		// catch and print the exception
		catch (const out_of_range& oor) {
			cout << "\n" << oor.what();
		}
	}
};

// Max Heap C++ implementation
int main()
{
	PriorityQueue pq;

  string operacao; int valor;
  while(cin >> operacao){
    if (operacao == "insert"){
      cin >> valor;
      pq.push(valor);
    } else if (operacao == "extract"){
      cout << pq.top() << endl;
      pq.pop();
    } else {
      break;
    }
  }
	return 0;
}


Measured memory_bytes: 6916
import java.awt.geom.*;
import java.util.*;
import static java.lang.Math.*;
public class Main{
	final Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		new Main().init();
	}
	void init(){
		new AOJ1167();
	}
	
	class AOJ1167{
		AOJ1167(){
			solve(1000000);
			while(sc.hasNext()){
				int n=sc.nextInt();
				if(n==0)	break;
				System.out.println(dp[n]+" "+dp2[n]);
			}
		}
		final int INF=1<<29;
		int[] a,b;
		int[] dp,dp2;
		void solve(int n){
			final int MAX=1000000;
			a=new int[MAX+1];
			b=new int[MAX+1];
			for(int i=1,j=1; true; ++i){
				a[i]=i*(i+1)*(i+2)/6;
				if(a[i]%2==1)	b[j++]=a[i];
				if(a[i]>=MAX)	break;
			}
			
			dp=new int[n+1];
			for(int i=0; i<=n; ++i)dp[i]=INF;
			dp[0]=0;
			for(int i=1; a[i]<=n; ++i){
				for(int j=0; j<=n; ++j){
					int tmp=j-a[i];
					if(tmp>=0){
						dp[j]=min(dp[j], dp[j-a[i]]+1);
					}
				}
			}
			
			dp2=new int[n+1];
			for(int i=0; i<=n; ++i)dp2[i]=INF;
			dp2[0]=0;
			for(int i=1; b[i]<=n; ++i){
				for(int j=0; j<=n; ++j){
					int tmp=j-b[i];
					if(tmp>=0){
						dp2[j]=min(dp2[j], dp2[j-b[i]]+1);
					}
				}
			}
		}
	}
}

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

int main(){
  int N;
  cin >> N;
  vector<vector<int>> vec(N,vector<int>(3));
  for(int i=0; i<N; i++){
    for(int j=2; j>=0; j--){
      cin >> vec.at(i).at(j);
    }
  }
  sort(vec.rbegin(),vec.rend());
  for(int i=0; i<N; i++){
    swap(vec.at(i).at(0),vec.at(i).at(2));
  }
  
  
  int ans_x = -1;
  int ans_y = -1;
  int ans_h = -1;
  for(int x=0; x<=100; x++){
    for(int y=0; y<=100; y++){
      int h = -1;
      for(int i=0; i<N; i++){
        int a = vec.at(i).at(0);
        int b = vec.at(i).at(1);
        int c = vec.at(i).at(2);
        if(h == -1){
          h = c + abs(x-a) + abs(y-b);
        }
        else{
          int d = max(0,h-abs(x-a)-abs(y-b));
          if(d != c){
            break;
          }
        }
        if(i == N-1){
          ans_x = x;
          ans_y = y;
          ans_h = h;
          break;
        }
      }
    }
  }    
  cout << ans_x << " " << ans_y << " " << ans_h << endl;         
}

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

typedef int64_t Int;
#define all(x) (x).begin(), (x).end()
 
const double EPS = 1e-10;
const Int INF = 1e18;
const int inf = 1e9;
const Int mod = 1e9+7;

bool print_space_enable = false;
void print() { 
    cout << '\n'; 
    print_space_enable = false;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
    if (print_space_enable) std::cout << " ";
    cout << fixed << setprecision(15) << head;
    print_space_enable = true;
    print(std::forward<Tail>(tail)...);
}

template<typename T>
void print(vector<T> v) {
    for (size_t i = 0; i < v.size(); i++) {
        if (i > 0) std::cout << " ";
        std::cout << v[i];
    }
    std::cout << '\n';
}

void solve() {
    Int n;
    cin >> n;
    vector<Int> b(n);
    for (Int i = 0; i < n; i++) {
        cin >> b[i];
    }
    vector<Int> c = b;
    sort(all(b));
    vector<pair<Int, Int>> a(n);
    for (Int i = 0; i < n; i++) {
        a[i] = {b[i], i};
    }
    map<Int, Int> mp;
    for (Int i = 0; i < n; i++) {
        if (a[i].second < n / 2) {
            mp[a[i].first] = b[n / 2];
        } else {
            mp[a[i].first] = b[n / 2 - 1];
        }
    }
    for (Int i = 0; i < n; i++) {
        print(mp[c[i]]);
    }
}

int main() {
    solve();
    return 0;
}


Measured memory_bytes: 21492
import java.util.*;

public class Main {

    static class Edge {
        int from, to, cost;

        public Edge(int from, int to, int cost) {
            this.from = from;
            this.to = to;
            this.cost = cost;
        }
    }

    static class Node implements Comparable<Node> {
        int id, value;

        public Node(int id, int value) {
            this.id = id;
            this.value = value;
        }

        @Override
        public int compareTo(Node o) {
            return value - o.value;
        }
    }

    static int n;
    static List<List<Edge>> graph;
    static int[] dist;
    static int INF = 1000000100;

    static void dijkstra(int start) {
        dist = new int[n];
        Arrays.fill(dist, INF);
        dist[start] = 0;

        PriorityQueue<Node> pq = new PriorityQueue<>(n * 2);
        pq.offer(new Node(start, 0));

        boolean[] visited = new boolean[n];

        while (!pq.isEmpty()) {
            Node node = pq.poll();
            visited[node.id] = true;

            if (dist[node.id] < node.value) continue;;

            List<Edge> edges = graph.get(node.id);
            for (int i = 0; i < edges.size(); ++i) {
                Edge edge = edges.get(i);

                if (visited[edge.to]) continue;

                int newDist = dist[edge.from] + edge.cost;
                if (newDist < dist[edge.to]) {
                    dist[edge.to] = newDist;
                    pq.offer(new Node(edge.to, dist[edge.to]));
                }
            }
        }
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        int e = sc.nextInt();
        int r = sc.nextInt();
        graph = new ArrayList<>(n);
        for (int i = 0; i < n; ++i) {
            graph.add(new ArrayList<>());
        }

        for (int i = 0; i < e; ++i) {
            int from = sc.nextInt();
            int to = sc.nextInt();
            int cost = sc.nextInt();
            graph.get(from).add(new Edge(from, to, cost));
        }

        dijkstra(r);

        for (int i = 0; i < n; ++i) {
            if (dist[i] == INF)
                System.out.println("INF");
            else
                System.out.println(dist[i]);
        }
    }
}


Measured memory_bytes: 324296
#include <iostream>
#include <utility>
#include <queue>
#include <memory>
#include <cstring>
#include <vector>
#include <algorithm>
#include <functional>

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

using namespace std;
using ll = long long;
const int mod = 1e9+7;

int main(){
    int x,y,a,b,c;
    cin >> x >> y >> a >> b >> c;
    vector<int> p(a),q(b),r(c);
    rep(i,a) cin >> p[i];
    rep(i,b) cin >> q[i];
    rep(i,c) cin >> r[i];

    sort(p.begin(),p.end(),greater<int>());
    sort(q.begin(),q.end(),greater<int>());
    vector<int> temp(x+y+c);
    rep(i,x) temp[i] = p[i];
    rep(i,y) temp[i+x] = q[i];
    rep(i,c) temp[i+x+y] = r[i];
    sort(temp.begin(),temp.end(),greater<int>());
    ll ans = 0; 
    rep(i,x+y){
        //cout << temp[i] << endl;
        ans += temp[i]; 
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h> 
using namespace std; 
#define deb(x) cout <<"\n"<< (#x) << " = " << (x) << "\n"
const long long  INF = 1e18;
const long long mod=1e9+7 ;
void inputoutput()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); 
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
	    
}

 
int32_t main()
{ 
	inputoutput() ;

	int n;
	cin>>n;

	vector< pair<pair<int,int>,int> > ar;

	for(int i=0 ; i<n ; ++i)
	{
		int a,b,c  ;
		cin>>a>>b>>c;
		ar.push_back(make_pair(make_pair(a,b),c));
	}

	int dp[n][3];

	dp[0][0]=ar[0].first.first;
	dp[0][1]=ar[0].first.second;
	dp[0][2]=ar[0].second ;

	for(int i=1 ; i<n ; ++i)
	{
		dp[i][0]=ar[i].first.first+max(dp[i-1][1], dp[i-1][2]);
		dp[i][1]=ar[i].first.second+max(dp[i-1][0], dp[i-1][2]);
		dp[i][2]=ar[i].second+max(dp[i-1][0], dp[i-1][1]);
	}
	int ans=INT_MIN ;

	for(int i=0 ; i<3 ; ++i)
	{
		// cout<<dp[n-1][i]<<" ";
		ans=max(ans,dp[n-1][i]);
	}

	cout<<ans;

	return 0;
}


Measured memory_bytes: 5572
//2017-7-15 20:13
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<vector>
using namespace std;
const int MaxN = 1e5;

vector<int> edge[MaxN + 5];
bool vis[MaxN + 5];
int n, len;
int tot[3], ans[3];
bool flag;

void dfs1(int u, int cnt){
	if(vis[u] || flag) return;
	vis[u] = true;
	if(u == n){
		flag = true;
		len = cnt;
		return;
	}
	for(int i = 0; i < edge[u].size(); i++){
		int v = edge[u][i];
		dfs1(v, cnt + 1);
	}
	if(!flag) vis[u] = false;
}

void dfs2(int u, int fa, int x, int num){
	if(vis[u]){
		num++;
		if(num > tot[x]) return;
	}
	ans[x]++;
	for(int i = 0; i < edge[u].size(); i++){
		int v = edge[u][i];
		if(v != fa)dfs2(v, u, x, num);
	}
}
	
int main(){
	while(~scanf("%d", &n)){
		memset(vis, 0, sizeof(vis));
		flag = false;
		for(int i = 1; i < n; i++){
			int u, v;
			scanf("%d %d", &u, &v);
			edge[u].push_back(v);
			edge[v].push_back(u);
		}
		dfs1(1, 1);
		tot[1] = (len + 1) / 2, tot[2] = len / 2;
		//printf("%d %d\n", tot[1], tot[2]);
		dfs2(1, 0, 1, 0);
		dfs2(n, n + 1, 2, 0);
		//printf("%d %d\n", ans[1], ans[2]);
		if(ans[2] >= ans[1]) printf("Snuke\n");
		else if(ans[1] > ans[2]) printf("Fennec\n");
	}
	return 0;
}

		


Measured memory_bytes: 10496