akhauriyash/Code-Regression huggingface dataset:
// clang-format off
#include <cassert>
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <functional>
#include <set>
#include <queue>

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (b)-1; i >= (a); i--)
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep(i, n) for(int i = (n)-1; i >= 0; i--)

#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define pii pair<int, int>
#define vi vector<int>

using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T>& p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T>& vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}
typedef long long ll;
constexpr ll MOD = 1000000007;

constexpr int MAX = 50;

int N,M;
ll a[MAX];
ll b[MAX];
ll c[MAX];
ll d[MAX];

ll di(ll a, ll b, ll c, ll d)
{
    return abs(a-c) + abs(b-d);
}

int main()
{
    cin >> N >> M;
    rep(i, N){
        cin >> a[i] >> b[i];
    }
    rep(i, M){
        cin >> c[i] >> d[i];
    }

    rep(i, N){
        ll min_d = 1000000000;
        int min_ind = 0;
        rep(j, M){
            ll dist = di(a[i], b[i], c[j], d[j]);
            if(min_d > dist){
                min_ind = j;
                min_d = dist;
            }
        }
        cout << min_ind+1 << endl;
    }


    
    return 0;
}


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

using namespace std;
#define double64 long double

int main() {
    int L;
    cin >> L;
    double64 w,h,d;
    w=(double64)L/3;
    h=(double64)L/3;
	d=(double64)L/3;
    double64 result=w*h*d;
    cout<<fixed;
    cout<<setprecision(12);
    cout << result << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class Main {
	
	public static class Point{
		public int x,y;
		
		Point(int x, int y){
			this.x = x;
			this.y = y;
		}
	}
	
	public static void main(String[] args){
		
		Scanner sc = new Scanner(System.in);
		
		while(true){
			int H = sc.nextInt();
			int W = sc.nextInt();
			
			if(H == 0 && W == 0){
				break;
			}
			
			char[][] input = new char[H][W];
			for(int i = 0; i < H; i++){
				char[] tmp = sc.next().toCharArray();
				for(int j = 0; j < W; j++){
					input[i][j] = tmp[j];
				}
			}
			
			int count = 0;
			for(int i = 0; i < H; i++){
				for(int j = 0; j < W; j++){
					if (input[i][j] != '.') {
						count++;

						Queue<Integer> queue = new LinkedList<Integer>();
						queue.add(j + i * W);

						while (!queue.isEmpty()) {
							int k = queue.poll();
							final int x = k % W;
							final int y = k / W;
							final char in = input[y][x];

							input[y][x] = '.';

							if (x != 0 && in == input[y][x - 1]
									&& input[y][x - 1] != '.') {
								queue.add(y * W + (x - 1));
							}

							if (y != 0 && in == input[y - 1][x]
									&& input[y - 1][x] != '.') {
								queue.add((y - 1) * W + x);
							}

							if (x != W - 1 && in == input[y][x + 1]
									&& input[y][x + 1] != '.') {
								queue.add(y * W + (x + 1));
							}

							if (y != H - 1 && in == input[y + 1][x]
									&& input[y + 1][x] != '.') {
								queue.add((y + 1) * W + x);
							}

						}
					}
				}
			}
			
			System.out.println(count);
		}
		
		return;
	}
	
}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
using namespace std;
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> P1;
typedef pair<P, P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i, x) for (long long i = 0; i < x; i++)
#define repn(i, x) for (long long i = 1; i <= x; i++)
#define SORT(x) sort(x.begin(), x.end())
#define ERASE(x) x.erase(unique(x.begin(), x.end()), x.end())
#define POSL(x, v) (lower_bound(x.begin(), x.end(), v) - x.begin())
#define POSU(x, v) (upper_bound(x.begin(), x.end(), v) - x.begin())
vector<pair<string, P> > vec;
// vector<vector<int>> data(3, vector<int>(4));

const string YES = "Yes";
const string NO = "No";

void solve(std::string S) {
    if (S[2] == S[3] && S[4] == S[5])
        cout << YES << endl;
    else
        cout << NO << endl;
}

int main() {
    std::string S;
    std::cin >> S;
    solve(S);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    int l,r,d;
    cin >> l >> r >> d;
    int answer = 0;
    FOR(i,l,r+1){
        if(i%d==0)answer++;
    }
    cout << answer << endl;
    return 0;
}

Measured memory_bytes: 3588
#include <iostream>
using namespace std;
typedef long long ll;
 
