akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef int Weight;
struct Edge {  
	int src, dst;
	Weight weight;
	Edge(int sr, int ds, Weight we) :
		src(sr), dst(ds), weight(we) { }
};
bool operator < (const Edge &e, const Edge &f) {
	return e.weight != f.weight ? e.weight > f.weight : 
	(e.src != f.src ? e.src < f.src : e.dst < f.dst);
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
int main(){
	int n; cin >> n; 
	Graph g(n+1);
	for(int i=1; i<=n-1; ++i){
		int a, b;
		cin >> a >> b;
		g[a].push_back(Edge(a,b,i));
		g[b].push_back(Edge(b,a,i));
	}
	
	vector<int> c(n,0), par(n+1,0);
	stack<int> s;
	s.push(1);
	while(!s.empty()){
		int z=s.top();
		s.pop();
		for(int i=0, j=1; i<g[z].size(); ++i, ++j){
			int k=g[z][i].weight;
			if(c[k]!=0){
				--j;
				continue;
			}
			if(par[z]==j) ++j;
			c[k]=j;
			par[g[z][i].dst]=j;
			s.push(g[z][i].dst);
		}
	}

	cout << *max_element(c.begin(), c.end()) << endl;
	for(int i=1; i<n; ++i) cout << c[i] << endl;
}

Measured memory_bytes: 7808
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i8 = int8_t;
using i16 = int16_t;
using i32 = int32_t;
using i64 = int64_t;

constexpr char newl = '\n';
constexpr double eps = 1e-10;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
#define fi first
#define se second
#define debug(x) cout << #x << ": " << x << '\n';
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()

template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
template<class T> void Print(vector<T> v) {
  F0R(i, v.size()) {
    cout << v[i] << ' ';
  }
  cout << newl;
}

#if 1


// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N;
  cin >> N;
  vector<int> vs(N), cs(N);
  F0R(i, N) { cin >> vs[i]; }
  F0R(i, N) { cin >> cs[i]; }
  int result = 0;
  F0R(i, N) {
    if (vs[i] > cs[i])result += vs[i] - cs[i];
  }
  cout << result;
}
#endif


Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
char  x[100010];
int main()
{
    while(scanf("%s",x)!=EOF)
    {
        bool y[30];
        memset(y,0,sizeof(y));
        int len=strlen(x);
        for(int i=0;i<len;i++)
            y[x[i]-'a'+1]=1;
        int flag=0;
        for(int i=1;i<=26;i++)
        {
            if(y[i]==0)
            {
                flag=1;
                printf("%c\n",i+'a'-1);
                break;
            }
        }
        if(flag==0)
            printf("None\n");

    }





}


Measured memory_bytes: 384
#include <iostream>

using namespace std;

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

    long long a = n / k;
    long long c = a * a * a;
    if (k % 2 == 1)
        cout << c << endl;
    else
    {
        long long b = n / (k / 2) - a, d = b * b * b;
        cout << c + d << endl;
    }
    return 0;
}


Measured memory_bytes: 256
n, m, q = map(int, input().split())
a_list = []
b_list = []
c_list = []
d_list = []
for _ in range(q):
    a, b, c, d = map(int, input().split())
    a_list.append(a)
    b_list.append(b)
    c_list.append(c)
    d_list.append(d)

import itertools

ans = 0
h_list = [i+1 for i in range(m)]
for A in itertools.combinations_with_replacement(h_list, n):
    # print(A)
    max_d = 0
    for a, b, c, d in zip(a_list, b_list, c_list, d_list):
        if A[b-1]-A[a-1] == c:
            max_d += d
    ans = max(ans, max_d)

print(ans)

Measured memory_bytes: 9128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n;
ll a[200005],ans=1e18;
int main() {
	cin>>n;
	for (int i=1;i<=n;++i) cin>>a[i],a[i]+=a[i-1];
	for (int l=1,r=3,k=2;k<=n-2;++k) {
		while (l+1<k&&llabs((a[l])-(a[k]-a[l]))>llabs((a[l+1])-(a[k]-a[l+1]))) ++l;
		while (r+1<n&&llabs((a[r]-a[k])-(a[n]-a[r]))>llabs((a[r+1]-a[k])-(a[n]-a[r+1]))) ++r;
		ll w=a[l],x=a[k]-a[l],y=a[r]-a[k],z=a[n]-a[r];
		ans=min(ans,
			max(max(max(max(max(llabs(w-x),llabs(w-y)),llabs(w-z)),llabs(x-y)),llabs(x-z)),llabs(y-z))
		);
	}
	cout<<ans;
}

Measured memory_bytes: 1792
n=int(input())
L=list(map(int,input().split()))
LL=list(set(L))
ans="No"
if LL==[0]:
    ans="Yes"
elif len(LL)==2:
    if L.count(LL[0])==2*L.count(LL[1]) or L.count(LL[1])==2*L.count(LL[0]):
        ans="Yes"
elif len(LL)==3:
    if L.count(LL[0])==L.count(LL[1]) and L.count(LL[1])==L.count(LL[2]):
        if LL[0]^LL[1]^LL[2]==0:
            ans="Yes"
print(ans)

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

using namespace std;

