akhauriyash/Code-Regression huggingface dataset:
#include "atcoder/dsu"
#include <bits/stdc++.h>
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rp(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

void solve(){
    ll n,q;
    cin >> n >> q;
    atcoder::dsu uf(n);
    while(q--){
        ll t,u,v;
        cin >> t >> u >> v;
        if(t==0){
            uf.merge(u,v);
        }else{
            if(uf.same(u,v)){
                print(1);
            }else{
                print(0);
            }
        }
    }
    return;
}
int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    solve();
    return 0;
}

Measured memory_bytes: 3796
/*
ID: i_love_7
LANG: C++
TASK: 
*/
#include <iostream> 
#include <cstdio> 
#include <fstream> 
#include <algorithm> 
#include <cmath> 
#include <deque> 
#include <vector> 
#include <queue> 
#include <string> 
#include <cstring> 
#include <map> 
#include <stack> 
#include <set> 
#define INF 0x3f3f3f3f
typedef long long ll;
//orz yht
using namespace std;
string i_s(int x){
	if(x==0)
	return "0";
	string ret="";
	while(x){
		ret=ret+(char)(x%10+'0');
		x/=10;
	}
	reverse(ret.begin(),ret.end());
	return ret;
}
string add(string a,string b){
	if(a=="")
	a="0";
	if(b=="")
	b="0";
	if(a.length()<b.length())
	swap(a,b);
	while(b.length()<a.length()){
		b='0'+b;
	}
	for(int i=0;i<a.length();i++){
		a[i]=a[i]+(b[i]-'0');
	}
	bool big=false;
	for(int i=a.length()-1;i>=0;i--){
		if(big){
			a[i]++;
		}
		big=false;
		if(a[i]>'9'){
			a[i]=a[i]-10;
			big=true;
		}
	}
	if(big)
	a='1'+a;
	return a;
}
string mul(string a,string b){
	vector<int> va,vb;
	if(a=="0" || b=="0")
	return "0";
	string ans;
	for(int i=0;i<a.length();i++){
		va.push_back(a[i]-'0');
	}
	for(int i=0;i<b.length();i++){
		vb.push_back(b[i]-'0');
	}
	reverse(va.begin(),va.end());
	reverse(vb.begin(),vb.end());
	vector<int> res;
	res.clear();
	res.resize(1005);
	for(int i=0;i<a.length();i++){
		for(int j=0;j<b.length();j++){
			res[i+j]+=(va[i]*vb[j]);
		}
	}
	for(int i=0;i<1005;i++){
		if(res[i]>9){
			res[i+1]+=(res[i]/10);
			res[i]%=10;
		}
	}
	for(int i=0;i<1005;i++){
		ans+=(res[i]+'0');
	}
	reverse(ans.begin(),ans.end());
	int k=0;
	while(ans[k]=='0'){
		k++;
	}
	ans=ans.substr(k);
	return ans;
}
int n;
int main(){
	//freopen("inout.in","r",stdin);
	//freopen("output.out","w",stdout);
    cin>>n;
    cout<<n*n*n;
	//system("pause");
	return 0;
}

Measured memory_bytes: 256
"""
N = list(map(int,input().split()))
S = [str(input()) for _ in range(N)]
S = [list(map(int,list(input()))) for _ in range(h)] 
print(*S,sep="")
"""

import sys
sys.setrecursionlimit(10**6)
input = lambda: sys.stdin.readline().rstrip()

n = input()
if n[-1]=="2" or n[-1]=="4" or n[-1]=="5" or n[-1]=="7" or n[-1]=="9":
    print("hon")
elif n[-1]=="0" or n[-1]=="1" or n[-1]=="6" or n[-1]=="8":
    print("pon")
else:
    print("bon")

Measured memory_bytes: 9092
import java.io.*;
import java.io.ObjectInputStream.*;
import java.util.*;
import java.util.regex.*;


public class Main {

	final static long MOD = (long)1e9+7;
	//final static long MOD = 998244353;

	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static long cnt=0;
	public static PrintWriter pw = new PrintWriter(System.out);
	public static void main(String[] args) throws Exception {
		slove(args);
		if(in!=null){
			in.close();
		}
		pw.flush();
		pw.close();
	}

	public static void slove(String[] args) throws Exception{
		int N = nextInt();

		pw.println(dfs("0",N));
	}

	public static int dfs(String n,int N) {
		int ans = 0;
		String[] p = new String[] {"3","5","7"};
		for(String x:p) {
			String now = n+x;
			if(Long.parseLong(now)>N) {
				continue;
			}
			boolean flg = true;
			for(String y:p) {
				if(now.indexOf(y)<0) {
					flg=false;
					break;
				}
			}
			if(flg) {
				ans++;
			}
			ans+=dfs(n+x,N);
		}
		return ans;

	}


	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}


}



Measured memory_bytes: 44888
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<n;++i)
#define rep2(i,a,b) for (ll i=a;i<b;++i)
const ll MOD=1e9+7;
const ll INF=1e9;
const ll IINF=1e18;
const double EPS=1e-8;
const double pi=acos(-1);

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;
}

int main(){
    int N;
    cin >> N;
    vector<vector<Pii>> G(N);
    rep(i,N-1){
        int a,b;
        cin >> a >> b;
        --a,--b;
        G[a].push_back(Pii(b,i));
        G[b].push_back(Pii(a,i));
    }
    int color=0;
    rep(i,N) chmax(color,(int)G[i].size());
    cout << color << endl;
    vector<int> ans(N-1);
    queue<pair<Pii,int>> que;
    que.push(make_pair(Pii(0,0),-1));
    while(!que.empty()){
        pair<Pii,int> pa=que.front();
        que.pop();
        Pii p=pa.first;
        int par=pa.second;
        int v=p.first;
        int c=1;
        rep(i,G[v].size()){
            Pii q=G[v][i];
            if (q.first==par) continue;
            if (c==p.second) ++c;
            ans[q.second]=c;
            que.push(make_pair(Pii(q.first,c),v));
            ++c;           
        }
    }
    rep(i,N-1) cout << ans[i] << endl;
}

Measured memory_bytes: 7040
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <fstream>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

ll sol(ll n) {
    if (n == 1) return 1;
    return sol(n / 2) * 2 + 1;
}