const int M = 10000001;
ll a[M];
int main() {
    int N;
    cin >> N;
    fill(a, a + M, 1);
    for (ll i = 2; i < M; i++) {
        for (ll j = 1; i * j < M; j++) {
            a[i * j]++;
        }
    }
    ll ans = 0;
    for (ll i = 1; i <= N; i++) {
        ans += i * a[i];
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 81320
import java.io.*;
import java.util.*;
//import java.util.stream.*;
//import java.math.*;

public class Main {

    public static void main(String[] args) throws IOException {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        Scanner sc = new Scanner(System.in);
        int p, x;
        long sum = 0;
        int n = sc.nextInt();
        int array[] = new int[n];
        for (int i = 0; i < n; i++) {
            array[i] = sc.nextInt();
            sum += array[i];
        }
        int test = sc.nextInt();
        for (int i = 0; i < test; i++) {
            p = sc.nextInt();
            x = sc.nextInt();
            System.out.println(sum - array[p - 1] + x);
        }
        bw.flush();
    }
}


Measured memory_bytes: 21844
#[test]
fn test_solve() {
    assert_eq!(solve("3\n2 3\n1 3\n1 2\n"), "3\n");
    assert_eq!(solve("4\n2 3 4\n1 3 4\n4 1 2\n3 1 2\n"), "4\n");
    assert_eq!(solve("3\n2 3\n3 1\n1 2\n"), "-1\n");
}
use std::cmp::max;
fn solve(src: &str) -> String {
    let mut sc = Scanner::from_str(src);

    let n: usize = sc.read();
    let m = n * (n - 1) / 2;
    let mut pre = vec![Vec::new(); m];
    let game = |i, j| {
        let (i, j) = if i < j { (i, j) } else { (j, i) };
        n * i - i * (i + 1) / 2 + j - i - 1
    };
    for i in 0..n {
        let mut p: usize = sc.read();
        for _ in 0..n - 2 {
            let a: usize = sc.read();
            pre[game(i, a - 1)].push(game(i, p - 1));
            p = a;
        }
    }
    let mut dfm = vec![1; m];
    let mut vtd = vec![0; m];
    for v in 0..m {
        if vtd[v] == 0 {
            if !dfs(v, &mut dfm, &mut vtd, &pre) {
                return "-1\n".to_string();
            }
        }
    }

    format!("{}\n", dfm.iter().max().unwrap())
}
fn dfs(v: usize, dfm: &mut [usize], vtd: &mut [usize], pre: &[Vec<usize>]) -> bool {
    vtd[v] = 1;
    for &p in &pre[v] {
        match vtd[p] {
            0 => {
                if !dfs(p, dfm, vtd, pre) {
                    return false;
                }
            }
            1 => return false,
            _ => (),
        }
        dfm[v] = max(dfm[v], dfm[p] + 1);
    }
    vtd[v] = 2;
    true
}
fn main() {
    let mut buf = String::new();
    use std::io::{Read, Write};
    std::io::stdin().read_to_string(&mut buf).unwrap();
    std::io::stdout().write_all(solve(&buf).as_bytes()).unwrap();
}
struct Scanner<I> {
    src: I,
}
impl<'a> Scanner<std::str::SplitWhitespace<'a>> {
    fn from_str(src: &'a str) -> Self {
        Scanner {
            src: src.split_whitespace(),
        }
    }
}
#[allow(dead_code)]
impl<'a, I> Scanner<I>
where
    I: std::iter::Iterator<Item = &'a str>,
{
    fn read<T: std::str::FromStr>(&mut self) -> T {
        self.src.next().unwrap().parse().ok().expect("Parse error")
    }
    fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    fn chars(&mut self) -> Vec<char> {
        self.src.next().unwrap().chars().collect()
    }
}


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

int main(void){
    int n,d,i,j,k,count=0;
    double dis=0.0,a[11][11];
    scanf("%d %d",&n,&d);
    for(i=0;i<n;i++){
        for(j=0;j<d;j++){
            scanf("%lf",&a[i][j]);
        }
    }
    for(i=0;i<n-1;i++){
        for(j=i+1;j<n;j++){
            for(k=0;k<d;k++){
                dis+=(a[i][k]-a[j][k])*(a[i][k]-a[j][k]);
                }
            dis=sqrt(dis);
            if(dis==(int)dis){
                count++;
            }
            dis=0;
        }
    }
    printf("%d",count);
    return 0;
}


Measured memory_bytes: 128
#include<cmath>
#include<cstdio>
#include<algorithm>

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

using namespace std;

const double EPS=1e-11;
const double INF=1e77;
const double PI=acos(-1);

struct point{
	double x,y;
	point(double x,double y):x(x),y(y){}
};

double arg(const point &a){
	double t=atan2(a.y,a.x);
	return t<0?t+2*PI:t;
}

struct interval{
	double a,b;
	interval():a(0),b(0){}
	interval(const double &a,const double &b):a(a<b?a:b),b(a<b?b:a){}
	bool operator<(const interval &I)const{ return b+EPS<I.b || abs(b-I.b)<EPS && a+EPS<I.a; }
};

bool cover(const interval &I,double x){
	return I.a-EPS<x && x<I.b+EPS;
}

int solve(int n,const interval *I){
	int res=0;
	double x=-INF;
	rep(i,n) if(x+EPS<I[i].a) res++, x=I[i].b;
	return res;
}

int main(){
	int n; scanf("%d",&n);
	int t[2000],l[2000],b[2000],r[2000];
	rep(i,n) scanf("%d%d%d%d",l+i,b+i,r+i,t+i);

	interval I[2000];
	rep(i,n){
		I[i].a=INF;
		I[i].b=-INF;
		if(l[i]>0 && t[i]>=0 && b[i]<0){ // x ティツサツクテ」ツ?ョテヲツュツ」テ」ツ?ョテゥツδィテ・ツ按?」ツつ津」ツ?セテ」ツ?淌」ツ??
			I[i].a=min(I[i].a,arg(point(l[i],b[i])));
			I[i].a=min(I[i].a,arg(point(r[i],b[i])));
			I[i].b=max(I[i].b,arg(point(l[i],t[i]))+2*PI);
			I[i].b=max(I[i].b,arg(point(r[i],t[i]))+2*PI);
		}
		else{
			I[i].a=min(I[i].a,arg(point(l[i],t[i])));
			I[i].a=min(I[i].a,arg(point(l[i],b[i])));
			I[i].a=min(I[i].a,arg(point(r[i],t[i])));
			I[i].a=min(I[i].a,arg(point(r[i],b[i])));
			I[i].b=max(I[i].b,arg(point(l[i],t[i])));
			I[i].b=max(I[i].b,arg(point(l[i],b[i])));
			I[i].b=max(I[i].b,arg(point(r[i],t[i])));
			I[i].b=max(I[i].b,arg(point(r[i],b[i])));
		}
	}
	sort(I,I+n);

	int ans=n;
	rep(i,n){
		int m=0;
		interval J[2000];
		for(int j=i+1;j<n;j++){
			if(!cover(I[j],I[i].b)
			&& !cover(I[j],I[i].b+2*PI)
			&& !cover(I[j],I[i].b-2*PI)) J[m++]=I[j];
		}
		rep(j,i){
			if(!cover(I[j],I[i].b)
			&& !cover(I[j],I[i].b+2*PI)
			&& !cover(I[j],I[i].b-2*PI)) J[m++]=interval(I[j].a+2*PI,I[j].b+2*PI);
		}
		sort(J,J+m);
		ans=min(ans,solve(m,J)+1);
	}
	printf("%d\n",ans);

	return 0;
}

Measured memory_bytes: 1212
#include <bits/stdc++.h>
#define FOR(i, n) for (int i = 0; i < n; i++) 

using namespace std;

#define fi first
#define se second

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

int main() {
  int n; scanf("%d", &n);
  pii a[n]; FOR(i, n) scanf("%d%d", &a[i].fi, &a[i].se);
  sort(a, a + n);

  pii pref[n], suff[n];

  int l = -1, r = 1e9 + 1;
  FOR(i, n) {
    l = max(l, a[i].fi);
    r = min(r, a[i].se);
    pref[i] = {l, r};
  }

  l = -1, r = 1e9 + 1;
  for (int i = n-1; i >= 0; i--) {
    l = max(l, a[i].fi);
    r = min(r, a[i].se);
    suff[i] = {l, r};
  }

  int sol = 0;

  auto calcP = [](int x, int y) {
    return max(0, y - x + 1);
  };

  auto calc = [calcP](pii p) {
    return calcP(p.first, p.second);
  };

  for (int i = 0; i < n-1; i++) {
    sol = max(sol, calc(pref[i]) + calc(suff[i+1]));
  }

  FOR(i, n) {
    int temp = calc(a[i]);
    l = -1, r = 1e9 + 1;
    if (i) { l = max(l, pref[i-1].fi); r = min(r, pref[i-1].se); }
    if (i < n-1) { l = max(l, suff[i+1].fi); r = min(r, suff[i+1].se); }
    temp += calcP(l, r);
    sol = max(sol, temp);
  }

  printf("%d\n", sol);

  return 0;
}


Measured memory_bytes: 2560
// luogu-judger-enable-o2
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,t,x,y;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>t>>x>>y;
        if(t<x+y)
        {
            cout<<"No"<<endl;
            return 0;
        }
        if((!((x+y)%2)&&t%2)||((x+y)%2&&!(t%2)))
        {
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
  int n,m;
  cin >> n >> m;
  vector<int> a(m);
  vector<bool> is(n+1,true);
  rep(i,m){
    cin >> a.at(i);
    is.at(a.at(i))=false;
  }
  vector<ll> ans(n+1,0);
  ans.at(0)=1;
  for(ll i=1;i<n+1;i++){
    if(is.at(i)==false && is.at(1+i)==false){
      cout << 0;
      return 0;
    }
  }
  ll p=1e9+7;
  for(ll i=1;i<n+1;i++){
    if(is.at(i)==false){
      continue;
    }
    if(i==1){
      ans.at(i)=1;
      continue;
    }
    ans.at(i)=ans.at(i-1)+ans.at(i-2);
    ans.at(i)=ans.at(i)%p;
  }
  cout <<ans.at(n);
}

Measured memory_bytes: 4408
#include<bits/stdc++.h>
using namespace std;
#define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
#define DREP(i,st,ed) for(register int i=st,i##end=ed;i>=i##end;--i)
typedef long long ll;
template<typename T>inline bool chkmin(T &x,T y){return (y<x)?(x=y,1):0;}
template<typename T>inline bool chkmax(T &x,T y){return (y>x)?(x=y,1):0;}
inline int read(){
	int x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1)+(x<<3)+(c^'0');
	return x*f;
}
inline ll readll(){
	ll x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1ll)+(x<<3ll)+(c^'0');
	return x*f;
}
const int maxn=1e5+10;
int f[maxn],g[maxn],a[maxn],d[maxn];
vector<int> G[maxn];
vector<int> E[maxn];
int dfs(int x){
	int sum=0;
	for(auto v:G[x]){
		int u=dfs(v);
		if(u){
			if(sum) E[u].push_back(sum),E[sum].push_back(u),sum=0;
			else sum=u;
		}
	}
	if(!sum) sum=x;
	return sum;
}
void dfs_graph(int x){
	for(auto v:E[x]) if(a[v]==-2) a[v]=-a[x],dfs_graph(v);
}
int main(){
	int n=read();
	int root;
	REP(i,1,n){
		f[i]=read();
		if(f[i]==-1) root=i;
		else G[f[i]].push_back(i),d[f[i]]^=1;
	}
	dfs(root);
	REP(i,1,n){
		G[i].clear();
		if(!d[i]) a[i]=-2;
	}
	REP(i,1,n){
		f[i]=read();
		if(f[i]==-1) root=i;
		else G[f[i]].push_back(i),d[f[i]]^=1;
	}
	dfs(root);
	REP(i,1,n) if(d[i]) return printf("IMPOSSIBLE\n"),0;
	printf("POSSIBLE\n");
	REP(i,1,n) if(a[i]==-2){
		a[i]=-1;
		dfs_graph(i);
	}
	REP(i,1,n) printf("%d%c",a[i],i==iend?'\n':' ');
	return 0;
}


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