int main()
{
	string n;
	cin >> n;
	
	int c = 0;
	for (int i = 0; i < 3; i++) {
		if (n[i] == 'A') {
			c++;
		}
	}
	
	if (c == 3 || c == 0) {
		cout << "No" << endl;
	}
	else {
		cout << "Yes" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(a,b) for(int a=0;a<(b);++a)
#define REP1(i,n) for(int i=1;i<=(n);++i)
#define debug(x) cerr<<#x<<": "<<x<<'\n'
#define all(x) (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n",(x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define isYes(x) printf("%s\n",(x) ? "Yes" : "No")
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
#define INF (1<<29)
#define Sp(p) cout<<setprecision(25)<< fixed<<p<<endl
#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 X first
#define Y second
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;


template<class T=int>
T in(){T x;cin>>x;return (x);}
template<class T>
void print(T& x){cout<<x<<'\n';}

const int MOD =(int)1e9+7;
const int mod =(int)1e9+7;
const int MAX =510000;
ll fac[MAX],finv[MAX],inv[MAX];
void COMint(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<MAX;i++){
        fac[i]=fac[i-1]*i%MOD;
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}
ll COM(int n,int k){
    if(n<k) return 0;
    if(n<0||k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}
ll gcd(ll a,ll b){
    if(b==0)return a;
    if(a>b){
        swap(a,b);
    }
    return gcd(a,b%a);
}
ll lcm(ll a,ll b){
    ll g;g=gcd(a,b);
    return a*b/g;
}
bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

bool compare_by_a(pair<int, int> a, pair<int, int> b) {
    if(a.first != b.first){
        return a.first < b.first;
    }else{
        return a.second < b.second;
    }
}
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

ll RS(ll N,ll P,ll M){
    if(P==0){
        return 1;
    }else{
        if(P%2==0){
            ll t=RS(N,P/2,M);
            return t*t%M;
        }else{
            return N*RS(N,P-1,M)%M;
        }
    }
}
int main() {
    ios::sync_with_stdio(false);
    int N=in();
    int p=0;int s=0;int max_p=0;
    REP(i, N){
        cin>>p;s+=p;max_p=max(max_p,p);
    }     
    cout<<s-max_p/2<<endl;
    return 0;

}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;

class Program {
  static void Main (string[] args) {
    string[] str = Console.ReadLine().Split(' ');
    int a = int.Parse(str[0]);
    int b = int.Parse(str[1]);
    int ans = a * b / 2;
    Console.WriteLine(ans);
  }
}

Measured memory_bytes: 13140
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define Rep(i, n) for (int i = 0; i < (int)(n); i++)
#define BitRep(i, n) for (int i = 0; i < (int)(1 << n); i++)
#define All(vec) vec.begin(), vec.end()
#define Sum(vec) accumulate(vec.begin(), vec.end(), 0)
#define Sort(vec) sort(vec.begin(), vec.end())
#define Reverse(vec) reverse(vec.begin(), vec.end())
#define Next_permutation(vec) next_permutation(vec.begin(), vec.end())
#define PI acos(-1)

int main() {
    string S;
    int Q;
    cin >> S >> Q;
    bool flag = 0;
    const int rev = 3;
    Rep(i, Q) {
        int T;
        cin >> T;
        if (T == 1) flag = 1 - flag;
        else {
            int F;
            char C;
            cin >> F >> C;
            if (flag) F = rev - F;
            if (F == 1) S = C + S;
            else S += C;
        }
    }
    if (flag) Reverse(S);
    cout << S << endl;
    return 0;
}

Measured memory_bytes: 4724
//inlclude前用define 
#define _USE_MATH_DEFINES

//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<cstdio>
#include<type_traits>
#include<numeric>
#include<limits>
#include<iomanip>
#include<set>

using namespace std;

//typedef
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;

//define
#define INF 100000000
#define NUM 1000000007


int main() {
	VI num(3);
	int cnt = 0,judge;

	for (int i = 0; i < 3; i++) cin >> num[i];
	sort(num.begin(), num.end());
	
	
	cnt += num[2] - num[1];
	num[0] += cnt;
	num[1] += cnt;
	judge = num[1] - num[0];
	if (judge % 2 == 0) {
		cnt += judge / 2;
	} else {
		cnt += ((judge+1) / 2) + 1;
	}

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


Measured memory_bytes: 256
from collections import Counter
S = input()
T = input()
c_S = Counter(S)
c_T = Counter(T)
# print('c_S, c_T', c_S, c_T)
v1 = sorted(c_S.values())
v2 = sorted(c_T.values())
if len(v1) != len(v2):
    print('No')
    exit()
for s1, s2 in zip(v1, v2):
    if s1 != s2:
        print('No')
        exit()
print('Yes')


Measured memory_bytes: 4016
x,n = map(int,input().split())
if n:
    p = list(map(int,input().split()))
else:
    p = []
p = set(p)
pp = set([item for item in range(0,105) if item not in p])
v = 3000
ans = -1
for item in pp:
    if v>abs(x-item):
        v = abs(x-item)
        ans = item
print(ans)

Measured memory_bytes: 9200
/*氏名：保坂優介, 学籍番号：200441141
  概要：秒を時間 分 秒に変える*/

#include<stdio.h>

int main(void)
{
    int time, hour, min, sec;       //変数の宣言

    scanf("%d", &time);      //入力

    sec = time % 60;        //計算
    min = (time / 60) % 60;
    hour = time / 3600;

    printf("%d:%d:%d\n", hour, min, sec);     //出力

    return 0;
}


Measured memory_bytes: 2100
#include<stdio.h>

int main() {
  
  int i, j, N, K, tmp;
  
  scanf("%d%d", &N, &K);
  
  int p[N];
  
  for(i=0; i<N; i++) {
    
    scanf("%d", &p[i]);
    
  }
  
  for(i=0; i<N; i++) {
    
    for(j=i+1; j<N; j++) {
      
      if(p[i] > p[j]) {
        
        tmp = p[i];
        p[i] = p[j];
        p[j] = tmp;
        
      }
      
    }
    
  }
  
  int sum = 0;
  
  for(i=0; i<K; i++) {
    
    sum += p[i];
    
  }
  
  printf("%d", sum);
  
  return 0;
}


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

int main() {
  long long h, w;
  cin >> h >> w;
  if ( h < w ) { swap(h, w); }

  long long ans;
  if ( h == 1 ) {
    ans = 1;
  } else if ( w == 1 ) {
    ans = h - 2;
  } else {
    ans = (h-2) * (w-2);
  }

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


Measured memory_bytes: 3572
#![allow(non_snake_case)]
#![allow(unused_variables)]
#![allow(dead_code)]

fn main() {
    let (H, W, K): (usize, usize, usize) = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        let mut iter = line.split_whitespace();
        (
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap(),
        )
    };
    let s: Vec<Vec<char>> = (0..H)
        .map(|_| {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().chars().collect()
        })
        .collect();

    let mut res = vec![vec![0; W]; H];
    let mut x = 1;
    let mut a = vec![];
    for i in 0..H {
        let mut k = s[i].iter().filter(|&&c| c == '#').count();
        if k >= 1 {
            a.push(i);
            for j in 0..W {
                for &l in &a {
                    res[l][j] = x;
                }
                if s[i][j] == '#' && k >= 2 {
                    k -= 1;
                    x += 1;
                }
            }
            x += 1;
            a = vec![];
        } else {
            a.push(i);
        }
    }
    if !a.is_empty() {
        for j in 0..W {
            for &l in &a {
                res[l][j] = res[a[0] - 1][j];
            }
        }
    }

    let ans = (0..H)
        .map(|i| {
            res[i]
                .iter()
                .map(|&r| r.to_string())
                .collect::<Vec<_>>()
                .join(" ")
        })
        .collect::<Vec<_>>()
        .join("\n");

    println!("{}", ans);
}


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

int main(){
	double a, b, c,d, S, L, h;
	cin >> a >> b >> c;
	c = c / 180 * 3.1415926535;
	h = b * sin(c);
	S = a * h * 1 / 2;
	L = pow(a, 2) + pow(b, 2)-2*a*b*cos(c);
	L = sqrt(L) + a + b;
	printf("%f\n%f\n%f\n", S, L, h);
	
	return 0;
}


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

int	main(void)
{
  int	A;
  int	B;
  int   C;
  int	num;
  double	e;
  double    f;
  double	ce;
  double    cf;
  double	ttax;
  double    ft;
  
  num = scanf("%d %d", &A, &B);
  
  C = A + 1;
  e = 12.5 * A;
  f = 12.5 * C;
  ce = ceil(e);
  cf = floor(f);
  if (f == cf)
    cf = cf - 1.0;

  while (ce <= cf)
  {
    ttax = ce * 0.1;
    ft = floor(ttax);
    if ((int)ft == B)
    {
        printf("%d",(int)ce);
        return (0);
    }
    ce = ce + 1.0;
  }
  printf("-1");
  return (0);
}

Measured memory_bytes: 128
from itertools import permutations as per
n,m,r = map(int,input().split())
v = list(map(int,input().split()))
for i in range(r):
    v[i] -= 1
INF = float("inf")
g = [[INF]*n for _ in range(n)]
for i in range(m):
    a,b,c = map(int,input().split())
    a -= 1
    b -= 1
    g[a][b] = c
    g[b][a] = c
for i in range(n): g[i][i] = 0
for k in range(n):
    for i in range(n):
        for j in range(n):
            g[i][j] = min(g[i][j],g[i][k]+g[k][j])

ans = INF
for l in per(range(r)):
    t = 0
    for i in range(r-1):
        t += g[v[l[i]]][v[l[i+1]]]
    ans = min(ans,t)
print(ans)

Measured memory_bytes: 75644
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <utility>
#include <set>
#include <stack>
#include <climits>
#include <cmath>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define rep1(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define reps(i,s,n) for(int i=s, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
typedef long long ll;
const char sp = ' ';


using namespace std;

int main(void){
    ll A, B, C, K;
    cin>>A>>B>>C>>K;
    if(K>A+B) cout<<A-(K-A-B)<<endl;
    else if(A<K) cout<<A<<endl;
    else cout<<K<<endl;
    return 0;
}


Measured memory_bytes: 3628
#include<stdio.h>
#include<math.h>
int main(){
  double S,L,h,x,y;
  int a,b,c;
  double pai=3.141592653589;

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

  x=c*pai/180;
  y=sqrt(a*a+b*b-2*a*b*cos(x));
  h=b*sin(x);
  printf("%.8lf\n%.8lf\n%.8lf\n",h*a/2,a+b+y,h);

  return 0;
}

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

using namespace std;

int main(){
  int A, B, C, D;
  cin >> A >> B >> C >> D;

  int s, e;
  s = A;
  e = B;
  if(C > A){
    s = C;
  }
  if(D < B){
    e = D;
  }
  if(e-s > 0){
  cout << e - s << endl;
  }else{
  cout << 0 << endl;
  }
}


Measured memory_bytes: 3596
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <cmath>
#include <ios>
#include <ctype.h>
#include <stack>
#include <istream>
#include <stdio.h>
#include <map>
#include <set>
#include <queue>
#include <unordered_map>
#include <functional>
#include <bitset>
#include <list>
#include <deque>
#include <time.h>
#include <random>
#include <iomanip>
#include <fstream>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,a,b) for (int i = a; i < (b); ++i)
#define all(x) (x).begin(),(x).end()
#define pint pair<int,int>
const int INF = 1000000007;
const long double EPS = 1e-15;
const long double PI = acos(-1);
typedef long long ll;
using namespace std;
using Graph = vector<vector<int>>;
using Graph_weighted = vector<vector<pair<int,int>>>;
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }
ll ceil(const ll a, const ll b) { return (a + b - 1) / b; }
int main(){
  cout << fixed;cout << setprecision(16);
  long double n;
  cin >> n;
  cout << (n + n) * PI << endl;
  return 0;
}


Measured memory_bytes: 3792
[A,V] = list(map(int,input().split()))
[B,W] = list(map(int,input().split()))
T = int(input())

if A<B:
    if A+V*T >= B+W*T:
        out='YES'
    else:
        out='NO'

else:
    if B-W*T >= A-V*T:
        out='YES'
    else:
        out='NO'
print(out)

Measured memory_bytes: 61632
#include <bits/stdc++.h>
using namespace std;
#define fo(i,n) for(int i=0;i<n;i++)
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    int x,n, cc=-1;cin >>x >> n;
    int arr[n];
    fo(i,n){
        cin >> arr[i];
    }
    sort(arr, arr+n);
    fo(i,n){
        if(arr[i]==x){
            cc =i;
        }
    }
    if(cc==-1){
        cout << x;
        return 0;
    }
    int min1 =x-arr[0]+1,min2 =arr[n-1]-x+1, k=1;
    int c = arr[cc];
    for(int i = cc-1; i >=0;--i){
        if(arr[i]!=c-k){
            min1 = k;
            break;
        }
        ++k;
    }
    k =1;
    for(int i = cc+1; i <n;++i){
        if(arr[i]!=c+k){
            min2 = k;
            break;
        }
        ++k;
    }
    if(min2<min1){
        cout << x + min2;
    }
    else{
        cout << x-min1;
    }
  
}


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

#define rep(i,a,b)      for(int i=a;i<=b;i++)
#define revp(i,a,b)     for(int i=b;i>=a;i--)

long long int a,b,k;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    

    cin>>a>>b>>k;
    if(k>=a and k-a<=b)
        cout<<0<<" "<<b-(k-a);
    else if (k>=a+b)
        cout<<"0 0";
    else if(k<a)
        cout<<a-k<<" "<<b;

}




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

const int inf = 1e9 + 7;

void Frog_2(vector<int> &h, int k)
{
	int n = h.size();

	vector<int> dp(n, inf);

	/* dp[i] represents the minimum cost to reach the end when you start at i */
	
	// No out of bound acces due to input constraints
	dp[n-1] = 0;

	for(int i = n-2; i >= 0; i--)
	{
		for(int j = i + 1; j <= i + k; j++)
		{
			if(j >= n)
				continue;

			dp[i] = min(dp[i], abs(h[j]-h[i]) + dp[j]);
		}
	}

	cout << dp.front() << endl;
}

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

	vector<int> h(n);
	for(auto &ele : h)
		cin >> ele;

	Frog_2(h, k);
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>                                            
                                                                    
using namespace std;                                                
                                                                    
int main() {                                                        
                                                                    
    int a, b, isNA, isData= 0;                                      
                                                                    
    while(cin >> a >> b && (a || b)) {                              
                                                                    
        if(isData == 0) {                                           
            isData = 1;                                             
        } else {                                                    
            cout << endl;                                           
        }                                                           
                                                                    
        isNA = 1;                                                   
                                                                    
        for(int i = a; i <= b; ++i) {                               
            if(i == 0) {                                            
                continue;                                           
            }                                                       
            if(i % 400 == 0 || (i % 4 == 0 && i % 100 != 0)) {      
                cout << i << endl;                                  
                isNA = 0;                                           
            }                                                       
        }                                                           
                                                                    
        if(isNA == 1) {                                             
            cout << "NA" << endl;                                   
        }                                                           
                                                                    
    }                                                               
                                                                    
}                                                                   

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

int main(){
	int num[100] = {}, index = 0;
	char is[8];
	while(cin >> is){
		if(is[0] == '+'){
			index--;
			num[index-1] += num[index];
		}
		else if(is[0] == '-'){
			index--;
			num[index-1] -= num[index];
		}
		else if(is[0] == '*'){
			index--;
			num[index-1] *= num[index];
		}
		else if(is[0] == '/'){
			index--;
			num[index-1] /= num[index];
		}
		else{
			num[index] = atoi(is);
			index++;
		}
	}
	cout << num[0] << endl;
	return 0;
}


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

using namespace std;

typedef long long ll;

const ll LongINF=1e13+7;
const int INF=1e9+7;
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template <class T, class Y>T GCD(T a, Y b){if(a<b){int c=a;a=b;b=c;}if (a % b == 0){return b;}return GCD(b, a % b);}
void clear(queue<pair<int, int>> &q){queue<pair<int, int>> empty;swap(q, empty);} //queueの中身の型は適時変更を忘れない

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

int main(){
    int r;
    cin>>r;
    cout<<r*r<<endl;
    return 0;
}

//a=97,z=122

Measured memory_bytes: 256
#include<iostream>
#include<string.h>
#include<vector>
#include<list>
#include<stdio.h>
#include<math.h>
#include<iomanip>
#include<map>
#include<stack>
#include<queue>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << "debug " << x << endl;
using namespace std;

char land[55][55];
int white, black;
int count;
int w, h;
bool ww, bb;

void solve(int x, int y){
    if(land[x][y] == 'W'){
        ww = true;
        return;
    }else if(land[x][y] == 'B'){
        bb = true;
        return;
    }else if(land[x][y] == 'G'){
        return;
    }
    count++;
    land[x][y] = 'G';
    solve(x + 1, y);
    solve(x, y + 1);
    solve(x - 1, y);
    solve(x, y - 1);
}

int main(){
    while(cin >> w >> h, w||h){
        white = black = 0;
        rep(i, h + 2){
            rep(j,w + 2){
                land[i][j] = 'G';
            }
        }
        range(i, 1, h+1){
            scanf("%s", land[i] + 1);
            land[i][w + 1] = 'G';
        }
        range(i, 1, h+1){
            range(j, 1, w+1){
                if(land[i][j] == '.'){
                    ww = bb = false;
                    count = 0;
                    solve(i,j);
                    if(ww && !bb)
                        white += count;
                    else if(!ww && bb)
                        black += count;
                }
            }
        }
        cout << black << ' ' << white << endl;
    }
}

Measured memory_bytes: 1304
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353

typedef long long ll;
typedef pair<ll,ll> P;

ll V[1<<18];
ll W[1<<18];
ll n;
const ll sikiri = 10;
vector<vector<P>> g(1<<18);
ll ans[1<<18];
ll dp1[sikiri + 1][101010];
P dp2[1<<10];

void dfs(ll node, ll depth){
	//cout << "dfs: " << node << " " << depth << endl;
	if(n <= node)return;
	if(depth < sikiri){
		REP(i, 101010){
			ll now = dp1[depth][i];
			if(0 <= i - W[node])now = max(now, dp1[depth][i - W[node]] + V[node]);
			if(i)now = max(now, dp1[depth+1][i-1]);
			dp1[depth+1][i] = now;
		}

		REP(i, g[node].size()){
			ll id = g[node][i].FI;
			ll L = g[node][i].SE;
			ans[id] = dp1[depth + 1][L];
		}
	}
	else {
		ll kake = depth - sikiri;
		REP(i, 1 << kake){
			dp2[(1 << kake) | i] = MP(dp2[i].FI + W[node], dp2[i].SE + V[node]);
		}

		REP(i, g[node].size()){
			ll id = g[node][i].FI;
			ll L = g[node][i].SE;
			REP(j, 1 << (kake + 1)){
				if(L < dp2[j].FI)continue;
				ans[id] = max(ans[id], dp2[j].SE + dp1[sikiri][L - dp2[j].FI]);
			}
		}
	}

	dfs(2 * node + 1, depth + 1);
	dfs(2 * node + 2, depth + 1);
}

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

	cin >> n;
	REP(i, n)cin >> V[i] >> W[i];
	ll q;cin >> q;
	REP(i, q){
		ll v, l;cin >> v >> l;
		g[v-1].EB(i, l);
	}

	dfs(0, 0);
	REP(i, q)cout << ans[i] << endl;

	return 0;
}