int main() {
    ios::sync_with_stdio(false);
    int h, n, a[1003] = {}, b[1003] = {}, d[20004] = {}, z = mod;
    cin >> h >> n;
    for (int i = 1; i <= 20000; i++) d[i] = mod;
    for (int i = 0; i < n; i++) cin >> a[i] >> b[i];
    for (int i = 0; i < n; i++) {
        for (int j = a[i]; j <= 20000; j++) d[j] = min(d[j], d[j - a[i]] + b[i]);
    }
    for (int i = h; i <= 20000; i++) z = min(z, d[i]);
    cout << z;
}


Measured memory_bytes: 3724
H , W = map(int,raw_input().split())
target = 'snuke'
targetH,targetW = 0 , 0
alpabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'

for i in xrange(H):
    nowLine = raw_input().split()
    if target in nowLine:
        taregtW = nowLine.index(target)
        targetH = i+1
        break

print(alpabet[taregtW]+str(targetH))

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

int main(){
    int N;
    cin>>N;
    vector<tuple<string,int,int>> sp(N);
    for(int i=0;i<N;i++){
        string s; int p; cin>>s>>p;
        sp[i]=make_tuple(s,p,i+1);
    }
    sort(sp.begin(),sp.end());
    vector<int> ans;
    int idx=0;
    while(idx!=N){
        string s=get<0>(sp[idx]);
        for(int i=idx+1;i<=N;i++){
            if(i==N||s!=get<0>(sp[i])){
                for(int j=i-1;j>=idx;j--){
                    ans.push_back(get<2>(sp[j]));
                }
                idx=i;
                break;
            }
        }
    }
    for(int i=0;i<ans.size();i++)
        cout<<ans[i]<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define ull unsigned long long
#define endl '\n'
#define ll long long
const int N = 2e5 + 5;
pair<ll,ll> x[N];
ll mx[N], st[N * 4], dp[N], sum[N];
set<pair<ll,ll>, greater<pair<ll,ll>>> s;
set<pair<ll,ll>> ok;
ll mod = 998244353;
bool cmp(pair<ll,ll> a, pair<ll,ll> b){
        return a.first < b.first;
}
void upd(ll k, ll l, ll r, ll x, ll val){
        if (x > r || x < l) return;
        if (l == r){
                st[k] = val;
                return;
        }
        ll mid = (l + r) >> 1;
        upd(k << 1, l, mid, x, val);
        upd(k << 1 | 1, mid + 1, r, x, val);
        st[k] = max(st[k << 1 | 1], st[k << 1]);
}
ll get(ll k, ll l, ll r, ll x, ll y){
        if (x > r || y < l) return -1e18;
        if (x <= l && y >= r) return st[k];
        ll mid = (l + r) >> 1;
        return max(get(k << 1, l, mid, x, y), get(k << 1 | 1, mid + 1, r, x, y));
}
int main(){
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
        //freopen("test.txt", "r", stdin);
        ll n;
        cin >> n;
        for (int i = 1; i <= n; i++){
                cin >> x[i].first >> x[i].second;
        }
        sort(x + 1, x + n + 1, cmp);
        for (int i = 1; i <= n; i++){
                upd(1, 1, n, i, x[i].first + x[i].second);
                s.insert({x[i].first, i});
                ok.insert({x[i].first, i});
        }
        ok.insert({1e18, n + 1});
        dp[n + 1] = 0;
        sum[n + 1] = 0;
        ll ans = 0;
        for (int i = n; i >= 1; i--){
                auto it = s.lower_bound({x[i].first + x[i].second - 1, 1e18});
                ll cur = get(1, 1, n, i, (*it).second);
                upd(1, 1, n, i, cur);
                auto it2 = ok.lower_bound({cur, -1e18});
                dp[i] = (sum[(*it2).second] + 1) % mod;
                sum[i] = (sum[i + 1] + dp[i]) % mod;
        }
        for (int i = 1; i <= n; i++){
                ans += dp[i];
                ans %= mod;
        }
        cout << ans + 1;
}

Measured memory_bytes: 37248
N,A,B,C,D = gets.split.map(&:to_i)
S = gets.chomp

# 区間x,yにおける連続するsの最大数
# ただし、x,yは自然数
def f(x,y,s)
  S[x-1,y-x+1]
    .chars
    .slice_when{|a,b|a!=b}
    .to_a
    .select{|v|v[0]==s}
    .map(&:size)
    .max || 0
end

def g
  f(B,D,"#") < 2 && f(A,C,"#") < 2
end

def h
  f(B-1,[N, D+1].min,".") > 2
end

if C < D
  puts g ? "Yes" : "No"
else
  puts g && h ? "Yes" : "No"
end


Measured memory_bytes: 30992
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <algorithm>
#include <functional>
#include <set>
#include <map>
#include <list>
#define debug(x) cout << #x << ": " << (x) << endl
using namespace std;

const double PI  = 3.141592653589793238463;
const int INF = 1000000007;

using ull = unsigned long long;
using ll = long long;

using Int = int;
using Double = double;

using P = pair<Int, Int>;
using V = vector<Int>;
using M = vector<V>;

int solve(int w, int a, int b){
    if(a + w < b){
        return b - (a + w);
    }else if(b + w < a){
        return a - (b + w);
    }else{
        return 0;
    }
}

int main(int argc, char* argv[]){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int w, a, b;
    cin >> w >> a >> b;
    cout << solve(w, a, b) << endl;

    return 0;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))


sum = 0
present = 0
for s, t in enumerate(a):
  sum += abs(t-present)
  present = t
sum += abs(present-0)

for i, each in enumerate(a):
  if i == 0:
    prev = 0
    tmp = each
    next = a[i+1]
  elif i == len(a)-1:
    prev = a[i-1]
    tmp = each
    next = 0
  else:
    prev = a[i-1]
    tmp = each
    next = a[i+1]

  before = abs(prev-tmp) + abs(tmp - next)
  after = abs(prev - next)

  print(sum - before + after)


Measured memory_bytes: 14048
#include<iostream>
#include<string>
#include <vector>
#include<stack>
#include<queue>
#include<map>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<bitset>
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using vs = vector<string>;
using pii = pair<int, int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,m,n) for(int i=m;i<n;i++)
#define vsort(v) sort(v.begin(), v.end())
#define rv(v) reverse(v.begin(), v.end())
#define ll long long
#define PI 3.141592653589793
using vll = vector<ll>;
using Graph = vii;
const ll MOD = 1e9 + 7;

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

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

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>

#include <bits/stdc++.h>
#include <cmath>
#include <limits>

using namespace std;

long long N, x;
vector<long long> a;