int main(){
  unsigned N;
  std::cin>>N;
  std::vector<unsigned long> A(N);
  for(auto &a:A)
    std::cin>>a;

  std::sort(A.begin(),A.end());

  unsigned long sum = A[0];
  unsigned i,j=0;
  for(i=1;i<N;++i){
    if(sum*2<A[i]){
      j=i;
    }
    sum += A[i];
  }
  
  if(j==0){
    std::cout<<N<<std::endl;
  }else{
    std::cout<<N-j<<std::endl;
  }
  return 0;
}

Measured memory_bytes: 1656
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        int ans = 1;
        while (N-- != 0) {
            if (ans > K) {
                break;
            }
            ans += ans;
        }
        while (N-- != -1) {
            ans += K;
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 23636
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;

int main(void) {
    int n,m;
    cin>>n>>m;
    ll x[n],y[m];
    ll xsum=0,ysum=0;
    rep(i,n){cin>>x[i];}
    ll x0=x[0],y0=y[0];
    rep(i,n){x[i]-=x0;}
    DEBUG{rep(i,n)cout<<x[i]<<" ";}
    rep(i,m){cin>>y[i];}
    rep(i,n){y[i]-=y0;}
    for(int i=n-1;i>=0;i--){
        DEBUG{cout<<(2*i-n+1)*x[i]<<endl;}
        xsum+=(2*i-n+1)*x[i];
    }
    DEBUG{cout << xsum<<endl;}
    for(int i=m-1;i>=0;i--){
        ysum+=(2*i-m+1)*y[i];
    }
    DEBUG{cout << ysum<<endl;}
    xsum%=MOD;
    ysum%=MOD;
    cout << (xsum*ysum)%MOD << endl;
    return 0;
}


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

char letter(const string &s, int &p);
string srting(const string &s, int &p);
string cipher(const string &s, int &p);

char letter(const string &s, int &p) {
  if (s[p] == '?' || s[p] >= 'A' && s[p] <= 'Z') {
    p++;
    return s[p - 1];
  }

  int q = p;
  p++;
  char l = letter(s, p);

  if (s[q] == '+') {
    return l == '?' ? '?' : l != 'Z' ? l + 1 : 'A';
  }

  if (s[q] == '-') {
    return l == '?' ? '?' : l != 'A' ? l - 1 : 'Z';
  }
}

string srting(const string &s, int &p) {
  if (s[p] != '[') {
    return string() + letter(s, p);
  }

  p++;
  string c = cipher(s, p);
  p++;
  std::reverse(c.begin(), c.end());

  return c;
}

string cipher(const string &s, int &p) {
  string c = srting(s, p);

  if (s[p] == ']' || p == s.size()) {
    return c;
  }

  c += cipher(s, p);

  return c;
}

int main() {
  string s;
  while (cin >> s, s != ".") {
    int p = 0;
    string c = cipher(s, p);
    replace(c.begin(), c.end(), '?', 'A');

    cout << c << endl;
  }

  return 0;
}

Measured memory_bytes: 3128
#include <cstdio>
#include <vector>
#include <queue>
#include <cmath>
#include <algorithm>

using namespace std;

#define N 10005

typedef struct {
	double x, y;
} point;

typedef struct {
	int from, to;
	double cost;
} edge;

typedef pair<double, int> PDI;

point p[N];
vector<edge> G[N];

double d[N];
bool used[N];

int n, m;
double ans;

double calc_length(point& p1, point& p2){
	return sqrt((p1.x - p2.x) * (p1.x - p2.x) + 
			(p1.y - p2.y) * (p1.y - p2.y));
} 

double prim(int x){
	fill(d, d + N, 0);

	priority_queue<PDI, vector<PDI>, greater<PDI> > que;
	d[x] = 0.0;
	double rst = 0.0;
	que.push(PDI(0.0, x));
	while (!que.empty()){
		PDI p = que.top();
		que.pop();
		int v = p.second;
		if (d[v] < p.first) continue;
		rst += d[v];
		used[v] = true;
		for (int u = 0; u < G[v].size(); u++){
			edge& e = G[v][u];
			if (!used[e.to] && d[e.to] > e.cost){
				d[e.to] = e.cost;
				que.push(PDI(d[e.to], e.to));
			}
		}
	}
	return rst;
}

void init(){
	for (int i = 0; i < n; i++){
		scanf("%lf %lf", &p[i].x, &p[i].y);
	}
	int from , to;
	double cost;
	ans = 0.0;
	for (int i = 0; i < m; i++){
		scanf("%d %d", &from, &to);	
		--from, --to;
		cost = calc_length(p[from], p[to]);
		edge e1, e2;
		e1.from = from, e1.to = to, e1.cost = -cost;
		e2.from = to, e2.to = from, e2.cost = -cost;
		G[from].push_back(e1);
		G[to].push_back(e2);
		ans += cost;
	}
}

int main(){
	
	scanf("%d %d", &n, &m);
	init();
	fill(used, used + N, false);
	for (int i = 0; i < n; i++){
		if (!used[i]) ans += prim(i);
	}
	printf("%.3lf\n", ans);
	return 0;
}

Measured memory_bytes: 4840
N,M = [int(i) for i in input().split()]
A = [int(j) for j in input().split()]
B = [0,A[0]]
for i in range(1,len(A)):
    B+=[A[i]+B[i]]
C = {}
X = 0
for j in B:
    if str(j%M) in C:
        X+=C[str(j%M)]
        C[str(j%M)]+=1
    else:
        C.update({str(j%M):1})
print(X)

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


int main() {
  int N,K;
  cin >> N >> K;
  
  vector<int> T(N,0);
  rep(i,N){
 	int times = 0;
    int Num = i+1;
    
  	while(Num < K){
        Num *= 2;
        T.at(i)++;
    }
 }
 
 double ans = 0.0;
 int bunbo = 0;
 rep(i,N){
 	bunbo = N * pow(2,T.at(i));

    ans += (1.0 / bunbo);
 }
 cout << fixed;
 cout << setprecision(10) << ans << endl;  
 
 return 0;
}

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

#define ll long long
#define pb push_back
#define N 1000000007
#define N2 998244353
#define nmax 200001
#define pll pair<ll,ll>
#define fill_nums(A,n) for(ll i=0;i<n;i++) scanf("%lld",&A[i]);
#define fill_edges(adj,m) for(ll i=0;i<m;i++) {ll a, b; scanf("%lld %lld",&a,&b); adj[a-1].pb(b-1); adj[b-1].pb(a-1);}
#define fill_direct(adj,m) for(ll i=0;i<m;i++) {ll a, b; scanf("%lld %lld",&a,&b); adj[a-1].pb(b-1);}

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

    vector<pll> A(n);
    vector<ll> ys(n); 
    for(int i=0;i<n;i++) {
        scanf("%lld%lld",&A[i].first, &A[i].second);
        ys[i] = A[i].second;
    }

    sort(ys.begin(), ys.end());
    for(int i=0;i<n;i++) {
        int a = lower_bound(ys.begin(), ys.end(), A[i].second)-ys.begin();
        A[i].second = a+1;
    }

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

    ll base = 1;
    while(base<=n)
        base*=2;

    vector<int> left(n,0), right(n,0);  // smaller y coord
    vector<ll> tree(2*base,0), tree2(2*base,0);
    
    for(int i=0;i<n;i++) {
        int x = base+A[i].second;
        int c = tree[x];

        while(x>1) {
            if(x%2==1)
                c += tree[x-1];
            x/=2;
        }

        left[i] = c;
        x = base+A[i].second;
        while(x>0) {
            tree[x] += 1;
            x/=2;
        }
    }

    for(int i=n-1;i>=0;i--) {
        int x = base+A[i].second;
        int c = tree2[x];

        while(x>1) {
            if(x%2==1)
                c += tree2[x-1];
            x/=2;
        }

        right[i] = c;
        x = base+A[i].second;
        while(x>0) {
            tree2[x] += 1;
            x/=2;
        }
    }

    // for(int i=0;i<n;i++)
    //     cout<<left[i]<<" ";
    // cout<<endl;

    // for(int i=0;i<n;i++)
    //     cout<<right[i]<<" ";
    // cout<<endl;

    vector<ll> pows(n+1,1);
    for(int i=1;i<=n;i++)
        pows[i] = ((ll)2*pows[i-1])%N2;

    int res = 0;
    for(int i=0;i<n;i++) {
        int sl = left[i], sr = right[i];
        int gl = i-left[i], gr = (n-i-1)-right[i];

        res = (res+pows[i]+pows[n-i-1]-1)%N2; 
        res = (res+(pows[i]-1)*(pows[n-i-1]-1))%N2;
        res = (res+(pows[i]-1)*(pows[n-i-1]-1))%N2;
        res = (res-(pows[sl]-1)*(pows[sr]-1))%N2;
        res = (res-(pows[gl]-1)*(pows[gr]-1))%N2;
        // cout<<i<<" "<<res<<endl;
    }
    cout<<(res+N2)%N2<<endl;

    return 0;
}