Measured memory_bytes: 25344
cin = open(0).read().strip().split('\n')
n,m = map(int, cin[0].split(' '))
ab = [tuple(map(int, a.split(' '))) for a in cin[1:]]

g = [[] for _ in range(n)]
for abi in ab:
    g[abi[0]-1].append(abi[1]-1)
    g[abi[1]-1].append(abi[0]-1)

for ii in range(n):
    g[ii] = sorted(g[ii])

dist = [-1]*n
dist[0] = 0

import queue
q = queue.Queue()
q.put(0)

while not q.empty():
    idx = q.get()
    for i in g[idx]:
        if dist[i] != -1: continue
        q.put(i)
        dist[i] = idx

aa = min(dist)
if aa == -1:
    print('No')
else:
    print('Yes')
    for a in dist[1:]:
        print(a+1)

Measured memory_bytes: 80900
#include<iostream>
#include<queue>
#include <math.h>
using namespace std;

typedef long long ll;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll r;
    cin >> r;
    cout << r*r << "\n";
    return 0;
}

Measured memory_bytes: 256
def show1(n, ans):
    for i in xrange(n):
        print ans[i],
    print

def show2(n, m, l, ans):
    for i in xrange(l):
        print ans[i] + m + 1,
    for i in xrange(l, n):
        print ans[i] + m ,
    print