int main(int argc, char* argv[]){
	cin.tie(0);
	ios::sync_with_stdio(false);

	long long ans = 0;
	cin >> N >> x;
	for(int i=0; i<N; i++){
		long long v;
		cin >> v;
		if(v > x){
			ans += (v - x);
			v = x;
		}
		a.push_back(v);
	}
	a.push_back(0);

	for(int i=1; i<N; i++){
		long long d = x - a[i - 1];
		if(a[i] > d){
			ans += (a[i] - d);
			a[i] = d;
		}
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 1400
from collections import defaultdict
class UnionFind:
  
  def __init__(self, n):
    self.par = [i for i in range(n)]
    self.rank = [0]*n
  
  def find(self, x):
    if self.par[x]==x:
      return x
    else:
      self.par[x] = self.find(self.par[x])
      return self.par[x]
  
  def unite(self, x, y):
    x = self.find(x)
    y = self.find(y)
    if x==y:
      return
    if self.rank[x]<self.rank[y]:
      self.par[x] = y
    else:
      self.par[y] = x
      if self.rank[x]==self.rank[y]:
        self.rank[x] += 1
  
  def same(self, x, y):
    return self.find(x)==self.find(y)
  
N, M = map(int, input().split())
h = [int(i)-1 for i in input().split()]
dic1 = defaultdict(list)
dic2 = defaultdict(list)
u = UnionFind(N)
for i in range(M):
  a, b = map(int, input().split())
  u.unite(a-1,b-1)

for c in range(N):
  p = u.find(c)
  dic1[p] += [c]
  dic2[p] += [h[c]]
ans = 0
for p in dic1.keys():
  dic1[p].sort()
  dic2[p].sort()
  i = 0
  j = 0
  while i<len(dic1[p]) and j<len(dic2[p]):
    if dic1[p][i]==dic2[p][j]:
      i += 1
      j += 1
      ans += 1
    elif dic1[p][i]<dic2[p][j]:
      i += 1
    else:
      j += 1
    
print(ans)

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

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

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

int main()
{
    int A, B, C;
    cin >> A >> B >> C;
    int max = std::max(A, std::max(B, C));
    int min = std::min(A, std::min(B, C));
    if (C == min || C == max)
        cout << "No" << endl;
    else
        cout << "Yes" << endl;
    return 0;
}

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

typedef vector< long long int > vi;
typedef vector< vi > vvi;
typedef pair< int,int > ii;
#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define forn(i,n) for(int i=0;i<n;++i)
#define fortr(i,v) for(auto &i:v)
#define set(n) __builtin_popcount(n)


typedef struct{
	
	int a,b,c;

}happy;
int main()
{
	int n;
	cin>>n;
    happy *A=new happy[n];
    forn(i,n)
    {
    	cin>>A[i].a>>A[i].b>>A[i].c;
    }
    happy*dp=new happy[n];
    dp[0]=A[0];

    for(int i=1;i<n;++i)
    {
        dp[i].a=max(dp[i-1].b,dp[i-1].c)+A[i].a;
        dp[i].b=max(dp[i-1].c,dp[i-1].a)+A[i].b;
        dp[i].c=max(dp[i-1].a,dp[i-1].b)+A[i].c;
    }
    int j=n-1;
    cout<<max(max(dp[j].a,dp[j].b),dp[j].c)<<endl;

}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<int> vect(n);
  for(int i=0;i<n;++i){
    cin>>vect[i];
  }
  sort(vect.begin(),vect.end());
  
  int sum=0;
  for(int i=0;i<n-1;++i){
    sum+=vect[i];
  }
  if(sum>vect[n-1]){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }




}
  


Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp::{min,max};
#[allow(unused_imports)]
use std::collections::BTreeMap;
#[allow(unused_imports)]
use std::ops::*;
#[allow(unused_imports)]
use std::collections::BinaryHeap;

fn main() {
    let ss: Vec<u8> = read_line().bytes().collect();
    let ts: Vec<u8> = read_line().bytes().collect();
    let n = ss.len() as usize;
    for i in 0..n {
        let mut ok = true;
        for k in 0..n {
            if ss[k] != ts[(i+k)%n] {
                ok = false;
            }
        }
        if ok {
            println!("Yes");
            return;
        }
    }
    println!("No");
}

#[allow(dead_code)]
fn read_line() -> String {
    let mut ret = String::new();
    std::io::stdin().read_line(&mut ret).ok();
    ret.pop();
    return ret;
}

#[allow(dead_code)]
fn read_i64() -> i64 {
    let ss = read_line();
    return ss.parse::<i64>().unwrap();
}

#[allow(dead_code)]
fn read_vec_i64() -> Vec<i64> {
    let mut res = vec![];
    let ss = read_line();
    for ts in ss.split_whitespace() {
        let x = ts.parse::<i64>().unwrap();
        res.push(x);
    }
    return res;
}

use std::fmt::Display;
#[allow(dead_code)]
fn write_vec<T: Display>(xs: &Vec<T>) {
    if xs.len() == 0 {
        println!("");
        return;
    }
    print!("{}", xs[0]);
    for i in 1..xs.len() {
        print!(" {}", xs[i]);
    }
    println!("");
}


Measured memory_bytes: 4352
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);
        int n = stdIn.nextInt();
        int[] b = new int[n-1];
        for(int i = 0;i<n-1;i++) {
            b[i] = stdIn.nextInt();
        }
        int count = 0;
        int[] a = new int[n];
        for(int i = 0;i<b.length;i++) {
            if(i==0)    {a[i] = b[i]; a[i+1] = b[i];}
            else {
                a[i] = Math.min(a[i],b[i]);
                a[i+1] = b[i];
            }
        }
        for(int i = 0;i<a.length;i++) {
            count += a[i];
        }
        System.out.println(count);
    }
}

Measured memory_bytes: 21716
main :: IO ()
main = getLine >>= print . solve . drop 1 . reverse
 
solve :: String -> Int
solve s
    | even $ length s = solver s
    | otherwise = solver ss
        where _:ss = s
 
solver :: String -> Int
solver s = if p == q then len else solver ss
    where
        len = length s
        (p, q) = splitAt (len `div` 2) s
        _:_:ss = s

Measured memory_bytes: 892
// AOJ 1281 The Morning after Halloween
// 2018.3.3 bal4u
 
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

int  w, h;
char map[18][18];
int  n;
char sr[3], sc[3], gr[3], gc[3];
char r[3], c[3], nr[3], nc[3];
int  mv[5][2] = {{-1,0},{0,1},{1,0},{0,-1},{0,0}};
short mk[16][16][16][16][16][16];