Measured memory_bytes: 16256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> l_l;
typedef pair<int,int> i_i;
const ll MOD=1e9+7;
const int INF=1<<30;

int dp[1010][10010];

int main(){
  int H,N;
  cin >> H >> N;
  vector<int> a(N);
  vector<int> b(N);
  rep(i,N) cin >> a[i] >> b[i];
  rep(i,N+1) rep(j,H+1) dp[i][j]=INF;
  dp[0][0]=0;
  rep(i,N){
    for(int j=0;j<=H;j++){
      chmin(dp[i+1][j],dp[i][j]);
      chmin(dp[i+1][min(j+a[i],H)],dp[i+1][j]+b[i]);
    }
  }
  cout << dp[N][H] << endl;
}


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

static const int MAX = 3600*24+60*60+60;

int main(){
    while(1){
        int N;
        cin>>N;
        if(N == 0) break;
        vector<int> V(MAX,0);

        for(int i=0; i<N; i++){
            int h1,h2,m1,m2,s1,s2;
            scanf("%d:%d:%d",&h1,&m1,&s1);
            scanf("%d:%d:%d",&h2,&m2,&s2);
            int left = 3600*h1+60*m1+s1;
            int right = 3600*h2+60*m2+s2;
            V[left]++;
            V[right]--;
        }

        int ans = 0;

        for(int i=0; i<MAX; i++){
            V[i+1] += V[i];
            ans = max(ans,V[i+1]);
        }

        cout<<ans<<endl;
    }

    return 0;
}