k = int(raw_input())
n = 50
ans = [0] * n
print n
if k <= n:
    for i in xrange(k):
        ans[i] = n - i
    show1(n, ans)
else:
    ans = range(50, 0, -1)
    m = k / 50 - 1
    l = k % 50
    show2(n, m, l, ans)


Measured memory_bytes: 2568
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define pi acos(-1.0)
#define eps 1e-9
#define ll long long
#define ull unsigned long long
#define sf scanf
#define pf printf
#define nl printf("\n")
#define	inf (ll)1e15
#define mod 1000000007
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend() 
#define sz(x) (int)(x).size()
#define test_case int ___t;scanf("%d", &___t);for(int cs=1;cs<=___t;cs++)

using namespace __gnu_pbds;
using namespace std;

inline string str_inp(int n){char ch[n+5];sf(" %s",ch);return string(ch);}
inline string line_inp(int n)
{char ch[n+5];fgets(ch,n+5,stdin);string s=string(ch);s.pop_back();return s;}

//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> new_data_set;


const int S=100100;
int main()
{
    //#ifndef ONLINE_JUDGE
    //freopen("input.txt","r",stdin);
    //#endif
	int k;
	string s;
	while(~sf("%d",&k))
	{
		string s=str_inp(105);

		if(sz(s)<=k)pf("%s\n",s.c_str());
		else
		{
			string t;
			for(int i=0;i<k;i++)
			{
				t+=s[i];
			}
			t+="...";
			pf("%s\n",t.c_str());
		}
	}
    return 0;
}
 






































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