#define QMAX 300000
typedef struct { char r[3], c[3]; short t; } QUE;
QUE que[QMAX]; int qsize;

#define PARENT(i) ((i)>>1)
#define LEFT(i)   ((i)<<1)
#define RIGHT(i)  (((i)<<1)+1)

void min_heapify(int i)
{
	int l, r, min;
	QUE qt;

	l = LEFT(i), r = RIGHT(i);
	if (l < qsize && que[l].t < que[i].t) min = l; else min = i;
	if (r < qsize && que[r].t < que[min].t) min = r;
	if (min != i) {
		qt = que[i], que[i] = que[min], que[min] = qt;
		min_heapify(min);
	}
}

void deq()
{
	que[0] = que[--qsize];
	min_heapify(0);
}

void enq(short t)
{
	int i, j, min;
	QUE qt;

	i = qsize++;
	for (j = 0; j < n; j++) que[i].r[j] = nr[j], que[i].c[j] = nc[j]; 
	que[i].t = t;
	while (i > 0 && que[min = PARENT(i)].t > que[i].t) {
		qt = que[i], que[i] = que[min], que[min] = qt;
		i = min;
	}
}

int check(int i, int j)
{
	if (nr[i] == nr[j] && nc[i] == nc[j]) return 1;
	if (r[i] == nr[j] && c[i] == nc[j] && r[j] == nr[i] && c[j] == nc[i]) return 1;
	return 0;
}

void _enq(int t)
{
	if (t < mk[nr[0]][nc[0]][nr[1]][nc[1]][nr[2]][nc[2]]) {
		mk[nr[0]][nc[0]][nr[1]][nc[1]][nr[2]][nc[2]] = t;
		enq(t);
	}
}

int dijkstra()
{
	int i, j, k, t;

	memset(mk, 0x55, sizeof(mk));
	for (i = n; i < 3; i++) r[i] = c[i] = nr[i] = nc[i] = 0;
	for (i = 0; i < n; i++) nr[i] = sr[i], nc[i] = sc[i];
	qsize = 0;
	mk[nr[0]][nc[0]][nr[1]][nc[1]][nr[2]][nc[2]] = 0;
	enq(0);

	while (qsize) {
		for (i = 0; i < n; i++) r[i] = que[0].r[i], c[i] = que[0].c[i];
		t = que[0].t, deq();

		for (i = 0; ; i++) {
			if (i == n) return t;
			if (gr[i] != r[i] || gc[i] != c[i]) break;
		}

		if (mk[r[0]][c[0]][r[1]][c[1]][r[2]][c[2]] < t) continue;
		for (i = 0; i < 5; i++) {
			nr[0] = r[0] + mv[i][0], nc[0] = c[0] + mv[i][1];
			if (map[nr[0]][nc[0]] == '#') continue;

		if (n >= 2) for (j = 0; j < 5; j++) {
			nr[1] = r[1] + mv[j][0], nc[1] = c[1] + mv[j][1];
			if (map[nr[1]][nc[1]] == '#' || check(0, 1)) continue;

		if (n == 3) for (k = 0; k < 5; k++) {
			nr[2] = r[2] + mv[k][0], nc[2] = c[2] + mv[k][1];
			if (map[nr[2]][nc[2]] == '#' || check(0, 2) || check(1,2)) continue;
			_enq(t+1);
		} else _enq(t+1);
		} else _enq(t+1);
		}
	}
	return -1;
}

int main()
{
	int i, r, c;
	char buf[20], *p;

	while (fgets(buf, 20, stdin) && *buf != '0') {
		sscanf(buf, "%d%d%d", &w, &h, &n);
		for (i = n; i < 3; i++) sr[i] = sc[i] = gr[i] = gc[i] = 0;
		for (r = 0; r < h; r++) {
			fgets(p=map[r], 18, stdin);
			for (c = 0; c < w; c++) {
				if (isalpha(*p)) {
					if (islower(*p)) gr[*p-'a'] = r, gc[*p-'a'] = c;
					else             sr[*p-'A'] = r, sc[*p-'A'] = c;
					*p = ' ';
				}
				p++;
			}
		}
		printf("%d\n", dijkstra());
	}
	return 0;
}


Measured memory_bytes: 35096
#include <bits/stdc++.h>
using namespace std;
int main(void)
{
    int n;
    cin >> n;
    vector<pair<int,int>> ans(n);
    for(int i=0;i<n;i++){
        cin >> ans[i].first;
        ans[i].second = i+1;
    }
    sort(ans.begin(),ans.end());

    for(int i=0;i<n;i++){
        cout << ans[i].second << " ";
    }

    
    return (0);
}

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

int main(){
  int n;
  cin >> n;
  vector<int> town;
  vector<int> hunter;
  for(int i=0; i<n+1; i++){
    int num;
    cin >> num;
    town.push_back(num);
  }
  for(int i=0; i<n; i++){
    int num;
    cin >> num;
    hunter.push_back(num);
  }
  int previousTown = 0;
  long long count = 0;
  for(int i=0; i<n; i++){
    if(previousTown > town[i]){
      count += town[i];
      town[i] = 0;
    }else{
      count += previousTown;
      town[i] = town[i] - previousTown;
    }
    if(town[i] >= hunter[i]){
      count += hunter[i];
      previousTown = 0;
    }else{
      count += town[i];
      previousTown = hunter[i] - town[i];
    }
  }
  if(town[n] > previousTown){
    count += previousTown;
  }else{
    count += town[n];
  }
  cout << count << endl;
  return 0;
}
    
    
  


Measured memory_bytes: 1400
#include<stdio.h>
#include<iostream>
#include<vector>
#include<map>
#include<utility>
#include<iostream>
#include<string>

using namespace std;
#define MOD 1000000007

int main()
{
  string s, t;
  cin >> s >> t;
  int mx = (int) -1e9;
  for(int i = 0; i < (int)s.size() - (int)t.size() + 1; i++){
    int cnt = 0;
    for(int j = 0; j < (int)t.size(); j++)
    {
      cnt += (int)(s[i+j] == t[j]);
    }
    mx = max(mx, cnt);
  }
  cout << ((int)t.size() - mx) << endl;
  return 0;
}


Measured memory_bytes: 3148
A, B = map(int, input().split())
if B == 1:
    print(0)