Measured memory_bytes: 3512
n = int(input())
R = [int(x) for x in input().split()]#リスト内包表記
def selected_sort(a,n):
    count=0
    judge=False
    for i in range(0,n-1):#一個前までやれば全てソートが完了する
        minj=i#未ソート部の先頭をminとみなす
        for j in range(i,n):
            if a[j]<a[minj]:#
                minj=j#最小インデックスの更新
                judge=True#インデックスが更新されたかどうかの判定
        a[i],a[minj]=a[minj],a[i]#最小値と未ソートの先頭をswap
        if judge:
            count+=1
        judge=False
    print(*a)
    print(count)
        

selected_sort(R,n)


Measured memory_bytes: 5612
#include<stdio.h>
#include<iostream>
 
using namespace std;
 
void InsertionSort(int *,int);
 
int main(){
  int a[100],v,n,i,j,k,l;
 
  cin >> n;
 
  for(i=0; i<n; i++)cin >> a[i];
 
  for (j=0; j<n; j++){
    v = a[j];
    k = j - 1;
    while(k >= 0 && a[k] > v){
      a[k+1] = a[k];
      k--;
      a[k+1] = v;
    }
    for(l=0; l<n-1; l++)cout << a[l] << " ";
 
    cout << a[l] << endl;
  }
 
  return 0;
  
}



Measured memory_bytes: 3092
#if !defined(__clang__) && defined(__GNUC__)
#include <bits/stdc++.h>
#else
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#endif //  !defined(__clang__) && defined(__GNUG__)
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/multi_array.hpp>

using namespace std;

int main()
{
    size_t N;
    std::cin >> N;

    std::vector<int64_t> A;
    for (size_t i = 0; i < N; ++i) {
        int64_t t;
        std::cin >> t;
        A.push_back(t);
    }

    size_t count = 1;
    int dir = 0;
    for (size_t i = 1; i < N; ++i) {
        if (dir == 0) {
            if (A[i-1] < A[i]) {
                dir = 1;
            }
            else if (A[i-1] > A[i]) {
                dir = -1;
            }
        }
        else {
            if (A[i-1] < A[i] && dir == -1) {
                count++;
                dir = 0;
            }
            else if (A[i-1] > A[i] && dir == 1) {
                count++;
                dir = 0;
            }
        }
    }
    std::cout << count << std::endl;

    return 0;
}


Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
int main(){
int  N;
  cin>>N;
  double n=1.0/2.0;
  double a=(N+1)/2/N;
if(N%2==0){
cout<<fixed<<setprecision(10)<<n<<endl;
}
else
cout<<fixed<<setprecision(10)<<(double)(N+1)/2/N<<endl;
}

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

using ll =  long long;
using pint =  pair<int,int>;

#define rep(i,n) for(int (i)=0,temp=(int)(n);(i)<temp;++(i))
#define repi(i,start,end) for(int (i)=(start),temp=(int)(end);i<(end);++(i))
#define rfor(x,v) for(const auto& (x) : (v))
#define all(x) (x).begin(),(x).end()
#define SORT(v, n) sort((v), (v)+(n))
#define vsort(v) sort((v).begin(), (v).end())
#define vfsort(v,lambda) sort(all((v)),(lambda))
#define vint vector<int>
#define vvint vector<vector<int>> //vvint v(n,vint(n))
#define vin(v) rep(i,(v).size()) {cin >> (v)[i];}
//最終奥義 #define int long long
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
//lambda: [&](int x, int y){return x<y;}
string n;int k,len;

ll nCr(int n,int r){
    if(r==1)return n;
    if(r==2)return n*(n-1)/2;
    return n*(n-1)*(n-2)/6;
}
ll solve(int i,int k,bool smaller){
    if(i==len){
        if(k==0)return 1;
        else return 0;
    }
    if(k==0)return 1;
    if(smaller){
        return nCr(len-i,k)*pow(9,k);
    }else if(n[i]=='0'){
        return solve(i+1,k,smaller);
    }else{
        ll strict_small=solve(i+1,k,true);
        ll mid=solve(i+1,k-1,true)*(n[i]-'0'-1);
        ll max=solve(i+1,k-1,false);
        return strict_small+mid+max;
    }
}

signed main(void){
    cin>>n>>k;
    len=n.size();
    cout << solve(0,k,false) << endl;
}


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

const long long INF = 1LL << 60;

int main() {
  string S;
  cin >> S;
  
  if(S == "Sunny")
    cout << "Cloudy" << endl;
    else if(S == "Cloudy")
      cout << "Rainy" << endl;
  		else if(S == "Rainy")
          cout << "Sunny" <<endl;
  
}


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

// 1ターン分プラスして，
// dp_x=1+dp_(x-2)*P/100+dp_x*(100-p)/100
// dp_x=dp_(x-2)+100/p