#define err(x) cerr << #x << " = " << x << '\n';
const int maxn = 1e6;


int n  ,res ,mx ,my ,x ,y ,cnt2[maxn] ,cnt[maxn];

int main(){
    cin >> n;
    
    for(int i = 0 ,v; i < n; i++){
        cin >> v;       
       if(i & 1){cnt[v]++; mx < cnt[v] ? mx = cnt[v] ,x = v : res = res;}
       else {cnt2[v]++; my < cnt2[v] ? my = cnt2[v] ,y = v : res = res;}
    }
   	sort(cnt,cnt+100003);
	sort(cnt2,cnt2+100003);
        
    res = n - max(mx + cnt2[100001] , my + cnt[100001]);
    x != y ? res = n - mx - my : res = res;

    return cout << res << '\n' ,0;
    }



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

int main(){
  int a, b, n, cnt=1, cnt_b=1;;
  cin >>n >>a >>b;
  char s;
  
  for (int i=0; i<n; i++){
    cin >>s;
    if(s=='a'){
      if(a+b>=cnt){
        cnt++;
        cout <<"Yes" <<endl;
      }else cout <<"No" <<endl;
    }
    if(s=='b'){
      if(a+b>=cnt && b>=cnt_b){
        cnt++;
        cnt_b++;
        cout <<"Yes" <<endl;
      }else cout <<"No" <<endl;
    }
    if(s=='c') cout <<"No" <<endl;
  }
}

Measured memory_bytes: 640
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import numpy


def main():
  height, width = map(int, input().split())
  max_value = height + width
  values = []

  for y in range(height):
    values.append([0 if v == '#' else max_value for v in input().strip()])

  values = numpy.array(values)

  for x in range(width - 1):
    values[:, x + 1] = numpy.minimum(values[:, x] + 1, values[:, x + 1])

  for x in range(width - 1, 0, -1):
    values[:, x - 1] = numpy.minimum(values[:, x] + 1, values[:, x - 1])

  for y in range(height - 1):
    values[y + 1, :] = numpy.minimum(values[y, :] + 1, values[y + 1, :])

  for y in range(height - 1, 0, -1):
    values[y - 1, :] = numpy.minimum(values[y, :] + 1, values[y - 1, :])

  print(numpy.max(values), flush=True)


if __name__ == '__main__':
  main()