else:
    q, mod = divmod(B, A-1)
    if mod <= 1 and A == 2:
        print(q-1)
    elif mod <= 1:
        print(q)
    else:
        print(q+1)

Measured memory_bytes: 3060
#include <bits/stdc++.h> 
using namespace std; 
#define lli long long int  
int main() 
{ 
  lli x,y,na,nb,nc;
  cin>>x>>y>>na>>nb>>nc;
  lli a[na],b[nb],c[nc];
  for(int i=0;i<na;i++) cin>>a[i];
  for(int i=0;i<nb;i++) cin>>b[i];
  for(int i=0;i<nc;i++) cin>>c[i];
    sort(a,a+na,greater<int>());
    sort(b,b+nb,greater<int>());
    sort(c,c+nc,greater<int>());
  
  lli ans[x+y+nc];
  for(int i=0;i<x;i++) ans[i]=a[i];
  for(int i=x;i<x+y;i++) ans[i]=b[i-x];
  for(int i=x+y;i<x+y+nc;i++) ans[i]=c[i-x-y];
  sort(ans,ans+x+y+nc,greater<int>());
  lli sum=0;
  for(lli i=0;i<x+y;i++) sum=sum+ans[i];
  cout<<sum<<"\n";  
  
  
  
  
 return 0;} 

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

int t[101], point[101];
int main()
{
  int n, m, num;
  cin >> n >> m;
  
  for (int i = 0; i < m; i++){
    cin >> t[i];
  }
  for (int i = 0; i < m; i++){
    int ct = 0;
    for (int j = 0; j < n; j++){
      cin >> num;
      if (num == t[i]){
        point[j]++;
      }
      else {
        ct++;
      }
    }
    point[t[i] - 1] += ct;
  }
  for (int i = 0; i < n; i++){
    cout << point[i] << endl;
  }
  return (0);
}

Measured memory_bytes: 1160
// Vivek Rai
// Blazer_007
#include <bits/stdc++.h>
#define fastio 		ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define mp(i,j)     make_pair(i,j)
#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define FF           first
#define SS           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define INF         0x3f3f3f3f3f3f3f3fLL
#define loop(i,a,b)  for(int i=a;i<b;i++)
using namespace std;

void solution(){
	int n,k;
	cin>>n>>k;
	vi h(n);
	loop(i,0,n)cin>>h[i];
	
	vector<ll> dp(n,INF);
	dp[0] = 0;
	loop(i,1,n){
		int temp = k;
		for(int j=i-1;j>=0&&temp>0;j--,temp--){
			dp[i] = min(dp[i],dp[j]+abs(h[i]-h[j]));
		}
	}
	cout<<dp[n-1]<<endl;
}

signed main(){
    fastio;
    int t=1;
    //cin>>t;
    for(int i=1;i<=t;i++){
    	//cout<<"Case #"<<i<<":";
    	solution();
	} 
    return 0;
}       


Measured memory_bytes: 1408
#include "bits/stdc++.h"

typedef long long int lli;

using namespace std;

int gcd(int $a,int $b) {
	if ($b == 0) {return $a;}
	return gcd($b, $a % $b);
}

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

	int N;
	cin >> N;
	vector<int> ver(N);
	
	cin >> ver[0];
	int g = ver[0];
	for (int i = 1; i < N; i++) {
		cin >> ver[i];
		g = gcd(g, ver[i]);
	}

	cout << g << endl;
}

Measured memory_bytes: 640
def bc(x):
  return bin(x).count("1")

n = input()
s = int('0b' + n, 2)
m1 = ('01' * len(n))[:len(n)]
m2 = ('10' * len(n))[:len(n)]
b1 = int('0b' + m1, 2)
b2 = int('0b' + m2, 2)

c1 = s ^ b1
c2 = s ^ b2

print(min(bc(c1), bc(c2)))


Measured memory_bytes: 3504
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String a = sc.next();
        String b = sc.next();
        String c = sc.next();
        System.out.println(a.substring(0,1).toUpperCase() + b.substring(0,1).toUpperCase() + c.substring(0,1).toUpperCase());
    }
}

Measured memory_bytes: 21844
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stdio.h>
using namespace std;
using ll = long long;
map <int ,int> mpa,mpb;

int main(){
  ll N;
  cin >> N;
  ll a[200100];
  a[0]=0;
  int t;
  for (ll i=0;i<N;i++){
    cin >> t;
    a[i+1]=a[i]+t;
  }
  sort(a,a+N+1);
  ll ans=0;
  ll k=1;
  for(int i=1;i<=N;i++){
    if(a[i]==a[i-1]){
      k++;
    }
    else{
      ans+=k*(k-1)/2;
      k=1;
    }
  }
  cout << ans+k*(k-1)/2;
}

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

int v[20],c[20];
int main(int argc, char *argv[]) { ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);


  int n;cin>>n;
  for(int i=0;i<n;i++)cin>>v[i];
  for(int i=0;i<n;i++)cin>>c[i];
  int ans=0;

  for(int i=0;i<n;i++){
    if(v[i]-c[i]>0)ans+=v[i]-c[i];
  }

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


Measured memory_bytes: 3608
import math
import sys
INFTY=sys.maxsize

def readinput():
    n=int(input())
    return n

def main(n):
    fmin=INFTY
    m=int(math.sqrt(n))+1
    for a in range(1,m+1):
        if(n%a==0):
            b=n//a
            f=max(len(str(a)), len(str(b)))
            fmin=min(fmin,f)
    return fmin

if __name__=='__main__':
    n=readinput()
    ans=main(n)
    print(ans)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int x[100*1000+3];
int n;
bool chk(int D){
	for(int i=1;i<=n;++i){
		if(x[i]%D!=0)return false;
	}
	return true;
}
int main(){
	int X;cin>>n>>X;
	for(int i=1;i<=n;++i){
		int val;cin>>val;
		x[i]=val-X;
		x[i]=abs(x[i]);
	}
	//ans=gcd(x[]);
	int gcd=x[1];
	for(int i=2;i<=n;++i)gcd=__gcd(gcd,x[i]);
	cout<<gcd<<"\n";
	//now do bs
	/*int md,lo=1,hi=1e9;
	while(lo<hi){
		md=(lo+hi)>>1;
		if(chk(md)){
			lo=md;
		}else{
			hi=md-1;
		}
	}
	//lo is the answer
	cout<<lo<<"\n";*/
	return 0;
}