int main(){
  ll x; cin>>x;
  double p; cin>>p;
  if(x%2) x++;
  cout<<setprecision(15);
  cout<<x/2*100/p<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(){
	string save;
	int A = 0, B = 0;
	while (1){
		cin >> save;
		int s = save.size();
		if (save[0] == '0') break;
		for (int i = 1; i < s; i++){
			if (save[i] == 'A') A++;
			else B++;

		}
		if (A > B) A++;
		else B++;
		cout << A << ' ' << B << endl;
		A = B = 0;
	}
	return 0;
}

Measured memory_bytes: 1180
#include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define repr(i,a,n) for(int i=a;i>=n;i--)
#define INF 999999999
#define INF_M 2147483647
#define pb(a) push_back(a)
using namespace std;
typedef pair<int, int> pii;
typedef long long int ll;

int main() {
	double n;
	while(cin >> n) {
		double ret = n;
		double temp = n;
		rep(i,2,11) {
			if(i % 2 == 0) {temp *= 2; ret += temp;}
			else {temp /= 3; ret += temp;}
		}
		printf("%.8f\n",ret);
	}
}

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

int a,b,c,n,m,h,w;
string s;

int  main()
{
    cin>>s;
    a=(s[0]-'0')*1000+(s[1]-'0')*100+(s[2]-'0')*10+(s[3]-'0');
    b=(s[5]-'0')*10+(s[6]-'0');
    c=(s[8]-'0')*10+(s[9]-'0');
    if(2019<a){
        cout<<"TBD"<<endl;
    }else{
        if(4<b){
            cout<<"TBD"<<endl;
        }else{
            if(30<c){
                cout<<"TBD"<<endl;
            }else{
                cout<<"Heisei"<<endl;
            }
        }
    }
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<stdlib.h>

int main(void)
{
	char O[51], E[51];
	char *ans;
	int i;
	int olen, elen,len;
	scanf("%s", O);
	scanf("%s", E);

	olen = strlen(O);
	elen = strlen(E);
	len = olen+elen;
	ans = (char *)malloc(len);

	for (i = 0; i < len; i++) {
		if (i % 2 == 0)ans[i] = O[i/2];
		else ans[i] = E[(i + 1) / 2-1];
	}
	printf("%s", ans);
	free(ans);
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <limits.h>
#include <math.h>
int acs(const void *a, const void *b){return *(int*)a - *(int*)b;} /* 1,2,3,4.. */
int des(const void *a, const void *b){return *(int*)b - *(int*)a;} /* 8,7,6,5.. */
int cmp_char(const void *a, const void *b){return *(char*)a - *(char*)b;} /* a,b,c,d.. */
int cmp_str(const void *a, const void *b){return strcmp(*(const char **)a, *(const char **)b);} /* aaa,aab.. */
#define min(a,b) (a < b ? a: b)
#define max(a,b) (a > b ? a: b)
#define rep(i, l, r) for (int i = l; i < r; i++)
#define MAX 100001
#define MOD 1000000007

typedef long long int lli;

int main(void) {
  char c;
  scanf("%c", &c);
  if (c == 'A') printf("T\n");
  else if (c == 'T') printf("A\n");
  else if (c == 'G') printf("C\n");
  else if (c == 'C') printf("G\n");
  return 0;
}


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

int main() {
    int N; cin >> N;
    vector<ll> vec(N + 1);
    int a;
    int cnt = 0;
    for (int i = 0; i < N; i++){
        cin >> a;
        if (a <= N){
        vec[a] = vec[a] + 1;
        }
        else {
        cnt++;
        }
    }
    for (int i = 1; i < N + 1; i++){
        if (vec[i] - i >= 0){
            cnt += vec[i] - i;
        }
        else{
            cnt += vec[i];
        }
    }
    cout << cnt << endl;
}



Measured memory_bytes: 1024
/*---> 22 December 2019 <--- > 17:26:34 <---*/
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// #pragma GCC optimize("unroll-loops")
// #pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
//#pragma GCC target ("sse4")
#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;
//template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
#define int long long
#define F first
#define S second
#define mod 1000000007
#define inf (int)1e18+5
#define sz(x) (int)x.size()
#define PI 3.141592653589793238510
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define __ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define vi vector<int>
#define vpii vector<pair<int,int> > 
#define vvi vector<vector<int> >
#define PRINT_TIME cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s." <<endl;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename   enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
typedef long double ld;
typedef pair<int,int> pii;
///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
const int N=1e5+5;

int32_t main(){__
	int a[2];
	cin>>a[0]>>a[1];
	for(int i=1;i<=3;i++){
		if(i==a[0] || i==a[1])
			continue;
		cout<<i<<"\n";
		break;
	}
return 0;
}

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

using namespace std;

int64_t calc(const std::vector<int>& as) {
  int64_t ret = 0;
  int prev_a = 0;
  int count = 0;
  for (int i = 0; i < as.size(); i++) {
    auto const a = as[i];
    if (a == prev_a) {
      count++;
      continue;
    }
    if (count < prev_a) {
      ret += count;
    } else {
      ret += count - prev_a;
    }
    count = 1;
    prev_a = a;
  }

  if (count) {
    if (count < prev_a) {
      ret += count;
    } else {
      ret += count - prev_a;
    }
  }

  return ret;
}

int main() {
  int n;
  std::cin >> n;
  std::vector<int> as(n);
  for (int i = 0; i < n; i++) {
    std::cin >> as[i];
  }
  std::sort(as.begin(), as.end());
  std::cout << calc(as) << std::endl;
  return 0;
}


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


int main(void){
    int n;
    cin >> n;
    vector<int>p;
    rep(i,n){
        int x;
        cin >> x;
        p.push_back(x);
    }
    sort(p.begin(),p.end(),greater<int>());
    ll ans = p[0]/2;
    for(int i=1;i<n;i++){
        ans += p[i];
    }
    cout << ans <<endl;
    
    return 0;
}







































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

int main()
{
	
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	if(c<=a&&d<=b&&d>=a)
	cout<<d-a<<endl;
	else if(c>=a&&c<=b&&d>=a&&d<=b)
	cout<<d-c<<endl;
	else if(c>=a&&d>=b&&c<=b)
	cout<<b-c<<endl;
	else if(c<=a&&d>=b)
	cout<<b-a<<endl;
	else
	cout<<0<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;


int main(){

	int n, w,v;
	int hei, num,anum;
	double ans;
	int cnt[101];

	while (1){
		cin >> n >> w;
		if (n == 0 && w == 0) break;

		for (int i = 0; i < 101; i++) cnt[i] = 0;

		for (int i = 0; i < n; i++){
			cin >> v;
			cnt[v / w]++;
		}

		num = 0;
		hei = -1;
		for (int i = 100; i >= 0; i--){
			if (cnt[i] != 0||num!=0) num++;
			if (cnt[i] > hei) hei = cnt[i];
		}

		ans = 0;
		num--;
		anum = num;
		for (int i = 0; i < 101; i++){
			if (cnt[i] != 0){
				//cout << cnt[i] << "," << anum << "," << hei << "," << i <<","<<ans<< endl;
				ans += ((double)anum / num)*((double)cnt[i] / hei);
			}
			anum--;
		}
		ans += 0.01;

		cout << ans << endl;

	}
	return 0;
}

Measured memory_bytes: 1232
#include <stdio.h>
#include <stdlib.h>
int main(void){
    int i,j,k,n;
    char ch;
    int a[4][13];
    scanf("%d",&n);
    for(k=0;k<4;k++){
        for(j=0;j<13;j++){
            a[k][j]=j+1;
        }
    }
    for(i=0;i<n;i++){
        scanf("%c", &ch);
        scanf("%c %d",&ch,&j);
        if(ch=='S') a[0][j-1]=0;
        if(ch=='H') a[1][j-1]=0;
        if(ch=='C') a[2][j-1]=0;
        if(ch=='D') a[3][j-1]=0;
    }
    for(k=0;k<4;k++){
        for(j=0;j<13;j++){
            if(a[k][j]!=0){
            if(k==0) printf("S %d\n",a[k][j]);
            if(k==1) printf("H %d\n",a[k][j]);
            if(k==2) printf("C %d\n",a[k][j]);
            if(k==3) printf("D %d\n",a[k][j]);
            }
        }
    }
    return 0;
}


Measured memory_bytes: 2752
#include<bitset>
#include<math.h>
#include<limits.h>
#include<iostream>
#include<string>
#include<vector>
#include<cstdio>
#include<sstream>
#include<list>
#include<queue>
#include<algorithm>
#include<functional>
#include<map>
#include<set>
#include<utility>
#include<initializer_list>
#include<tuple>
#include<regex>
using namespace std;
#define ull unsigned long long
#define ll long long
#define rep(i, a, n) for(int i=(a);i<(int)(n);i++)
#define repc(i, a, n) for(int i=(a);i<=(int)(n);i++)
#define all(t) t.begin(), t.end()
#define rall(t) t.rbegin(), t.rend()
#define mat(type, row, col, init) vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout<<(cond? "Yes":"No")<<endl;
#define YES(cond) cout<<(cond? "YES":"NO")<<endl;
#define DBG(str) cerr<<(str)<<endl;
int ketawa(int n) {
	int cnt = 0;
	while (n > 0) {
		cnt += n % 10;
		n /= 10;

	}
	return cnt;
}
int main() {
	int n;
	cin >> n;
	int mi = INT32_MAX;
	repc(i, 1, n/2+1) {
		int a = n - i;
		int b = i;
		mi = min(mi, ketawa(a) + ketawa(b));

	}
	cout << mi;
	return 0;
}





Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
string a[200000];
string b[200000];
int main()
{
	int n, i,k,sum,x;
	string flag;
	scanf("%d", &n);
	for (i = 0; i < n; i++)
		cin >> a[i];
	sort(a, a + n);
	flag = a[0]; sum = 0; k = 0; x = 0;
	for (i = 0; i < n; i++)
	{
		if (flag == a[i])
			sum++;
		else
		{
			flag = a[i];
			if (sum > x)
			{
				k = 0;
				b[k++] = a[i-1];
				x = sum;
			}
			else if (sum == x)
				b[k++] = a[i-1];
			sum = 1;
		}
	}
	if (sum > x)
	{
		k = 1;
		b[0] = a[n - 1];
	}
	else if(sum==x&&b[k-1]!=b[n-1])
	{
		b[k++] = a[n - 1];
	}
	for (i = 0; i < k; i++)
		cout << b[i] << endl;
	return 0;
}

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

int main() {
  int a,b;
 
  cin >> a>>b ;
 if ((a+b)%2 == 0){
   cout << (a+b)/2 << endl;
 }
  else{
  cout << "IMPOSSIBLE" <<endl;
}
 }
  




Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <functional>
#include <sstream>
#include <complex>
#include <climits>
using namespace std;

#define REP(i,a,n) for(int i=(a);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define EPS 1e-8

#define DEB 0
#define SIZE 1000000

int d;

string parse(char *p){
#if DEB
printf("start:%c\n",*p);
#endif
	if( *p=='\0' ) return "";
	if( isdigit(*p) ){
		int num=0;
		for(;*p!='\0' && isdigit(*p);p++){
			num = 10*num + (*p-'0');
		}
		char *tp = p;
		int x = 0;
		if( *tp=='(' ){
			for(;;){
				if( *tp=='(' )x++;
				else if( *tp==')' )x--;
				tp++;
				if( x==0 )break;
#if DEB
printf("x:%d  %c\n",x,*tp);
#endif
			}
		}
		
#if DEB
printf("p:%c  tp:%c\n",*(p+1),*tp);
#endif
		string tmp;
		if( p!=tp ){
			string sub = parse(p+1);
			if( sub.size()>d ) return sub;
			rep(i,num){
				tmp += sub;
				if( tmp.size()>d ) return tmp;
			}
			return tmp + parse(tp);
		}else{
			tmp = string(num,*p);
			return tmp + parse(tp+1);
		}
		
	}else if( isalpha(*p) ){
		return string(1,*p)+parse(p+1);
	}else if( *p==')' ){
		return "";
	}
#if DEB
printf("error : %c\n",*p);
#endif
	return "";
}

int main(){
	char in[128];
	while(scanf(" %s %d ",in,&d),strcmp(in,"0")|d){
		string ans = parse(in);
		if( d>=ans.size() ){
			puts("0");
		}else{
			printf("%c\n",ans[d]);
		}
#if DEB
		cout << "ans: " << ans << endl;
#endif
	}
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

#define DEBUG(x) cout<<#x<<": "<<x<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

#define CHMIN(a, b) a=min((a), (b))
#define CHMAX(a, b) a=max((a), (b))

const ll MOD=1000000007ll;
// const ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s;
	cin>>s;
	REP(i, s.size()-8){
		cout<<s[i];
	}
	return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
def ii(): return int(input())
def mi(): return map(int, input().rstrip().split())
def lmi(): return list(map(int, input().rstrip().split()))
def li(): return list(input().rstrip())
# template


b = input().rstrip()

if b == 'A':
    print('T')
elif b == 'T':
    print('A')
elif b == 'C':
    print('G')
elif b == 'G':
    print('C')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
#define ep emplace_back
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
constexpr int mod=1000000007;
constexpr int mod1=998244353;
vector<int> dx={0,1,0,-1},dy={-1,0,1,0};
bool inside(int y,int x,int h,int w){
	if(y<h && y>=0 && x<w && x>=0) return true;
	return false;
}





int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;cin >> s;
	int n = s.size();
	if(s.at(0) == s.at(n - 1)) n--;
	if(n % 2 == 0) cout << "Second" << endl;
	else cout << "First" << endl;
}


Measured memory_bytes: 512
#include <cmath>
#include <cstdlib>
#include <cstdio>
#include <climits>
#include <functional>
#include <bitset>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <set>
#include <map>
using namespace std;

int main() {
    string s;
    cin>>s;
    if (s.front()==s.back()) {
        int n=s.length()-2;
        if (!(n%2)) cout<<"First"<<endl;
        else cout<<"Second"<<endl;
        return 0;
    }
    int n=s.length()-2;
    if (n%2) cout<<"First"<<endl;
    else cout<<"Second"<<endl;
    return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define hackcyborg shresth_walia
#define ll  long long
#define ld  long double
#define pb push_back
#define mod 1000000007
#define M_PI 3.141592653589
#define IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define int long long
ll binpow(ll a,ll b,ll m=mod) {
    a %= m;
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}
ll a[10000001]={0};
main()
{
     IO
     ll n;
     cin>>n;
     ll ans=0;
     for(int x=1;x<=n;x++)
        {
        for(int y=x;y<=n;y+=x)
            ++a[y];
            ans+=(x*a[x]);
        }
        cout<<ans;
}


Measured memory_bytes: 81776
N = int(input())
K = int(input())
S = str(N)
L = len(S)

dp = [[[1, 0], [0, 0], [0, 0], [0, 0]] for i in range(L)]
dp[0] = [[1, 0], [int(S[0])-1, 1], [0, 0], [0, 0]]

for l in range(1,L):
    s = int(S[l])
    if s == 0:
        for k in range(1,4):
            dp[l][k][1] += dp[l-1][k][1]
    else:
        for k in range(1,4):
            dp[l][k][1] += dp[l-1][k-1][1]
            dp[l][k][0] += dp[l-1][k][1]
    for k in range(1,4):
        dp[l][k][0] += dp[l-1][k-1][0]*9 + dp[l-1][k][0]
        dp[l][k][0] += dp[l-1][k-1][1]*max(0,s-1)

print(sum(dp[L-1][K]))

Measured memory_bytes: 3064
#include<stdio.h>
#include<string.h>
int main(){
  char s[1027],*w;
  int l,f=0;
  fgets(s,1025,stdin);
  s[strlen(s)-1]=0;
  w=strtok(s," ,.");
  l=strlen(w);
  if(2<l&&l<7){
    printf("%s",w);
    f=1;
  }
  while(w=strtok(NULL,(s," ,."))){
    l=strlen(w);
    if(2<l&&l<7){
      if(f)printf(" ");
      f=1;
      printf("%s",w);
    }
  }
  printf("\n");
  return 0;
}

Measured memory_bytes: 524
#include<cstdio>
#define WHITE 0
#define GRAY  1
#define BLACK 2

void InitializeBoolMatrix(int nmbr_of_rows, int nmbr_of_columns, bool mtrx[][100]){
	for (int row = 0; row < nmbr_of_rows; ++row) {
		for (int column = 0; column < nmbr_of_columns; ++column)
			mtrx[row][column] = false;
	}
}

void ListToMatrix(int number_of_vertices, bool mtrx[][100]){
	int vertex_from, vertex_to, degree_out;	
	for (int vertex_i = 0; vertex_i < number_of_vertices; ++vertex_i) {
		scanf("%d %d", &vertex_from, &degree_out);
		vertex_from--; //0?????????????????????
		for (int vertex_out_i = 0; vertex_out_i < degree_out; ++vertex_out_i) {
			scanf("%d", &vertex_to);
			vertex_to--; //0?????????????????????
			mtrx[vertex_from][vertex_to] = true;
		}
	}
}

bool adjmtrx[100][100];

void BuildAdjacencyMatrix(int n){
	InitializeBoolMatrix(n, n, adjmtrx);
	ListToMatrix(n, adjmtrx);
}

int color[100];
int time;
int discoveredtime[100];
int finishedtime[100];

void Dfs(int present_vertex, int n){
	int pv = present_vertex;
	color[pv] = GRAY;
	discoveredtime[pv] = ++time;
	for(int v = 0;v < n;v++){
		if(adjmtrx[pv][v] && color[v] == WHITE){
			Dfs(v, n);
		}
	}
	color[pv] = BLACK;
	finishedtime[pv] = ++time;
}

void DfsInit(int n){
	for (int i = 0; i < n; ++i)
		color[i] = WHITE;
	time = 0;
}

int main(){
	int number_of_vertices;
	scanf("%d", &number_of_vertices);
	int n = number_of_vertices;
	BuildAdjacencyMatrix(n);
	DfsInit(n);
	for (int vertex_i = 0; vertex_i < n; ++vertex_i){
		if(color[vertex_i] == WHITE)
		Dfs(vertex_i, n);
	}
	for (int id = 0; id < n; ++id)
		printf("%d %d %d\n", id+1, discoveredtime[id], finishedtime[id]);
	return 0;
}

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

int main()
{
    string S; cin >> S;
    string s = "";
    int Q; cin >> Q;
    
    while(Q--)
    {
        int q; cin >> q;
        if (q == 1)   
        {
            swap(S, s);
        }
        else
        {
            int F; cin >> F;
            string C; cin >> C;
            if (F == 1)
                s += C;
            else
                S += C;
            
        }
    }
    reverse(s.begin(), s.end());
    cout << s << S;
    return 0;
}

Measured memory_bytes: 964