Measured memory_bytes: 28996
# Begin Header {{{
from math import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import accumulate, product, permutations, combinations, combinations_with_replacement
# }}} End Header
# _________コーディングはここから！！___________
t = defaultdict(int)
n, m = map(int, input().split())
for i in range(m):
    a, b = map(int, input().split())
    t[a]+=1
    t[b]+=1
for j in range(1, n+1):
    print(t[j])

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

int	main() {
	int	N;
  	cin >> N;
  	
  	vector<string> ss(N);
  	for (int i=0;i<N;i++) cin >> ss.at(i);
  	
  	sort(ss.begin(), ss.end());
  
  	// debug for (int i=0;i<N;i++) cout << i << " " << ss.at(i) << endl;
	
  	vector<int> cand(N);
  	vector<string> cand_str(N);
  	int	cand_index;
  	cand_index = 0;
    int	count;
    count = 1;
  	for (int i=1;i<N;i++) {
      	if (ss.at(i-1).compare(ss.at(i))==0) {
          count++;
            if (i==N-1) {
              	
        		cand.at(cand_index)=count;
          		cand_str.at(cand_index)=ss.at(i-1);
                cand_index++;
              	//cout << "debug end " << ss.at(i-1) << " " << cand_index << endl; 
        	}
        	
      		
        } else {
          	cand.at(cand_index)=count;
          	cand_str.at(cand_index)=ss.at(i-1);
       		count=1;
          	cand_index++;
           if (i==N-1) {
              	
        		cand.at(cand_index)=count;
          		cand_str.at(cand_index)=ss.at(i);
                cand_index++;
              	//cout << "debug end " << ss.at(i-1) << " " << cand_index << endl; 
        	}
        }

    }
  	//for (int i=0;i<cand_index;i++) cout << i << " " << cand.at(i) << endl;
  	//cout << endl;
    //for (int i=0;i<cand_index;i++) cout << i << " " << cand_str.at(i) << endl;
  	
  	// memory the biggest
  	int	c, b_index;
  	vector<int> biggest(cand_index);
  	for (int i=0;i<cand_index;i++) {
    	if (cand.at(i) > c) {
          c = cand.at(i);
          b_index=0;
          biggest.at(b_index)=i;
          b_index++;
        } else if (cand.at(i) == c) {
          biggest.at(b_index)=i;
          b_index++;
        }
    }
  	
  	for (int i=0;i<b_index;i++) {
      int	ans;
      ans = biggest.at(i);
      cout<< cand_str.at(ans) << endl;
    }
}


Measured memory_bytes: 17408
def main():
    from collections import defaultdict

    n = int(input())
    s = input()

    d = defaultdict(bool)

    for c in s:
        for x in '0123456789':
            for y in '0123456789':
                if d[x + y]:
                    d[x + y + c] = True
        for x in '0123456789':
            if d[x]:
                d[x + c] = True
        d[c] = True

    print(sum(len(k) == 3 for k in d))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3572
function Main(input) {
  input = input.split("\n");
  const a = parseInt(input[0], 10);
  const b = parseInt(input[1], 10);
  const h = parseInt(input[2], 10);
 
  var S = ((a + b) * h) / 2.0;
  console.log(S);
}
 
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 21064
n, k = map(int, input().split())
h = list(map(int, input().split()))
dp = [0]*n
for i in list(range(n))[1:]:
    tmp = max(0, i-k)
    dp[i] = min([dpk+abs(h[i]-hk) for dpk, hk in zip(dp[tmp:i], h[tmp:i])])
print(dp[-1])

Measured memory_bytes: 15480
#include <stdio.h>
#include <stdbool.h>

#define MAX 1000000

int main(void)
{
    int i, j;

    bool isPrime[MAX];
    isPrime[0] = isPrime[1] = false;
    for (i = 2; i < MAX; i++) {
        isPrime[i] = true;
    }

    for (i = 2; i <= MAX; i++) {
        if (isPrime[i] == true) {
            for (j = i + i; j <= MAX; j += i) {
                isPrime[j] = false;
            }
        }
    }

    int n;
    int cnt;
    while (scanf("%d", &n) != EOF) {
        cnt = 0;
        for (i = 2; i <= n; i++) {
            if (isPrime[i] == true) {
                cnt++;
            }
        }
        printf("%d\n", cnt);
    }

    return 0;

}

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

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

bool isEnd(int n, std::vector<int> a) {
  int zeroCnt = 0;
  rep(i, n) {
    if (a[i] == 0) zeroCnt++;
  }

  return zeroCnt == n - 1;
}

int main() {
  int n;
  std::cin >> n;
  std::vector<int> a(n);
  rep(i, n) std::cin >> a[i];

  while (a.size() > 1) {
    // rep(i, n) { std::cout << " " << a[i]; }
    // std::cout << '\n';
    for (int i = a.size() - 1; i >= 0; --i) {
      if (a[i] == 0) a.erase(a.begin() + i);
    }
    // for (auto it = a.begin(); it != a.end(); ++it) {
    //   if (*it == 0) a.erase(it);
    // }
    //
    // for(auto it = a.rbegin(); it!=a.rend();++it){
    //   if(*it == 0) a.erase(it);
    // }
    int minIdx = std::distance(a.begin(), std::min_element(a.begin(), a.end()));
    rep(i, n) {
      // if (a[i] == 0) continue;
      if (i != minIdx) { a[i] %= a[minIdx]; }
    }
  }

  rep(i, n) {
    if (a[i] != 0) { std::cout << a[i] << '\n'; }
  }

  return 0;
}


Measured memory_bytes: 640
k,s=map(int,input().split())
count=0
for x in range(k+1):
    for y in range(x+1):
        if x+y>s:
            continue
        else:
            z=s-x-y
            if z>x or z>y:
              continue
            if x==y==z:
                count+=1
            elif x==y or y==z or z==x:
                count+=3
            else:
                count+=6
print(count)

Measured memory_bytes: 9160
import sys
import numpy
import math

N=int(input())

A=list(map(int,input().split()))

dekaiyatu=numpy.argmax(A)
kati=A[dekaiyatu]