Measured memory_bytes: 640
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    A = list(map(int, input().split()))

    cnt_odd_plus, cnt_odd_minus = 0, 0
    R_plus, R_minus = [0], [0]
    for i in range(n):
        if i % 2 == 0:
            # 奇数番目までの和をプラスにしたいのに、0以下になってしまう場合は和が1になるように操作する
            if R_plus[-1] + A[i] <= 0:
                cnt_odd_plus += 1 - (R_plus[-1] + A[i])
                R_plus.append(1)
            else:
                R_plus.append(R_plus[-1] + A[i])

            # 奇数番目までの和をマイナスにしたいのに、0以上になってしまう場合は和が1になるように操作する
            if R_minus[-1] + A[i] >= 0:
                cnt_odd_minus += 1 + (R_minus[-1] + A[i])
                R_minus.append(-1)
            else:
                R_minus.append(R_minus[-1] + A[i])
        else:
            # 偶数番目までの和をマイナスにしたいのに、0以上になってしまう場合は和が-1になるように操作する
            if R_plus[-1] + A[i] >= 0:
                cnt_odd_plus += 1 + (R_plus[-1] + A[i])
                R_plus.append(-1)
            else:
                R_plus.append(R_plus[-1] + A[i])

            # 偶数番目までの和をプラスにしたいのに、0以下になってしまう場合は和が1になるように操作する
            if R_minus[-1] + A[i] <= 0:
                cnt_odd_minus += 1 - (R_minus[-1] + A[i])
                R_minus.append(1)
            else:
                R_minus.append(R_minus[-1] + A[i])

    res = min(cnt_odd_plus, cnt_odd_minus)
    print(res)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 15108
#include <iostream>
#include <numeric>
#include <string>
#include <algorithm>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <utility>

#define repd(i,a,b); for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define ll long long int
 
 
using namespace std;
int main() {
  string s; cin >> s;
  int k; cin >> k;
  int cnt=0;
  for(int i=0;;i++){
    if(s[i] == '1'){
      cnt++;
    } else {
      break;
    }
  }
  if(k <= cnt){
    cout << 1;
  } else {
    cout << s[cnt];
  }
 
 return 0;
}

Measured memory_bytes: 256
A, B = map(int, input().split())

def f(n):
    if n % 4 == 0:
        return(0 ^ n)
    elif n % 4 == 2:
        return(1 ^ n)
    elif n % 4 == 3:
        return(0)
    else:
        return(1)

if A == 0:
    ans = f(B)
    print(ans)
else:
    ans = f(B) ^ f(A-1)
    print(ans)

"""
ans = A
for i in range(A+1, B+1):
    ans ^= i

print(ans)
"""

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
using ll = long long;
int main(void){
    int N;
    string S,T;
    cin>>N>>S>>T;
    
    
    rep(i,N){
        cout<<S[i]<<T[i];
    }
    cout<<endl;
        
    }
    
    



Measured memory_bytes: 3628
while True:
    n = int(raw_input())
    if n == 0:
        break
    sale = {}
    order = []
    
    for i in range(n):
        j,p,q = map(int,raw_input().split())
        if j in sale:
            sale[j] += p * q
        else:
            sale[j] = p * q
            order.append(j)
         
    existflag = False
    for j in order:
        if sale[j] >= 1000000:
            print j
            existflag = True
    if not existflag:
        print 'NA'

Measured memory_bytes: 4336
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef vector<ll> vl;
#define inf 1000000000
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define rep1(i, a, b) for(int i =a; i >=b; i--)
#define f first
#define ss second
#define pb push_back

char a, b;

int main(){

cin >> a >> b;

if(a=='H'){
        if(b=='H')cout << "H";
        else cout << "D";
}
else {
    if(b=='D')cout << "H";
    else cout << "D";
}




return 0;}






Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = input()
K = INT()

dp_co = [[0 for _ in range(3 + 1)] for _ in range(len(N) + 1)]
dp_unco = [[0 for _ in range(3 + 1)] for _ in range(len(N) + 1)]
dp_co[0][0] = 1

for i in range(len(N)):
	for j in range(4):
		for k in range(2):
			for num in range(10):
				n_i, n_j, n_k = i + 1, j, k
				if num != 0:
					n_j += 1
				if n_j > K:
					continue
				if k == 0:
					if num > int(N[i]):
						continue
					if num == int(N[i]):
						k = 0
					if num < int(N[i]):
						n_k = 1
				if n_k == 0:
					dp_co[n_i][n_j] += dp_co[i][j]
				if n_k == 1:
					if k == 0:
						dp_unco[n_i][n_j] += dp_co[i][j]
					else:
						dp_unco[n_i][n_j] += dp_unco[i][j]						

ans = dp_co[len(N)][K] + dp_unco[len(N)][K]
print(ans)

Measured memory_bytes: 5396
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0207

