akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
using namespace std;

struct info{
	long long int x, y, z;
};

long long int INF = 1e18;
int n, m;
int st[] = {0, 0, 0};
const int N = 1e3+10;
info v[N];

long long int cost(){
	long long int s1 = 0;
	long long int s2 = 0;
	long long int s3 = 0;
	for(int i=0; i < m; i++){
		s1 += v[i].x;
		s2 += v[i].y;
		s3 += v[i].z;
	}
	return abs(s1) + abs(s2) + abs(s3);
}

long long int value(info tmp){
	long long int ans = 0;
	long long int aux[] = {tmp.x, tmp.y, tmp.z};
	for(int i=0; i < 3; i++){
		if(st[i]) ans += aux[i];
		else ans -= aux[i];
	}
	return ans;
}

bool cmp_p(info i1, info i2){
	long long int v1 = value(i1);
	long long int v2 = value(i2);
	return v1 > v2;
}



int main(){
	cin >> n >> m;
	for(int i=0; i < n; i++)
		cin >> v[i].x >> v[i].y >> v[i].z;
	

	long long int ans = -INF;
	for(int i=0; i <= 1; i++){
		for(int j=0; j <= 1; j++){
			for(int k=0; k <= 1; k++){
				st[0] = i;
				st[1] = j; 
				st[2] = k;
				sort(v, v+n, cmp_p);
				ans = max(ans, cost());
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long n, m, q;
long long a[105], b[105], c[105], d[105];
long long ans;
vector<long long> v;
 
void dfs(int x) {
    if(x==n+1) {
        long long now=0;
        for(int i=1;i<=q;i++) {
            if(v[b[i]]-v[a[i]]==c[i]){
            	now += d[i];
			} 
        }
        ans = max(ans, now);
        return;
    }
    for(int i=v[x-1];i<=m;i++) {
        v.push_back(i);
        dfs(x+1);
        v.pop_back();
    }
}
int main() {
    cin>>n>>m>>q;
    for(int i=1;i<=q;i++) {
        cin>>a[i]>>b[i]>>c[i]>>d[i];
    }
    ans = 0;
    v.clear();
    v.push_back(1);
    dfs(1);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3616
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

int main(){
  ll n,m;
  cin>>n>>m;
  vector<vector<ll> > vp(m,vector<ll>());
  vector<ll> v;
  rep(i,0,m){
    ll a;
    cin>>a;
    rep(j,0,a){
      ll b;
      cin>>b;
      vp[i].pb(b-1);
    }
  }
  rep(i,0,m){
    ll a;
    cin>>a;
    v.pb(a);
  }
  ll ans = 0;
  rep(i,0,1<<n){
    ll flag = 1;
    rep(j,0,vp.sz){
      ll c = 0;
      rep(k,0,vp[j].sz){
        ll a = vp[j][k];
        if(((i>>a)&1)==1){
          c++;
        }
      }
      if(c%2!=v[j])flag = 0;
    }
    ans += flag;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
  let stdin = stdin();
  let stdin = stdin.lock();
  let token: String = stdin
    .bytes()
    .map(|c| c.expect("failed to read char") as char)
    .skip_while(|c| c.is_whitespace())
    .take_while(|c| !c.is_whitespace())
    .collect();
  token.parse().ok().expect("failed to parse token")
}

fn main() {
  let s = read::<i32>();
  let mut s_list = vec![s];
  let mut ans = 0;

  for i in 2..10000000 {
    let s_c = s_list[i - 2].clone();
    let new_s = if s_c % 2 == 0 { s_c / 2 } else { 3 * s_c + 1 };
    if s_list.contains(&new_s) {
      ans = i;
      break;
    }

    s_list.push(new_s);
  }

  println!("{:?}", ans)

}



Measured memory_bytes: 4352
#include<iostream>
using namespace std;
int main(){
  int N; int sum=0;cin>>N;
  int N_copy = N;
  while(N>0){
    sum+=N%10;
    N/=10;
  }
  if(N_copy%sum==0)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long ll;
ll dp[10000005];
int main() {
	int n;
	cin >> n;
	int h[100005];
	for (int i = 0; i < n; i++) {
		cin >> h[i];
	}

	dp[0] = 0;
	dp[1] = abs(h[1] - h[0]);
	for (int i =  2; i < n; i++) {
		dp[i] = min(dp[i - 1] + abs(h[i]-h[i-1]), dp[i - 2] + abs(h[i]-h[i-2]));
	}
	cout << dp[n-1] << endl;
	return 0;
}

Measured memory_bytes: 1408
def dfs(n,v,graph,visited):
  all_visited=True
  
  for i in range(n):
    if visited[i]==False:
      all_visited=False
      
  if all_visited==True:
    return 1
  
  ret=0
  for i in range(len(graph[v])):
    if visited[graph[v][i]]==False:
    	visited[graph[v][i]]=True
    	ret += dfs(n,graph[v][i],graph,visited)
    	visited[graph[v][i]]=False
  return ret

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

visited=[]
for j in range(n):
  visited.append(False)

graph=[]
for j in range(n):
  graph.append([])
  
for j in range(m):
  a,b=list(map(int,input().split()))
  graph[a-1].append(b-1)
  graph[b-1].append(a-1)

visited[0]=True

print(dfs(n,0,graph,visited))

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>
#include <complex>
#include <cstdio>

using namespace std;
//std::ios::sync_with_stdio(false);
//std::cin.tie(0);
const long long MOD = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ll> pdl;
typedef pair<ld, ld> pdd;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
//typedef boost::multiprecision::cpp_int bigint;

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	ll A, B, C;
	cin >> A >> B >> C;
	cout << min(C, B / A) << "\n";
	return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

// NextPermutation generates the next permutation of the
// sortable collection x in lexical order.  It returns false
// if the permutations are exhausted.
//
// Knuth, Donald (2011), "Section 7.2.1.2: Generating All Permutations",
// The Art of Computer Programming, volume 4A.
func NextPermutation(x sort.Interface) bool {
	n := x.Len() - 1
	if n < 1 {
		return false
	}
	j := n - 1
	for ; !x.Less(j, j+1); j-- {
		if j == 0 {
			return false
		}
	}
	l := n
	for !x.Less(j, l) {
		l--
	}
	x.Swap(j, l)
	for k, l := j+1, n; k < l; {
		x.Swap(k, l)
		k++
		l--
	}
	return true
}

func f(s string) {
	pos := -1
	m := make([]int, 26)
	v := byte(0)
L0:
	for i := len(s) - 1; i >= 0; i-- {
		c := int(s[i] - 'a')
		// out(c, m)
		for j := c; j < 26; j++ {
			if m[j] == 1 {
				v = byte(j + 'a')
				pos = i
				break L0
			}
		}
		m[c]++
	}

	if pos == -1 {
		out(-1)
		return
	}

	out(s[:pos] + string(v))

	return
}

func f2(s string) {
	if s == "zyxwvutsrqponmlkjihgfedcba" {
		out(-1)
		return
	}
	x := make([]int, 26)
	for i := 0; i < 26; i++ {
		x[i] = int(s[i])
	}
	// fmt.Println(0, x)

	for i := 1; NextPermutation(sort.IntSlice(x)); i++ {
		// fmt.Println(i, x)
		break
	}
	for i := 0; i < 26; i++ {
		c := byte(x[i])
		if s[i] == c {
			fmt.Printf("%c", c)
		} else {
			fmt.Printf("%c", c)
			break
		}
	}
	out("")
}

func main() {
	sc.Split(bufio.ScanWords)
	s := getString()
	m := make([]int, 26)
	for _, v := range s {
		m[int(v-'a')]++
	}
	c := -1
	for i := 0; i < 26; i++ {
		if m[i] == 0 {
			c = i
			break
		}
	}
	if c == -1 {
		f2(s)
		return
	}
	out(s + string(byte(c+'a')))
}


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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define itn int
typedef long long ll;
typedef pair<ll,ll> p;


int main()
{
  int a, b, c;
  cin >> a >> b >> c;
  int res = 0;
  while(a % 2 == 0 && b % 2 == 0 && c % 2 == 0) {
    if(a == b && a == c && b == c)
    {
      cout << -1 << endl;
      return 0;
    }
    if (a % 2 == 1 || b % 2 == 1 || c % 2 == 1)
    {
      cout << res << endl;
      return 0;
    }


    res++;
    int tmpa = a;
    int tmpb = b;
    int tmpc = c;
    a = tmpb / 2 + tmpc / 2;
    b = tmpa / 2 + tmpc / 2;
    c = tmpa / 2 + tmpb / 2;
  }

  cout << res << endl;

}

Measured memory_bytes: 256
fun main(args: Array<String>) {
  val (h, w) = readLine()!!.split(" ").map { it.toInt() }
  val a = Array(h) { readLine()!! }
  val b = Array(w) { a.fold("") { buf, value -> buf + value[it] } }
  var row = Array<Boolean>(h) { true }
  for (i in 0 until h) {
    if (a[i].all { it == '.' }) row[i] = false
  }
  var col = Array<Boolean>(w) { true }
  for (j in 0 until w) {
    if (b[j].all { it == '.' }) col[j] = false
  }
  var ans = Array<MutableList<Char>>(h) { mutableListOf<Char>() }
  for (i in 0 until h) {
    for (j in 0 until w) {
      if (row[i] && col[j]) ans[i].add(a[i][j])
    }
    if (ans[i].isEmpty()) continue
    println(ans[i].joinToString(""))
  }
}


Measured memory_bytes: 40504
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define endl "\n"
#define se second
#define ll long long
#define inf 0x3f3f3f3f
#define fast    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int N = 3e5+5;
const ll mod =   1e9+7;

int main()
{  fast
ll n,k;
cin>>n>>k;
ll arr[n+1];
for(ll i=0;i<n;i++)
{
	cin>>arr[i];

}
for(ll i=k;i<n;i++) {

	if(arr[i]>arr[i-k]){
		cout<<"Yes\n";
	}
	else{
		cout<<"No\n";
	}
}
}


Measured memory_bytes: 5108
import java.util.*;
import java.util.stream.*;
class Main{
    public static void main(String[]$){
        Scanner s=new Scanner(System.in);
        int n=s.nextInt(),k=s.nextInt();
        System.out.println(IntStream.range(0,n).map(i->s.nextInt()).sorted().skip(n-k).sum());
    }
}

Measured memory_bytes: 28372
// 中心を通れば真っ二つにできる 中心だったら複数取れる
package main
import "fmt"
func main(){
	var W, H, x, y float64
	fmt.Scan(&W, &H, &x, &y)
	if H/2.0 == y && W/2.0 == x{
		fmt.Println(W*H/2, 1)
	}else{
		fmt.Println(W*H/2, 0)
	}
}

Measured memory_bytes: 1772
#include "bits/stdc++.h"
using namespace std;


int n, q;

class UnionFindTree {
  int* p;
  int* rank;
public:
  void makeSet(int x);
  void doUnion(int x, int y);
  int findRoot(int x);
  bool isSameSet(int x, int y);
  void link(int x, int y);
};

void UnionFindTree::makeSet(int n) {
  p = new int[n];
  rank = new int[n];
  for (int i=0; i < n; i++) {
    p[i] = i;
    rank[i] = i;
  }
}

void UnionFindTree::doUnion(int x, int y) {
  link(findRoot(x), findRoot(y));
}

int UnionFindTree::findRoot(int x) {
  while (x != p[x]) {
    p[x] = p[p[x]];
    x = p[x];
  }
  return x;
}

bool UnionFindTree::isSameSet(int x, int y) {
  return findRoot(x) == findRoot(y);
}

void UnionFindTree::link(int x, int y) {
  if (rank[x] > rank[y]) {
    p[y] = x;
  } else {
    p[x] = y;
    if (rank[x] == rank[y]) {
      rank[y]++;
    }
  }
}

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  cin >> n >> q;
  
  int com, x, y;
  UnionFindTree uft;
  uft.makeSet(n);
  
  for (int i=0; i < q; i++) {
    cin >> com >> x >> y;
    if (com == 0) {
      uft.doUnion(x, y);
    } else {
      if (uft.isSameSet(x, y)) {
        cout << '1' << '\n';
      } else {
        cout << '0' << '\n';
      }
    }
  }
  return 0;
}

Measured memory_bytes: 3236
N = int(input())

dammy=[]
for i in range(1,N+1):
    if i%3==0 and i%5==0:
        #dammy.append('FizzBuzz')
        continue
    elif i%3==0:
        #dammy.append('Fizz')
        continue
    elif i%5==0:
        #dammy.append('Buzz')
        continue
    else:
        dammy.append(i)

print(sum(dammy))

Measured memory_bytes: 103904
package main

import (
	"fmt"
	"strings"
)

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

	var s string
	fmt.Scan(&s)
	var listB = make([]string, n)
	listB = strings.Split(s, "")

	ret := 1
	for i := 0; i < len(listB)-1; i++ {
		if listB[i] != listB[i+1] {
			ret++
		}
	}

	fmt.Println(ret)

}



Measured memory_bytes: 3712
from collections import Counter

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

evens = Counter(v[::2])
odds = Counter(v[1::2])

evens[0] = 0  # 一種類の数値しか含まれないときの対策
odds[0] = 0

keep = 0
for even in evens.most_common(2):
    for odd in odds.most_common(2):
        if even[0] != odd[0]:
            keep = max(keep, even[1] + odd[1])

print(n - keep)


Measured memory_bytes: 18656
#include <bits/stdc++.h>
using namespace std;
int main(void)
{
  string S, T;
  cin>>S>>T;
  int ls,lt,n;
  ls=S.size();
  lt=T.size();
  n=lt;
  for(int i=0;i<=ls-lt;i++){
    int cn=0;
    if(0==S.compare(i,lt,T)){cout<<0<<endl;return 0;}
    for(int j=0;j<lt;j++)
     if(T[j]!=S[i+j]) cn++;
    if(cn<n) n= cn;
  }
  cout<<n<<endl;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
	int n;
	cin >> n;
	vector<int> a(n);
	rep(snip_i, n) cin >> a.at(snip_i);
	vector<int> ans(n, 0), ans2;
	rrep(i, n){
		int sum = 0;
		for(int j = i; j < n; j += (i+1)){
			sum += ans.at(j);
		}
		if(sum % 2 != a.at(i)){
			ans2.push_back(i+1);
			ans.at(i) = 1;
		}
	}
	cout << ans2.size() << endl;
	if(ans2.size() != 0){
		rep(i, ans2.size()){
			if(i != 0)cout << " ";
			cout << ans2.at(i);
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 3064
#encoding:utf-8

def evennum(number):
    count=0
    while(1):
        if number%2==1:
            break
        else:
            number=number/2
            count+=1
    return count
#input
n=int(input())

l=[int(i) for i in input().split()]

count=0

for i in range(n):
    count+=evennum(l[i])

print(count)


Measured memory_bytes: 4148
#include <bits/stdc++.h>
#include <ext/rope>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define ll long long
//#define int long long
#define pb push_back
#define x first
#define ld long double
#define y second
#define mk(a,b) make_pair(a,b)
#define rr return 0
#define sqr(a) ((a)*(a))
#define all(a) a.begin(),a.end()

using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;
template<class value, class cmp = less<value> >
using ordered_set = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class value, class cmp = less_equal<value> >
using ordered_multiset = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class key, class value, class cmp = less<key> >
using ordered_map = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;

/// find_by_order()
/// order_of_key()
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
inline int randll(int l = INT_MIN, int r = INT_MAX) {
    return uniform_int_distribution<int>(l, r)(rng);
}
main()
{
    ios::sync_with_stdio(0);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    vector <string> a(n);
    vector <int> b(n);
    int ans = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i] >> b[i];
        ans += b[i];
    }
    string s;
    cin >> s;
    for (int i = 0; i < n; i++) {
        ans -= b[i];
        if (a[i] == s) break;
    }
    cout << ans << '\n';
}


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

using namespace std;

int main(void) {
  int a, b;
  cin >> a >> b;

  // 隣り合う搭の高さはn異なる
  //ここで何本目の搭かわかる
  int n = b - a;
  int res = -a;

  //snow = \sum_{i = 1}^(n - 1) i - a
  for(int i = 1;i < n; i++) {
    res += i;
  }

  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int,int>;

vector<int>bitSearch(int bit,int n){
    vector<int>S;
    rep(i,n)if(bit&(1<<i))S.push_back(i);
    return S;
}


int d[3] = {-1,0,1};
int main(){
   int n,k;cin>>n>>k;
   VEC(int,h,n);
   sort(ALL(h),greater<int>());
   int res = 0;
   rep(i,k)res += h[i];
   cout<<res;
}



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;

int dx[]={0,1,0,-1,1,1,-1,-1};
int dy[]={1,0,-1,0,1,-1,1,-1};

int main(void) {
  int i,j;
  int h, w;
  while(cin >> h >> w, h){
      vs s(h);
      rep(i,h) cin >> s[i];
      map<string,int> ma;
      rep(i,h)rep(j,w)rep(k,8){
          string t = "";
          t += s[i][j];
          int x = (i + dx[k] + h)%h;
          int y = (j + dy[k] + w)%w;
          while(x != i || y != j){
              t += s[x][y];
              ma[t]++;
              x = (x + dx[k] + h)%h;
              y = (y + dy[k] + w)%w;
          }
      }
      string ans = "";
      for(auto itr=ma.begin();itr!=ma.end();itr++){
          if(itr->second >= 2){
              string t = itr->first;
              if(ans.size() < t.size()) ans = t;
          }
      }
      if(ans == ""){
          cout << 0 << endl;
      }else{
          cout << ans << endl;
      }
  }
}



Measured memory_bytes: 37876
#include <bits/stdc++.h>
#define ll long long
#define MAX_N 100000
using namespace std;

vector<vector<int>> V( 9,vector<int>(9,0) );
int n;

int main(){
    cin>>n;
    for(int i = 0 ; i <= n; i++){
        int top = i;
        while(top >= 10) top /= 10;
        int btm = i - ( i/10 ) *10;
        if (btm == 0 ) continue;
        top--;btm--;
        V.at(top).at(btm)++;
    }

    int ans = 0;
    for(int i =0; i < 9; i++){
        for(int j = 0; j<9;j++){
            ans += V.at(i).at(j) * V.at(j).at(i);
        }
    }
    cout<< ans <<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>

using namespace std;

int main()
{
	int unit_price, unit_sales;
	char dummy;
	
	int price_sum = 0, sales_sum = 0;
	int n;
	
	for ( n=0; cin >> unit_price >> dummy >> unit_sales; n++ ) {
		price_sum += unit_price * unit_sales;
		sales_sum += unit_sales;
	}
	
	float avg_sales = static_cast<float>(sales_sum) / n;
	
	avg_sales += 0.5; avg_sales = floor(avg_sales);
	
	cout << price_sum << endl;
	cout << static_cast<int>(avg_sales) << endl;
	
	return 0;
}

Measured memory_bytes: 2976
def Bellman_Ford(s, g, inf=1 << 60):
    # https://tjkendev.github.io/procon-library/python/graph/bellman-ford.html
    N = len(g)
    dist = [inf] * N
    dist[s] = 0
    for _ in range(N):
        not_updated = True
        for v in range(N):
            for u, c in g[v]:
                if (dist[v] == inf) or (dist[v] + c >= dist[u]): continue
                dist[u] = dist[v] + c
                not_updated = False

        if not_updated:
            return max(0, -dist[N - 1])

    # 負閉路が存在する
    for _ in range(N):
        not_updated = True
        for v in range(N):
            for u, c in g[v]:
                if (dist[v] == inf) or (dist[v] + c >= dist[u]): continue
                dist[u] = -inf
                not_updated = False
        if not_updated: break

    if dist[N - 1] == -inf:
        return -1
    else:
        return max(0, -dist[N - 1])


def main():
    import sys
    input = sys.stdin.readline

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

    g = tuple(set() for _ in range(N))
    for _ in range(M):
        a, b, c = map(int, input().split())
        a -= 1
        b -= 1
        g[a].add((b, -(c - P)))  # to,coin(負辺)

    ret = Bellman_Ford(0, g)
    print(ret)


if __name__ == '__main__':
    main()


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

using ll = long long int;
using vi = vector<int>;
using vll = vector<long long int>;
using vii = vector<vi>;

#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i, a, b) for(int (i) = a; (i) < (b);(i)++)
#define MAX(a, b) ((a > b) ? a : b)
#define MIN(a, b) ((a > b) ? b : a)

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

int main(){
  int n;
  string s, t;
  cin >> s;
  n = s.size();
  bool a, b;
  a = (n - 2) % 2;
  b = (s.front() == s.back());
  t = (a != b) ? "First" : "Second";
  cout << t << "\n";
  return 0;
}

Measured memory_bytes: 512
#include<cstdio>
#include <iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#include<functional>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<numeric>

using namespace std;
typedef long long ll;
typedef pair<int, int> Pr;

int N, K;
ll a[50001];

int main()
{
	cin >> N >> K;
	for (int i = 0; i < N; i++)
		cin >> a[i];

	sort(a, a + N);

	int ans = N;
	for (int i = N-1; i >= 0; i--) {
		int num = 0;
		for (int j = i; j >= 0; j--) {
			if (num + a[j] >= K)ans = min(ans, j);
			else num += a[j]; 
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
import pprint
sys.setrecursionlimit(10 ** 9)


INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


class UnionFind:
    def __init__(self, n):
        # 負  : 根であることを示す。絶対値はランクを示す
        # 非負: 根でないことを示す。値は親を示す
        self.table = [-1] * n
        self.size = [1] * n
        self.group_num = n

    def root(self, x):
        if self.table[x] < 0:
            return x
        else:
            self.table[x] = self.root(self.table[x])
            return self.table[x]

    def get_size(self, x):
        r = self.root(x)
        return self.size[r]

    def is_same(self, x, y):
        return self.root(x) == self.root(y)

    def union(self, x, y):
        r1 = self.root(x)
        r2 = self.root(y)
        if r1 == r2:
            return
        # ランクの取得
        d1 = self.table[r1]
        d2 = self.table[r2]
        if d1 <= d2:
            self.table[r2] = r1
            self.size[r1] += self.size[r2]
            if d1 == d2:
                self.table[r1] -= 1
        else:
            self.table[r1] = r2
            self.size[r2] += self.size[r1]
        self.group_num -= 1

n, m, k = LI()
U = UnionFind(n)
AB = LIR(m)
for a, b in AB:
    U.union(a - 1, b - 1)

ans = [U.get_size(U.root(i)) - 1 for i in range(n)]
for a, b in AB:
    ans[a - 1] -= 1
    ans[b - 1] -= 1

for _ in range(k):
    c, d = LI()
    if U.is_same(c - 1, d - 1):
        ans[c - 1] -= 1
        ans[d - 1] -= 1


print(*ans)


Measured memory_bytes: 91228
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
//ll mod = 998244353;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main() {
    int x, a, b;
    cin >> x >> a >> b;
    if (abs(x - a) > abs(x - b)) {
        cout << "B" << endl;
    }
    else {
        cout << "A" << endl;
    }
    return 0;
}


Measured memory_bytes: 3624
fun main(args: Array<String>) {
    var S = readLine() // 入力を読み込む
    while(S!!.isNotEmpty()) {
        // 末端の文字列を比較する
        val suffixList = listOf("dreamer", "eraser", "dream", "erase")
        var foundSuffix = ""
        for (suffix in suffixList) {
            if (S.endsWith(suffix)) {
                foundSuffix = suffix
                break
            }
        }
        if (foundSuffix.isNotEmpty()) {
            S = S.removeSuffix(foundSuffix)
        } else {
            // もしどれにも該当しない場合 NG
            return println("NO")
        }
    }
    // 最後までいったら OK
    return println("YES")
}

Measured memory_bytes: 118908
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;

int main()
{
    int n;
    cin >> n;
    int temp = n;
    int length = 0;
    while(temp){
        temp /= 10;
        ++length;
    }
    vector<vector<int>> array(length,vector<int>());
    array.at(0).push_back(3);
    array.at(0).push_back(5);
    array.at(0).push_back(7);
    int i;
    for(i = 1;i < length;++i){
        for(int x : array.at(i-1)){
            array.at(i).push_back(x*10+3);
            array.at(i).push_back(x*10+5);
            array.at(i).push_back(x*10+7);
        }
    }
    int ans = 0;
    vector<bool> flag(3,false);
    for(i = 2;i < length;++i){
        for(int x : array.at(i)){
            if(x > n){continue;}
            while(x){
                if(x%10 == 3){
                    flag.at(0) = true;
                }else if(x%10 == 5){
                    flag.at(1) = true;
                }else{
                    flag.at(2) = true;
                }
                x /= 10;
            }
            if(flag.at(0) && flag.at(1) && flag.at(2)){
                ++ans;
            }
            flag.at(0) = false;
            flag.at(1) = false;
            flag.at(2) = false;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512
#include<map>
#include<cmath>
#include<stack>
#include<queue>
#include<cstdio>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
string s;
int main(){
    cin>>s;
    cout<<s[0];
    cin>>s;
    cout<<s[0];
    cin>>s;
    cout<<s[0];
    return 0;
}

Measured memory_bytes: 256
main = do
  [n, a, b] <- map read.words <$> getLine
  print $ solve n a b

solve n a b = (2 ^% n) -% comb n a -% comb n b -% 1

mo = 10^9 + 7 :: Int
a ^% b
  | b < 0 = 0
  | b == 0 = 1
  | otherwise = f a b
  where
    f a b
      | even b = f (a *% a) (quot b 2)
      | b == 1 = a
      | otherwise = g (a *% a) (quot b 2) a
    g a b c
      | even b = g (a *% a) (quot b 2) c
      | b == 1 = a *% c
      | otherwise = g (a *% a) (quot b 2) (a *% c)
a *% b = rem (a * b) mo
a /% b = a *% (b ^% (mo - 2))
comb a b = foldl (*%) 1 [a-b+1..a] /% foldl (*%) 1 [1..b]
a -% b = rem (mo + a - b) mo

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

int main()
{
    vector<long long> a(5);
    long long i,n;
    cin >> n;
    for(i = 0;i < 5;++i){
        cin >> a.at(i);
    }
    long long min = a.at(0);
    for(i = 1;i < 5;++i){
        if(min > a.at(i)){
            min = a.at(i);
        }
    }
    if(n%min){
        cout << n/min+5 << endl;
    }else{
        cout << n/min+4 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
vector< vector<int> > edg;
vector<bool> vsd;
const int s = 1e5;
void f(int v, int *xcnt, int *ycnt){
    if(vsd[v])return;
    vsd[v] = true;
    if(v < s) (*xcnt)++;
    else (*ycnt)++;
    for(int i = 0; i < edg[v].size(); i++){
        f(edg[v][i], xcnt, ycnt);
    }
}
int main(void){
    int n, xcnt, ycnt;
    long long ans = 0;
    cin >> n;
    edg.assign(s * 2, vector<int>());
    vsd.assign(s * 2, false);

    for(int i=0;i<n;i++){
        int x, y;
        cin >> x >> y;
        x--;
        y += s-1;
        edg[x].push_back(y);
        edg[y].push_back(x);
    }

    for(int i = 0; i < s * 2; i++){
        if(!vsd[i]){
            xcnt = ycnt = 0;
            f(i, &xcnt, &ycnt);
            ans += (long long) xcnt * ycnt;
        }
    }
    cout << ans - n << endl;
}


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

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

    // 入力値を配列に代入
    int arr[n];
    for (int i = 0; i < n; i++) {
        cin >> arr[i];
    }

    // 配列の値を逆順に出力
    for (int i = n; i > 0; i--) {
        cout << arr[i-1];
        if(i-1 != 0) cout <<" ";
    }
    cout << "\n";
}



Measured memory_bytes: 3052
#include <bits/stdc++.h>
 
#define scd second
#define fst first
#define pb push_back
#define mkp make_pair
#define all(x) x.begin(), x.end()
#define VT(T) vector<T>
 
using namespace std;
 
typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vint;
typedef vector<ll> vlong;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vint> vvint;
typedef vector<vlong> vvlong;
typedef list<int> lint;
typedef list<ll> llong;
typedef list<pii> lpii;
typedef list<pll> lpll;
typedef list<lint> llint;
typedef list<llong> lllong;
 
ll const LINF=numeric_limits<long long int>::max();
int const INF=numeric_limits<int>::max();
 
ll gcd(ll a, ll b){
	return b ? gcd(b,a%b) : a;
}
 
ll pow_mod(ll a, ll e, ll m){
	ll res=1;
	while(e){
		if(e&1) res=res*a%m;
		a=a*a%m;
		e>>=1;
	}
	return res;
}
 
ll inv_mod(ll b, ll m){
	b%=m;
	ll x=0, y=1, r, q, a=m;
	while(b){
		q=a/b;
		r=a%b;
		a=b;
		b=r;
		r=x;
		x=y;
		y=r-q*y;
	}
	x+=m;
	return x%m;
}

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

	int n, k;
	cin>>n>>k;
	vlong fact(n+1,1), ifact(n+1,1);
	ll mod=1e9+7;
	for(int i=1; i<=n; i++){
		fact[i]=fact[i-1]*i%mod;
		ifact[i]=inv_mod(fact[i],mod);
	}

	vlong arr(n);
	for(int i=0; i<n; i++) cin>>arr[i];
	sort(all(arr));

	ll a=0, b=0;
	for(int i=n-1; i>=0; i--){
		if(i>=k-1){
			ll cnt=(fact[i]*ifact[k-1]%mod)*ifact[i+1-k]%mod;
			a+=arr[i]*cnt%mod;
		}
	}
	a%=mod;
	
	for(int i=0, j=n-1; i<n; i++,j--){
		if(j>=k-1){
			ll cnt=(fact[j]*ifact[k-1]%mod)*ifact[j+1-k]%mod;
			b+=arr[i]*cnt%mod;
		}
	}
	b%=mod;

	cout<<(mod+a-b)%mod<<endl;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
#define int long long

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
	//freopen("input.txt", "r", stdin);
	
	int a; cin>>a;
  cout<< 3 * a * a;
	
	
	
	
}

Measured memory_bytes: 256
using System;
using System.Text;

namespace AOJ.Volume0
{
    public class FlyingJenny
    {
        public static int Main()
        {
            var output = new StringBuilder();
            // merry[0]???merry[7]????????????????????????????????????????????§2??¨?????¨???????????????
            var merry = new int[16] { 4, 1, 4, 1, 2, 1, 2, 1, 4, 1, 4, 1, 2, 1, 2, 1 };
            while (true)
            {
                var input = Console.ReadLine();
                if (string.IsNullOrEmpty(input)) { break; }
                int[] wait = new int[8];
                var data = input.Split(' ');
                for(int i = 0; i < 8; i++) { wait[i] = int.Parse(data[i]); }

                // ?????¢???????????????
                // merry[0]??????merry[7]?????§???????????????????????°????¨??????????
                int ans = int.MaxValue; // ??????????£?
                int chk = int.MaxValue; // ????°?????¢????
                for (int i = 0; i < 8; i++)
                {
                    int tmp = 0;
                    for (int j = 0; j < 8; j++) { tmp += wait[j] > merry[i + j] ? wait[j] - merry[i + j] : 0; }
                    if (chk > tmp)
                    {
                        string tmp_ans = "";
                        for (int j = i; j < i + 8; j++) { tmp_ans += merry[j].ToString(); }
                        ans = int.Parse(tmp_ans);
                        chk = tmp;
                    }
                    else if (chk == tmp)
                    {
                        // ????????´????????????????°?????????°????????\??????????????????
                        string tmp_ans = "";
                        for(int j = i; j < i + 8; j++) { tmp_ans += merry[j].ToString(); }
                        ans = Math.Min(ans, int.Parse(tmp_ans));
                    }
                }
                string answer = "";
                for(int i = 0; i < 8; i++) { answer += ans.ToString()[i] + " "; }
                output.AppendLine(answer.Trim());
            }

            Console.Write(output);
            return 0;
        }
    }
}

Measured memory_bytes: 9240
package main

import (
	"fmt"
	"io"
	"os"
)

func main() {
	solve(os.Stdin, os.Stdout)
}

func solve(in io.Reader, out io.Writer) {
	var k int
	fmt.Fscanf(in, "%d", &k)

	fmt.Fprintln(out, (k/2)*((k+1)/2))
}


Measured memory_bytes: 512
#include <iostream>

using namespace std;

int main(){
	int n,r,p,c;
	int huda[51],hoge[51];

	while(1){

		//n:RDÌ  r:DðØéñ
		cin >> n >> r;
		if(n==0 && r==0)break;//0 0¾Á½çI¹

		//RDª5Èçã©çÉ54321ÆÈéæ¤É·é
		for(int i=0 ; i<n ; i++){
			huda[i] = n-i;
			hoge[i] = huda[i];
		}
		
		//rñ¾¯RDðVbt·é
		for(int i=0 ; i<r ; i++){
			//ã©çpÚÌD©çc²«æèRDÌêÔãÉÁÄ­é
			cin >> p >> c;
			p--;

			//ã©çpÚ©çp+cÚÜÅðêÔãÉÁÄ­éìðs¤
			for(int j=0 ; j<c ; j++){
				hoge[j] = hoge[p+j];
			}
			//cèÌDðºÉÁ¦é
			for(int j=0 ; j<p ; j++){
				hoge[c+j] = huda[j];
			}
			
			//ÅãÉhogeðhudaÉRs[·é
			for(int j=0 ; j<51 ; j++){
				huda[j] = hoge[j];
			}
		}

		//¦ÌoÍ
		cout << huda[0] << endl;
	}

	return 0;
}

Measured memory_bytes: 0
import numpy as np
[N,W],*h = [list(map(int,i.split())) for i in open(0)]

dp = np.zeros(W+1, dtype=int)

for i in range(N):
    w = h[i][0]
    v = h[i][1]
    dp[w:] = np.maximum(dp[:-w]+v,dp[w:])
print(dp[-1])

Measured memory_bytes: 29740
import java.util.Scanner;

public class Main {

    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int[] v = new int[n];
        int[] c = new int[n];

        for (int i = 0; i < n; i++) {
            v[i] = sc.nextInt();
        }

        for (int i = 0; i < n; i++) {
            c[i] = sc.nextInt();
        }
        sc.close();

        int ans = 0;

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

        System.out.println(ans);
    }
}

Measured memory_bytes: 22608
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>

int CalcBFS(int a, int b, std::vector<std::string>S, int hmax, int wmax)
{
	int res = 0;
	std::queue<std::pair<int, int>> Q;
	std::vector<std::vector<int>>d(hmax, std::vector<int>(wmax, -1));

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

	d[a][b] = 0;
	Q.push(std::make_pair(a, b));
	while (!Q.empty())
	{
		auto cur = Q.front();
		Q.pop();
		int y = cur.first;
		int x = cur.second;

		for (int i = 0; i < 4; i++)
		{
			int ny = y + dy[i];
			int nx = x + dx[i];

			if (ny < 0 || nx < 0 || ny >= hmax || nx >= wmax){ continue; }
			if (S[ny][nx] == '#' || d[ny][nx] != -1){ continue; }

			d[ny][nx] = d[y][x] + 1;

			Q.push(std::make_pair(ny, nx));
		}


	}

	for (int i = 0; i < hmax; i++)
	{
		for (int j = 0; j < wmax; j++)
		{
			res = std::max(res, d[i][j]);
		}
	}

	return res;
}

int main()
{
	int H = 0, W = 0, ans = 0;
	std::cin >> H >> W;

	std::vector<std::string> S(H);
	for (int i = 0; i < H; i++)
	{
		std::cin >> S[i];
	}
	int row = S.size();
	int col = 0;
	for (int i = 0; i < H; i++){
		col = std::max((int)(S[i].length()) , col);
	}

	for (int i = 0; i < H; i++)
	{
		for (int j = 0; j < W; j++)
		{
			if (S[i][j] == '#') continue;
			ans = std::max(ans, CalcBFS(i, j, S, row, col));
		}
	}
	std::cout << ans << std::endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int main()
{
  cout << fixed << setprecision(10);
  int a,b;
  cin >> a >> b;
  vector<int> vec(1000);
  int sum = 0;
  rep(i,1000)
  {
    sum += i;
    vec[i] = sum;
  }
  cout << vec[b-a] - b << endl;
  return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
//4/
typedef unsigned long long ull;
typedef long long ll;
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define rep(i, n)    for(ll i = 0; i < (n); ++i)
#define repA(i, a, n)  for(ll i = a; i < (n); ++i)
#define repD(i, a, n)  for(ll i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (ll)(x).size()
#define fill(a)  memset(a, 0, sizeof (a))
#define fill_2(a,b)  memset(a, 0, sizeof (a));memset(b, 0, sizeof (b));
#define fill_n(a) memset(a,-1,sizeof(a))
#define fst first
#define snd second
#define mpr make_pair
#define pb push_back
#define mod 1000000007
#define endl "\n"
//#define int long long
 
typedef long double ld;
typedef pair<ll, ll> pii;
typedef pair<ll, pii> pip;
typedef pair<pii, ll> ppi;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef map<ll,ll> mpl;
ll fac[1000006];
inline ll exp(ll x,ll n){ll r=1;x=x%mod;while(n){if(n%2)r=(r*x)%mod;x=(x*x)%mod;n=n/2;}return r;}
inline ll mmi(ll a){return exp(a,mod-2)%mod;}
inline ll fact(ll n){ll res=1;repA(i,1,n+1){res=(res*i)%mod;}return res;}
inline void fact_a(){fac[0]=1;fac[1]=1;repA(i,1,1000006){fac[i]=(fac[i-1]*i)%mod;}}
inline ll inv_fact(ll n){fact_a();ll par=fac[n];ll res=mmi(par);return res;}
inline ll comb(ll n,ll r){fact_a();if(n<r)return 0;return ((fac[n]*inv_fact(r))%mod*inv_fact(n-r))%mod;}
 
struct triplet{ll a,b,c;};
bool operator < (const triplet &t1,const triplet &t2){
	if(t1.a<t2.a)return true;
	if(t1.a==t2.a && t1.b <t2.b)return true;
	if(t1.a==t2.a && t1.b ==t2.b && t1.c<t2.c)
		return true;return false;}
 
pair<ll,pii > ex_gcd(ll a,ll b)
{   if(b==0){return mpr(a,mpr(1,0));}
    pip p=ex_gcd(b,a%b);
	ll gcd=p.fst;ll x1=p.snd.fst;ll y1=p.snd.snd;
    ll x=y1;ll y=x1-(a/b)*y1;
	return mpr(gcd,mpr(x,y));
} 
ll prime[1000006];
ll spf_prime[1000006];
void sieve(){for(ll i=2;i*i<=1000000;i++)if(prime[i]==0)for(ll j=i*i;j<=1000000;j+=i)prime[j]=1;}
void spf(){
	 for(ll i=2;i*i<=1000000;i++)if(!spf_prime[i])for(ll j=i*i;j<=1000000;j+=i)if(!spf_prime[j])spf_prime[j]=i;
		for(ll i=2;i<=1000000;i++)if(!spf_prime[i])spf_prime[i]=i;
}
ll getparent_BIT(ll idx)
{
    return idx-(idx& -idx);
}
ll getnext_BIT(ll idx)
{
    return idx+(idx& -idx);
}
ll getsum_BIT(ll idx,ll BIT[],ll n)
{   
	//idx++;
	ll sum=0;
	while(idx>0)
	{
      sum+=BIT[idx];
      idx=getparent_BIT(idx);
      
	}
	return sum;
}
void update_BIT(ll idx,ll BIT[],ll val,ll n)
{
	//idx++;
	while(idx<=n)
	{
		BIT[idx]+=val;
		idx=getnext_BIT(idx);
	}
}
void build_BIT(ll BIT[],ll a[],ll n)
{
	repA(i,0,n)
	{
		update_BIT(i,BIT,a[i],n);
	}
}

int main()
{
	IOS;
	ll n,a,b;
	cin>>n>>a>>b;
	if(a>b)
		swap(a,b);
	ll diff=(b-a);
	if(diff&1)
	{
      ll f=a-1+1+(diff/2);
      ll s=n-b+1+(diff/2);
      cout<<min(f,s)<<endl;
	}
	else
	{
		cout<<diff/2<<endl;
	}
}

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


int main(){
    int N, M;
    cin >> N >> M;
    vector<int> A(N);
    int total_vote = 0; //総得票数
    for(int i = 0; i < N; i++){
        cin >> A[i];
        total_vote += A[i];
    }
    double border = 1.0 * total_vote / (4 * M);
    int cnt = 0;
    for(int i = 0; i < N; i++){
        if(A[i] >= border){
            cnt++;
        }
    }

    if(cnt >= M){
        cout << "Yes" << endl;
    }else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int main() {
    int D, G;
    cin >> D >> G;
    vector<int> P(D), C(D);
    rep(i, D) cin >> P[i] >> C[i];
    int res = INF;
    for(int bit = 0; bit < (1 << D); bit++) {
        int score = 0;
        int num = 0;
        for(int i = 0; i < D; i++) {
            if(bit & (1 << i)) {
                score += C[i];
                score += 100 * (i + 1) * P[i];
                num += P[i];
            }
        }
        vector<int> list;
        for(int i = D - 1; i >= 0; i--) {
            if(!(bit & (1 << i))) {
                for(int j = 0; j < P[i]; j++)
                    list.pb(100 * (i + 1));
            }
        }
        for(auto x : list) {
            if(score >= G)
                break;
            score += x;
            num++;
        }
        if(score >= G) {
            res = min(res, num);
        }
    }
    cout << res << endl;
    return 0;
}

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

const int N_MAX = 2e5;

int n;
int x[N_MAX + 2], aux[N_MAX + 2];

int med[3];

int main() {
    cin >> n;
    for(int i = 1; i <= n; i++) {
        cin >> x[i];
        aux[i] = x[i];
    }

    sort(aux + 1, aux + n + 1);
    med[0] = aux[n / 2];
    med[1] = aux[n / 2 + 1];

    for(int i = 1; i <= n; i++) {
        if(x[i] < med[1])
            cout << med[1];
        else
            cout << med[0];
        cout << '\n';
    }

    return 0;
}


Measured memory_bytes: 3712
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <iostream>
#include <vector>
#include <queue>
#include <unordered_map>
#include <random>
#include <stack>
#include <set>
#include <unordered_set>

#define bug(x) cout<<"zdongdebug1: "<<x<<endl;
#define bug2(x, y) cout<<"zdongdebug2: "<<x<<" "<<y<<endl;
#define bug3(x, y, z) cout<<"zdongdebug3: "<<x<<" "<<y<<" "<<z<<endl;
using namespace std;
typedef long long ll;
const int maxn = 200005;
const int mod = 1000000007;



int main() {
#ifdef suiyuan2009
  freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin);
  //freopen("/Users/suiyuan2009/CLionProjects/icpc/output.txt", "w", stdout);
#endif
  string s;
  cin>>s;
  bool sign = 0;
  if(s.size()&1)sign=1;
  for(int i=0;i<s.size();i++){
    if((i&1)&&s[i]!='i')sign=1;
    if(s[i]!='h'&&!(i&1))sign=1;
  }
  if(sign)cout<<"No"<<endl;
  else cout<<"Yes"<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <ctype.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)


long long h[100000];
int tou[100000];
int main(){
	int n,m;
	cin >> n >> m;
	int a,b;
	REP(i,n) tou[i] = 1;
	
	REP(i,n){
		cin >> h[i];
	}
	REP(i,m){
		cin >> a >> b;
		if(h[a-1] == h[b-1]){
			tou[b-1]=0;
			tou[a-1]=0;
		}else if(h[a-1] > h[b-1]){
			tou[b-1]=0;
		}else if(h[a-1] < h[b-1]){
			tou[a-1]=0;
		}
	}
	
	int ans = 0;
	
	REP(i,n){
		
		if(tou[i] == 1){
			ans++;
		}
	}
	
	cout << ans << endl;
	
	
	
	
	
	
	
	return 0;
}

Measured memory_bytes: 4792
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int num=n,all=0,t=0;
  while (num) {
    t = num%10;
    all += t;
    num /= 10;
  }
  if (n%all == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>
using namespace std;

long long int k,s,res=0;

int main() {
    const long long int mod = 1000000007,INF=99999999999999;
	map<long long int, long long int>mp;
	cout << fixed << setprecision(10);
    cin>>k>>s;
    for(int i=0;i<=k;i++){
        if(s-i<0||s-i>2*k){continue;}
        res+=k+1-abs(s-i-k);
    }
    cout<<res;
} 


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

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

int main(){
	int n;cin>>n;
	vector<int>a(n);
	rep(i,n)cin>>a[i];
	vector<int>v;
	rep(i,n)v.push_back(i);
	sort(v.begin(),v.end(),[&](int l,int r){return a[l]<a[r];});
	for(int i:v){
		cout<<i+1<<endl;
	}
}

Measured memory_bytes: 1784
#include<bits/stdc++.h>
#define assn(n,a,b) assert(n<=b && n>=a)
using namespace std;
#define pb push_back
#define mp make_pair
#define clr(x) x.clear()
#define sz(x) ((int)(x).size())
#define F first
#define S second
#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,b) for(i=0;i<b;i++)
#define rep1(i,b) for(i=1;i<=b;i++)
#define pdn(n) printf("%d\n",n)
#define sl(n) scanf("%lld",&n)
#define sd(n) scanf("%d",&n)
#define pn printf("\n")
typedef pair<int,int> PII;
typedef vector<PII> VPII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef long long LL;
#define MOD 1000000007
LL mpow(LL a, LL n)
{LL ret=1;LL b=a;while(n) {if(n&1)
    ret=(ret*b)%MOD;b=(b*b)%MOD;n>>=1;}
return (LL)ret;}
#define MAXK 100000
#define MAXN 1000000000
int ar[MAXK];
int get(int n, int k){
    int i=0;
    while(i<k and ar[i]<=n)i++;
    return n-i;
}
typedef unsigned long long int ULL;
#define SSTR( x ) static_cast< std::ostringstream & >( \
        ( std::ostringstream() << std::dec << x ) ).str()
 
bool isSafe(int r, int c, vector<vector<int> > arr) {
	int n = arr.size();
	int m = arr[0].size();
	return (r>=0 && r<n && c>=0 && c<m);
}
 
/////////////////////////////////////////////////////////////

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int x,y,z;
    cin>>x>>y>>z;
    cout<<z<<" "<<x<<" "<<y;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  double ans=0;
  for (int i = 0; i < N; i++) {
    double x;
    string u;
    cin >> x >> u;
    if (u == "JPY") {
      ans += x;
    }
    else {
      ans += x*380000;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256