A.pop(dekaiyatu)
iikanjinoyatu= numpy.argmin(list(map((lambda x: abs((kati/2)-x)), A)))
string=str(kati)+" "+str(A[iikanjinoyatu])

print(string)


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

#define int long long

#define all(v) (v).begin(),(v).end()
#define pb push_back
#define fi first
#define se second
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define low(a,b) lower_bound(all(a),(b))
#define upp(a,b) upper_bound(all(a),(b))
#define fill(i,n) memset(i,n,sizeof i)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
typedef pair<pint,int> P1;
typedef pair<int,pint> P2;
typedef pair<pint,pint> PP;
static const ll maxLL = (ll)1 << 62;
const ll MOD=1000000007;
const ll INF=1e18;

int N,Q,K;
string s;

signed main() {
    IOS();
    /*シフト演算は(1ll<<x)*/
    cin>>N>>s>>Q;
    int dcnt,mcnt,dmcnt,ans;
    rep(i,0,Q){
        cin>>K;
        ans=0;
        dcnt=0,mcnt=0,dmcnt=0;
        rep(j,0,N){
            if(j>=K){
                if(s[j-K]=='D'){
                    dmcnt-=mcnt;
                    dcnt--;
                }else if(s[j-K]=='M'){
                    mcnt--;
                }
            }
            if(s[j]=='D')dcnt++;
            else if(s[j]=='M'){
                mcnt++;
                dmcnt+=dcnt;
            }
            else if(s[j]=='C')ans+=dmcnt;
        }
        cout<<ans<<endl;
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    return 0;
}

Measured memory_bytes: 1948
from collections import deque
import math

def Next(): return input()
def NextInt(): return int(Next())
def NextInts(): return map(int,input().split())
def Nexts(): return map(str,input().split())
def NextIntList(): return list(map(int,input().split()))
def RowInts(n): return [input() for i in range(n)]

n = NextInt()
ans = 0
for i in range(1, n+1):
    a = n//i
    ans += a*(a+1)//2*i
print(ans)

Measured memory_bytes: 9432
# 各桁の和を求める
def d(n,ans=0):
  if n == 0:
    return ans
  else:
    return d(n//10,ans+n%10)

# 条件を満たすなら桁の和の値を返す
def judge(k,a,b):
  s = d(k)
  if a <= s <= b:
    return k
  else:
    return 0

def solve(n,a,b):
  return sum([judge(i+1,a,b) for i in range(n)])

N,A,B = map(int,input().split())
print(solve(N,A,B))

Measured memory_bytes: 3292
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)

	s := make([]int, 5)
	for i := range s {
		fmt.Scan(&s[i])
	}

	bottleNeck := 1000000000000001
	for i := range s {
		if s[i] < bottleNeck && s[i] < n {
			bottleNeck = s[i]
		}
	}

	if bottleNeck == 1000000000000001 {
		fmt.Println(5)
		return
	}

	fmt.Println((n+bottleNeck-1)/bottleNeck + 4)
}


Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

	/**
	 * 
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String S = scan.next();
		scan.close();
		
		//11011010001011
		//1 8
		//0 6

		//System.out.println(count(S)*2);
		int c0=0;
		int c1=0;
		for(int i=0; i<S.length(); i++) {
			if(S.charAt(i)=='0') {
				c0++;
			} else {
				c1++;
			}
		}
		System.out.println(S.length()-(Math.abs(c0-c1)));

		
		
	}
	public static int count(String S) {
		int c=0;
		String T="";

		for(int i=0; i<S.length()-1; i++) {
			if(S.charAt(i+1) != S.charAt(i)) {
				c++;
				i++;
				if(i==S.length()-2) {
					T=T+S.charAt(i+1);
				}
			} else {
				T=T+S.charAt(i+1);
				if(i+1==S.length()) {
					T=T+S.charAt(i);
				}
			}
		}
		if(c==0) {
			return 0;
		}
		c+=count(T);
		return c;
		
	}

}


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

int main() {
    int m, f, r;

    while (true) {
        cin >> m >> f >> r;
        int point = m+f;
        if (m == -1 && f == -1 && r == -1) break;
        if (m == -1 || f == -1) {
            cout << 'F' << endl;
            continue;
        }
        if (point >= 80) cout << 'A' << endl;
        else if (point >= 65) cout << 'B' << endl;
        else if (point >= 50) cout << 'C' << endl;
        else if (point >= 30) cout << (r >= 50 ? 'C' : 'D') << endl;
        else cout << 'F' << endl;
    }
}


Measured memory_bytes: 3104
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <complex>
#include <set>
#include <list>
#include <iomanip>
#include <map>
#include <memory.h>



using namespace std;
static const double EPS = 1e-9;
typedef long long ll;
typedef unsigned long long ull;
#define FOR(i,n) for(int i=0;i<(int)n;++i)
#define FORNUM(p, x) for (int num = p; num < (int)(x); ++num)
#define FORI(p, x) for (int i = p; i < (int)(x); ++i)
#define FORJ(p, x) for (int j = p; j < (int)(x); ++j)
#define FORK(p, x) for (int k = p; k < (int)(x); ++k)
#define FORL(p, x) for (int l = p; l < (int)(x); ++l)

typedef pair<int,int>P;
#define INF 1000000000
 
struct edge { 
	int from, to,cap,rev; 
	edge (int from, int to, int cap, int rev){
		this->from=from; this->to=to; this->cap=cap; this->rev=rev;
	}
};
 
int V,E;
typedef vector<edge> edges;
vector<edges> G;

char tab[105][105];

int main(){
	int h, w;
	scanf("%d %d ", &h, &w);
	FORI(0, h+2) {
		FORJ(0, w+2) {
			tab[i][j] = '#';
		}
	}
	FORI(1, h + 1) {
		FORJ(1, w + 1) {
			scanf("%c ", &tab[i][j]);
		}
	}
	FORI(0, h + 2) {
		FORJ(0, w + 2) {
			cout << tab[i][j];
		}
		cout << endl;
	}
	return 0;
}


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

using namespace std;

const int NMAX = 100000 + 5;
const int MMAX = 100 + 5;

int N, M;
int A[NMAX];

int main() {
    ios_base :: sync_with_stdio(false);

    cin >> N >> M;

    for (int i = 1; i <= M; ++ i)
        cin >> A[i];

    int odds = 0;
    for (int i = 1; i <= M; ++ i)
        odds += A[i] % 2;
    
    //More than 2 odds is impossible
    if (odds > 2) {
        cout << "Impossible\n";
        return 0;
    }

    //Odds should come first and last in A
    vector <int> odd_positions;
    for (int i = 1; i <= M; ++ i)
        if (A[i] % 2 == 1)
            odd_positions.push_back(i);
    
    for (int i = 0; i < static_cast <int>(odd_positions.size()); ++ i)
        swap(A[1 + (M - 1) * i], A[odd_positions[i]]);
        
    //Print A
    for (int i = 1; i <= M; ++ i)
        cout << A[i] << " \n"[i == M];
    
    //Build B
    vector <int> B;

    if (A[1] != 1) {
        B.push_back(A[1] - 1);
        A[1] = 1;
    }

    for (int i = 2; i <= M; ++ i) {
        B.push_back(A[i - 1] + 1);
        -- A[i];
    }

    if (A[M] > 0)
        B.push_back(A[M]);
    
    //Print B
    cout << B.size() << '\n';
    for (int i = 0; i < static_cast <int> (B.size()); ++ i)
        cout << B[i] << " \n"[static_cast <unsigned int>(i + 1) == B.size()];
    return 0;
}

Measured memory_bytes: 256
#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;

vector<int> get_prime(int n){
    if(n <= 1) return vector<int>();
    vector<bool> is_prime(n+1, true);
    vector<int> prime;
    is_prime[0] = is_prime[1] = 0;
    for (int i = 2; i <= n; ++i) {
        if(is_prime[i]) prime.emplace_back(i);
        for (auto &&j : prime){
            if(i*j > n) break;
            is_prime[i*j] = false;
            if(i % j == 0) break;
        }
    }
    return prime;
}

int main() {
    auto v = get_prime(50100);
    int n;
    while(cin >> n){
        auto p = upper_bound(v.begin(),v.end(), n);
        int ans2 = *p;
        p--; if(*p == n) p--;
        cout << *p << " " << ans2 << "\n";
    }
    return 0;
}


Measured memory_bytes: 3112
#include <cstdio>
int main(){
	int n, k;
	scanf("%d %d",&n,&k);
	int a[n];
	for (int i = 0; i < n; i++){
		scanf("%d",&a[i]);
	}
	int l = 0, r = k - 1, temp, min = 2147483647;
	for (r; r < n; r++){
		if (a[r] <= 0){
			temp = 0 - a[l];
		}else if (a[l] >= 0){
			temp = a[r];
		}else{
			if (0 - a[l] < a[r]){
				temp = 0 - a[l] * 2 + a[r];
			}else{
				temp = 0 - a[l] + a[r] * 2;
			}
		}
		if (temp < min){
			min = temp;
		}
		l++;
	}
	printf("%d\n",min);
}

Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<math.h>
#include<cstdio>
#include<ctype.h>
#include<stdio.h>
#include<set>
#include<vector>
#include<map>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<numeric>
#include<string>
typedef long long ll;
using namespace std;

ll gcd(ll a, ll b) {
	if (a<b) { return gcd(b, a); }
	else if (a%b) { return gcd(b, a%b); }
	else { return b; }
}
int main() {
	ll N;
	ll ans = 0;
	ll cnt = 1;
	cin >> N;
	ll a[N + 100];
	for (ll i = 0; i < N; i++) {
		cin >> a[i];
	}
	sort(a, a + N);
  	a[N]=0;
	for (ll i = 0; i < N; i++) {
		if (a[i] == a[i + 1])cnt++;
		else {
          if(cnt%2==1)
            ans++;
          	cnt=1;
		}
	}
	cout << ans << endl;
}


 

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rep2(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define rev(i, n) for (int (i) = (n) - 1; (i) >= 0; (i)--)
#define rev2(i, a, b) for (int (i) = (a) - 1; (i) >= (b); (i)--)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define yn {puts("Yes");}else {puts("No");}
using namespace std;
using ll = long long;
using P = pair<int, int>;
using Pll = pair<long long, long long>;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
long long TEN(int i) {return !i ? 1 : TEN(i -  1) * 10LL;}
template<class T, class U> 
bool chmin(T& a, const U& b) {if (a > b) {a = b; return 1;} return 0;}
template<class T, class U> 
bool chmax(T& a, const U& b) {if (a < b) {a = b; return 1;} return 0;}
 
struct IoSetup {
  	IoSetup() {
    	cin.tie(nullptr);
    	ios::sync_with_stdio(false);
    	cout << fixed << setprecision(15);
  	}
} iosetup;

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//


int N;
double A[200005];

int count_num_prime(ll x, int n) {
	int cnt = 0;
	while (x % n == 0) {
		cnt++;
		x /= n;
	} 
	return cnt;
}



int main() {
	cin >> N;
	rep (i, N) cin >> A[i];

	rep (i, N) {
		A[i] *= TEN(9);
		A[i] = (ll)(A[i] + 0.5);
	}

	V<P> hoge;
	VV<int> cnt_2_5(50, V<int>(30, 0));
	rep (i, N) {
		int cnt2 = min(count_num_prime(A[i], 2), 18);
		int cnt5 = min(count_num_prime(A[i], 5), 18);
		cnt_2_5[cnt2][cnt5]++;
		hoge.eb(cnt2, cnt5);
	}

	ll ans = 0;
	rep (i, 19) rep (j, 19) rep (i2, 19) rep (j2, 19) {
		if (i + i2 >= 18 && j + j2 >= 18) {
			if (i == i2 && j == j2) {
				ans += (ll)cnt_2_5[i][j] * (cnt_2_5[i][j] - 1);
			}
			else {
				ans += (ll)cnt_2_5[i][j] * cnt_2_5[i2][j2];
			}
		}
	}

	cout << ans / 2 << endl;

	return 0;
}


Measured memory_bytes: 6964