"""
import sys
from sys import stdin
from collections import deque
input = stdin.readline


def solve(w, h, xs, ys, xg, yg, blocks):
    # ????????????????????±????????°???????????????l
    field = [[0] * (w+1) for _ in range(h+1)]
    for c, d, x, y in blocks:
        field[y][x] = c
        field[y][x+1] = c
        field[y+1][x] = c
        field[y+1][x+1] = c

        if d == 0:              #  ?¨????
            field[y][x+2] = c
            field[y][x+3] = c
            field[y+1][x+2] = c
            field[y+1][x+3] = c
        else:                   #  ??????
            field[y+2][x] = c
            field[y+3][x] = c
            field[y+2][x+1] = c
            field[y+3][x+1] = c

    # ????????????????§????????????´????????§?¨??????????
    dy = [-1, 1, 0, 0]
    dx = [0, 0, -1, 1]

    d = [[-1] * (w+1) for _ in range(h+1)] #  ?????¢?´¢?????°??¨???????????¨??????-1???
    Q = deque()
    Q.append((xs, ys))
    d[ys][xs] = 0
    color = field[ys][xs]       #  ?????????????????¨?????§?????????????????????????????°?????¨???????????????

    while Q:
        xc, yc = Q.popleft()        #  ?????¨??°?????§?¨?
        if xc == xg and yc == yg:
            return 'OK'
        for i in range(len(dx)):
            xn = xc + dx[i]
            yn = yc + dy[i]
            #  ?§????????????§???????????? ?????? ??¢?????¢?´¢?????§???????????°??????????????§?????¢?´¢????¶???????
            if 0 < xn <= w and 0 < yn <= h and d[yn][xn] == -1 and field[yn][xn] == color:
                Q.append((xn, yn))
                d[yn][xn] = d[yc][xc] + 1
    return 'NG'


def main(args):
    while True:
        w, h = map(int, input().split())
        if w == 0 and h == 0:
            break
        xs, ys = map(int, input().split())
        xg, yg = map(int, input().split())
        n = int(input())
        blocks = [list(map(int, input().split())) for _ in range(n)]

        result = solve(w, h, xs, ys, xg, yg, blocks)
        print(result)


if __name__ == '__main__':
    main(sys.argv[1:])
    

Measured memory_bytes: 8104
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int N;
vector<pair<int,int> >A;
long dp[5050];
main()
{
	cin>>N;
	for(int i=0;i<N;i++)
	{
		int h,p;cin>>h>>p;
		A.push_back(make_pair(h,p));
		dp[i+1]=9e18;
	}
	sort(A.begin(),A.end(),[](pair<int,int>x,pair<int,int>y){return x.first+x.second<y.first+y.second;});
	for(int i=0;i<N;i++)
	{
		for(int j=N;j>=0;j--)
		{
			if(dp[j]<=A[i].first)
			{
				dp[j+1]=min(dp[j+1],dp[j]+A[i].second);
			}
		}
	}
	int ans=0;
	while(ans+1<=N&&dp[ans+1]<9e18)ans++;
	cout<<ans<<endl;
}


Measured memory_bytes: 384
<?php
    $s = explode(' ', trim(fgets(STDIN)));
    $x = $s[0];
    $a = $s[1];
    $b = $s[2];
	if(abs($a-$x)>abs($b-$x)){
    	echo "B";
    }else{
    	echo "A";
    }

?>

Measured memory_bytes: 4604
#include <cstdio>
#include <algorithm>
#include <map>
#include <set>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;

int n, x, d, k;
const ll MM = 1ll << 60;
map<int, int> mp;
set<pll> S[200005]; int cnt;

int main(){
    scanf("%d %d %d", &n, &x, &d), k = x - d;
    if(d == 0){
        printf("%d", n * (k != 0) + 1);
        return 0;
    }
    if(d < 0) d = -d, k = -k;

    for(int a = 0; a <= n; a++){
        ll s = (a + 1) * 1ll * a / 2;
        ll e = (2 * n - a + 1) * 1ll * a / 2;
        ll con = a * 1ll * k;
        int mod = (con % d + d) % d;
        if(mp.find(mod) == mp.end()) mp[mod] = cnt++;
        int ind = mp[mod];

        ll shamt = 0;
        if(mod < con) shamt = (con - mod) / d;
        if(mod > con) shamt = -((mod - con) / d);
        s += shamt, e += shamt;

        while(!S[ind].empty()){
            auto it = S[ind].lower_bound({s, -MM});
            if(it == S[ind].end()) break;
            ll l = it->second, r = it->first;
            if(l > e) break;
            S[ind].erase(it);
            s = min(s, l), e = max(e, r);
        }
        S[ind].insert({e, s});
    }
    ll ans = 0;
    for(auto m: mp){
        for(pll p: S[m.second]) ans += p.first - p.second + 1;
    }
    printf("%lld", ans);
    return 0;
}

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

public class Main {

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

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String input = br.readLine();
        String[] point = input.split(" ");

        double x1 = Double.parseDouble(point[0]);
        double y1 = Double.parseDouble(point[1]);
        double x2 = Double.parseDouble(point[2]);
        double y2 = Double.parseDouble(point[3]);

        double x = x2 - x1;
        double y = y2 - y1;

        double distance = Math.sqrt(Math.pow(Math.abs(x), 2) + Math.pow(Math.abs(y), 2));

        System.out.println(distance);
    }
}

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

using namespace std;
using LL = long long;
using P = pair<int,int>;
const int INF=1e9;
const int Max_T=1e5+10;
const int Max_C=35;

bool now[Max_T][Max_C];

int main(){
	int N, C;
	cin >> N >> C;
	vector<vector<P>> channel(C);
	rep(i,N){
		int s, t, c;
		cin >> s >> t >> c;
		s--; t--; c--;
		channel[c].emplace_back(P(t,s));
	}
	rep(i,C) sort(channel[i].begin(),channel[i].end());
	rep(time,Max_T){
		rep(i,C){
			P p={time,-1};
			auto itr=upper_bound(channel[i].begin(),channel[i].end(),p);
			if(itr!=channel[i].end() && itr->second<=time) now[time][i]=true;
		}
	}
	int ans=0;
	rep(i,Max_T){
		int res=0;
		rep(j,C) if(now[i][j]) res++;
		ans=max(ans,res);
	}
	cout << ans << endl;

	return 0;
}

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

int N, M, X;
vector<int> C;
vector< vector<int> > A;
ll ans = INF;

void dfs(int ex, int count, int CC, vector<int> XX){
    
    if(count == N){
        rep(i, M){
            if(XX[i] < X){
                return;
            }
        }
        
        if(CC < ans){
            ans = CC;
        }
        
        return;
    }
    
    if(ex == 1){
        CC += C[count];
        rep(i, M){
            XX[i] += A[count][i];
        }
    }
    
    
    dfs(0, count+1, CC, XX);
    dfs(1, count+1, CC, XX);
    
}

int main() {
    
    cin >> N >> M >> X;
    
    rep(i, N){
        int c;
        cin >> c;
        C.push_back(c);
        
        vector<int> vec;
        A.push_back(vec);
        rep(j, M){
            int a;
            cin >> a;
            A[i].push_back(a);
        }
    }
    
    vector<int> XX(M, 0);
    dfs(0, 0, 0, XX);
    dfs(1, 0, 0, XX);
    
    if(ans == INF){
        cout << -1 << endl;
    }else{
        cout << ans << endl;
    }
    
    return 0;
    
}

Measured memory_bytes: 3640
import java.util.Scanner;

public class Main{
	public static void main(String args[]){

		//??????????????????????????¢?????¨?????¨??????????????????
		Scanner sc = new Scanner(System.in);
		double dbR = sc.nextDouble();
		double dbMenseki = 0;
		double dbEnsyu = 0;

		//??¢?????¨?????¨????±???????
		dbMenseki = dbR * dbR * Math.PI;
		dbEnsyu = ( dbR * 2 ) * Math.PI;

		//6????????§??¨?????????
		String stMen = String.format("%.6f", dbMenseki);
		String stEnsyu = String.format("%.6f", dbEnsyu);

		System.out.println(stMen + " " + stEnsyu);
	}
}

Measured memory_bytes: 27984
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define PI 3.14159265358979323846264338327950L
int main() {
    //long long double a,b;
    int a, b, h, m;
    scanf("%d%d%d%d", &a, &b, &h, &m);
    long double rad = PI * 2 * ((long double)h / 12.0 + ((long double)m / 60.0) / 12.0 - (long double)m / 60.0);
    long double rsq = (long double)(a * a + b * b) - (long double)(2 * a *b) * cosl(rad);
    printf("%20.20Lf\n", sqrtl(rsq));
    return 0;
}

Measured memory_bytes: 4216
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define ll long long
#define lb(x) ((x)&(-x))
#define pii pair<int,int>
#define vi vector<int>
#define pb push_back
#define fi first
#define se second
#define de(x) cout<<x<<" x"<<endl
#define LCAFA rep(i,1,20)rep(j,1,n+1)fa[j][i]=fa[fa[j][i-1]][i-1]
#define all(x) x.begin(),x.end()
#define ls(x) x<<1
#define rs(x) x<<1|1
using namespace std;
const int N=2e5+9;
const ll mod=998244353;
pair<int,int> g[N];
ll dp[N][40];
int a[N],b[N],p[N];
int cnt,cnt2;
void upd(ll &a,ll b){
	if(a>b)a=b;
}
bool cmp(pii x,pii y){
	return 1.0*(x.fi-1)/x.se>1.0*(y.fi-1)/y.se;
}
int main(){
//	freopen("text.in","r",stdin);
	int n,t;
	scanf("%d%d",&n,&t);
	++t;
	rep(i,1,n+1){
		scanf("%d%d",&a[i],&b[i]);
		++a[i],++b[i];
		if(a[i]>1)g[++cnt]={a[i],b[i]};
		else p[cnt2++]=b[i];
	}
	sort(g+1,g+1+cnt,cmp);
	sort(p,p+cnt2);
	rep(i,0,N)rep(j,0,40)dp[i][j]=1e12;
	dp[0][0]=1;
	rep(i,1,cnt+1){
		rep(j,0,40){
			if(dp[i-1][j]<=t)upd(dp[i][j],dp[i-1][j]);
			if(j&&dp[i-1][j-1]<=t&&dp[i-1][j-1]*g[i].fi+g[i].se<=t)upd(dp[i][j],dp[i-1][j-1]*g[i].fi+g[i].se);
		}
	}
	ll sum=0;
	int pos=0,ans=0;
	per(j,0,40){
		if(dp[cnt][j]>t)continue;
	//	cout<<cnt<<' '<<j<<' '<<dp[cnt][j]<<"dp\n";
		while(pos<cnt2&&dp[cnt][j]+sum+p[pos]<=t)sum+=p[pos++];
	//	cout<<cnt2<<' '<<pos<<"pos\n";
		ans=max(ans,pos+j); 
	}
	cout<<ans;
} 


Measured memory_bytes: 65920
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<utility>
#define lint long long
#define P(x,y) ((lint)x*n+y)
#define mp make_pair
#define fir first
#define sec second
#define N 100010
using namespace std;
typedef pair<int,int> pii;
map<lint,int> f;
set<int> g[N];
queue<pii> q;
int main()
{
	int n;scanf("%d",&n);
	for(int i=1;i<=2*n-2;i++)
	{
		int x,y;scanf("%d%d",&x,&y);
		f[P(x,y)]++,f[P(y,x)]++;
		g[x].insert(y),g[y].insert(x);
		if(f[P(x,y)]==2) q.push(mp(x,y));
	}
	int ans=0;
	while(!q.empty())
	{
		int x=q.front().fir,y=q.front().sec;q.pop();
		if(f[P(x,y)]==2)
		{
			if(g[x].size()<g[y].size()) swap(x,y);
			while(!g[y].empty())
			{
				int t=*g[y].begin();
				f[P(x,t)]+=f[P(y,t)],f[P(y,t)]=0;
				f[P(t,x)]+=f[P(t,y)],f[P(t,y)]=0;
				g[x].insert(t),g[t].insert(x);
				g[y].erase(t),g[t].erase(y);
				if(f[P(x,t)]==2) q.push(mp(x,t));
			}
			ans++;
		}
	}
	if(ans==n-1) printf("YES\n");
	else printf("NO\n");return 0;
}

Measured memory_bytes: 55168
import copy

n = int(raw_input())
cards = []
for i in range(n):
    suit,num = raw_input().strip().split(' ')
    num = int(num)
    cards.append((suit,num))

def quick_sort(S,p,r):
    if p < r:
        q = partition(S,p,r)
        quick_sort(S,p,q-1)
        quick_sort(S,q+1,r)

def partition(S,p,r):
    x = S[r][1]
    i = p-1
    for j in range(p,r):
        if S[j][1] <= x:
            i += 1
            S[j],S[i]=S[i],S[j]
    S[r],S[i+1]=S[i+1],S[r]
    return i+1

def merge_sort(S):
    if len(S) <= 1:
        return S
    S1,S2 = split(S)
    return merge(merge_sort(S1),merge_sort(S2))

def split(S):
    mid = len(S)/2
    return S[:mid],S[mid:]

def merge(S1,S2):
    S = []
    S1.append(('SENTINEL',100000000000))
    S2.append(('SENTINEL',100000000000))
    i = 0
    j = 0
    for k in range(len(S1)+len(S2)-2):
        if S1[i][1] <= S2[j][1]:
            S.append(S1[i])
            i += 1
        else:
            S.append(S2[j])
            j += 1
    return S



cards2 = copy.copy(cards)
quick_sort(cards,0,len(cards)-1)
cards2 = merge_sort(cards2)
flag = True
for i in range(len(cards)):
    if cards[i] != cards2[i]:
        print "Not stable"
        flag = False
        break
if flag: print "Stable"
for suit,num in cards:
    print suit,num

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

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

  if (n == 1) {
    cout << "Hello World" << endl;
  } else {
    int a, b;
    cin >> a >> b;
    cout << a + b << endl;
  }
}

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

using namespace std;

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

	string s;
	cin >> s;

	int g = 0, p = 0,ans = 0;
	for (auto a : s) {
		if (a == 'g') {
			if (g > p) {
				ans++;
				p++;
			}
			else {
				g++;
			}
		}
		else {
			if (g > p) {
				p++;
			}
			else {
				ans--;
				g++;
			}
		}
	}
	cout << ans << endl;;

	return 0;

}

Measured memory_bytes: 640