akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> P;
map <int,int> mp;
vector<int> V;
list<int> L;
stack<int> S;
queue<int> Q;
deque<int> dq;
#define INF (1<<30)
#define INFLL (1ll<<60)
#define EPS (1e-10)
static const int MAX=100000;
static const int NMAX=50;
static const int MMAX=50;
ll H,W;
ll ans=INFLL;

int main(){
    cin.tie(0);  ios::sync_with_stdio(false);
    
    cin>>H>>W;
    
    if(H%3==0||W%3==0){
        cout<<0<<"\n";
        return 0;
    }else{
        for(int k=0;k<2;k++){
            ans=min(ans,(H/3+1)*W-H/3*W); //割り切れない時必ず最大(H+1)/3,最小H/3
            swap(H,W);
        }
    }
    
    //次は縦＋横二分割
    
    for(int k=0;k<2;k++){
        for(int ha=1;ha<=H;ha++){
            ll a=ha*W;
            ll b=(H-ha)*(W/2);
            ll c=(H-ha)*((W+1)/2);
            ans=min(ans,max(a,max(b,c))-min(a,min(b,c)));
        }
        swap(H,W);
    }
    cout<<ans<<"\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int a, b, c;
  cin >> a >> b >> c;

  cout << ((a + b + c) >= 22 ? "bust" : "win") << '\n';
  return 0;
}

Measured memory_bytes: 256
import * as fs from "fs"
const process = (n: number, b: number[]): string => {
  const res: number[] = []
  res.push(b[0])

  for (let i = 0; i < n - 2; i++) {
    if (b[i] <= b[i + 1]) {
      res.push(b[i])
    } else {
      res.push(b[i + 1])
    }
  }

  res.push(b[b.length - 1])
  return "" + res.reduce((a, b) => a + b, 0)
}

const Main = (input: string): string => {
  const aa: string[][] = input.split("\n").map((e) => e.split(" "))
  const na0: number[] = aa[0].map((e) => parseInt(e))
  const na1: number[] = aa[1].map((e) => parseInt(e))
  const [n] = na0

  const res = process(n, na1) + ""
  console.log(res)
  return res
}
Main(fs.readFileSync("/dev/stdin", "utf8"))


Measured memory_bytes: 7372
a = list(map(int, input().split()))
a.sort(reverse=True)

c = a[0] - a[1]
b = a[0] - a[2]

ans = c // 2 + b // 2
c %= 2
b %= 2

if c == 0 and b == 0:
    print(ans)
elif c == 1 and b == 1:
    print(ans + 1)
else:
    print(ans + 2)


Measured memory_bytes: 3060
import sys
input = sys.stdin.readline
sys.setrecursionlimit(2 * 10**6)


def inpl():
    return list(map(int, input().split()))


def count_v(last_d, C, S, t, d):
    ret = S[t - 1]
    last_d[t - 1] = d
    for i in range(len(last_d)):
        ret -= C[i] * (d - last_d[i])
    return ret


def main():
    D = int(input())
    C = inpl()
    Ss = [inpl() for _ in range(D)]
    T = [int(input()) for _ in range(D)]
    last_d = [-1] * len(C)

    v = 0
    for d in range(D):
        tmp = count_v(last_d, C, Ss[d], T[d], d)
        v += tmp
        print(v)

    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 68172
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,n;
  int l=1;
  int r=10;
  int s=0;
  cin >> N;
  
  for(int i=0;1;i++){
    if(l<=N&&N<r){
      n=i+1;
      break;
    }
    l*=10;
    r*=10;
  }
   
  l=1;
  for(int i=0;i<n;i++){
    s+=((N/l)%10);
    l*=10;    
  }
  if (N%s==0){
    cout<<"Yes"<<endl;
  }
  else {
    cout << "No" <<endl;
  }
}
      
        


Measured memory_bytes: 256
#include<stdio.h>
#define MOD 1000000007
int main(){
    int n,i,j;
    long long a[200002];
    long long ans = 0;
    long long tmp;
    long long times_sum = 0;
    
    scanf("%d",&n);
    for(i = 0; i < n; i++) scanf("%lld",&a[i]);
    for(i = 1; i < n; i++) times_sum += a[i];
    
    tmp = a[0] * (times_sum % MOD);
    ans += tmp;
    ans %= MOD;
    //     printf("ans = %lld\n",ans);
    //     printf("times_sum = %lld\n",times_sum);
    
    for(i = 1; i < n-1; i++){
        times_sum -= a[i];
        //         printf("times_sum = %lld\n",times_sum);
        tmp = a[i] * (times_sum % MOD);
        //         prinprintf("ans = %lld\n",ans);
        ans += tmp;
        ans %= MOD;
    }
    
    printf("%lld\n",ans);
    return 0;
}



Measured memory_bytes: 3208
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
	int a, b;
	string s;
	cin >> a >> b >> s;
	vector<int>r(b);
	vector<int>l(b);
	for (int i = 0; i < b; i++) {
		cin >> r[i] >> l[i];
	}
	vector<int>abc(a + 1, 0);
	for (int i = 1; i < a; i++) {
		if (s[i - 1] == 'A' && s[i] == 'C')abc[i + 1] = abc[i] + 1;
		else abc[i + 1] = abc[i];
	} 
	for (int i = 0; i < b; i++) {
		int c = abc[r[i]]-abc[l[i]];
		cout << c*-1 << endl;
	}
	return 0;
}

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

#define int long long
#define rep(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define reps(i, n) for (int (i) = 1; (i) <= (n); (i)++)
#define all(x) (x).begin(), (x).end()
#define bit(n) (1LL << (n))
typedef vector<int> vint;
typedef pair<int, int> pint;
constexpr double PI = 3.1415926535897932384626433832795028;
constexpr int DY[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int DX[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
template<typename T, typename U> inline bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> inline bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
struct SetUp {
    SetUp() {
        cout << fixed << setprecision(20);
        cerr << fixed << setprecision(20);
    };
} setUp;

int H, W, N;
int sr, sc;
string S, T;
void end() {
    cout << "NO" << endl;
    exit(0);
}
signed main() {
    cin >> H >> W >> N;
    cin >> sr >> sc;
    cin >> S >> T;
    int y = sr;
    rep(i, N) {
        if (S[i] == 'U') { y--; }
        if (y == 0) { end(); }
        if (T[i] == 'D' && y < H) { y++; }
    }
    y = sr;
    rep(i, N) {
        if (S[i] == 'D') { y++; }
        if (y == H + 1) { end(); }
        if (T[i] == 'U' && y > 1) { y--; }
    }
    int x = sc;
    rep(i, N) {
        if (S[i] == 'L') { x--; }
        if (x == 0) { end(); }
        if (T[i] == 'R' && x < W) { x++; }
    }
    x = sc;;
    rep(i, N) {
        if (S[i] == 'R') { x++; }
        if (x == W + 1) { end(); }
        if (T[i] == 'L' && x > 1) { x--; }
    }
    cout << "YES" << endl;
}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

template<class A,class B>
ostream& operator<<(ostream& ost,const pair<A,B>&p){
	ost<<"{"<<p.first<<","<<p.second<<"}";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost,const vector<T>&v){
	ost<<"{";
	for(int i=0;i<v.size();i++){
		if(i)ost<<",";
		ost<<v[i];
	}
	ost<<"}";
	return ost;
}


signed main(){
	vector<string>uku{"SUN","MON","TUE","WED","THU","FRI","SAT"};

	string s;cin>>s;

	int k=find(all(uku),s)-uku.begin();

	cout<<7-k<<endl;
	return 0;
}

Measured memory_bytes: 256
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder.Contest.C
{
	static class Program
	{
		public static void Main(string[] args)
		{
			var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
			Console.SetOut(sw);

			var cin = new Scanner();

			int n = cin.NextInt();
			var a = cin.ArrayInt(n);
			Array.Sort(a);
			double ans = a[0];
            for (int i = 1; i < n; i++)
            {
				ans += a[i];
				ans /= 2;
            }
            Console.WriteLine(ans);

			Console.Out.Flush();
		}
	}

	class Scanner
	{
		string[] s;
		int i;

		char[] cs = new char[] { ' ' };

		public Scanner()
		{
			s = new string[0];
			i = 0;
		}

		public string Next()
		{
			if (i < s.Length) return s[i++];
			string st = Console.ReadLine();
			while (st == "") st = Console.ReadLine();
			s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
			if (s.Length == 0) return Next();
			i = 0;
			return s[i++];
		}

		public int NextInt()
		{
			return int.Parse(Next());
		}

		public int[] ArrayInt(int N, int add = 0)
		{
			int[] Array = new int[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = NextInt() + add;
			}
			return Array;
		}

		public long NextLong()
		{
			return long.Parse(Next());
		}

		public long[] ArrayLong(int N, long add = 0)
		{
			long[] Array = new long[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = NextLong() + add;
			}
			return Array;
		}

		public double NextDouble()
		{
			return double.Parse(Next());
		}

		public double[] ArrayDouble(int N, double add = 0)
		{
			double[] Array = new double[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = NextDouble() + add;
			}
			return Array;
		}
	}
}

Measured memory_bytes: 11220
from collections import namedtuple


def solve(arms):
    arms = sorted(arms, key=lambda x: x.right)
    right = -float("inf")
    res = 0
    for arm in arms:
        if right <= arm.left:
            res += 1
            right = arm.right

    return res


Arm = namedtuple("Arm", ["center", "left", "right"])


arms = []
N = int(input())
for _ in range(N):
    x, length = [int(val) for val in input().split(" ")]
    arm = Arm(x, x - length, x + length)
    arms.append(arm)


ans = solve(arms)
print(ans)


Measured memory_bytes: 71640
import sys
sys.setrecursionlimit(10**8)
N = int(input())
a = [[] for i in range(N)]
for i in range(N-1):
  A, B, C = map(int, input().split())
  a[A-1].append([B-1, C])
  a[B-1].append([A-1, C])
dist = [-1]*N
Q, K = map(int, input().split())
dist[K-1] = 0

def dfs(now):
  for i, dis_e in a[now]:
    if dist[i] == -1:
      dist[i] = dist[now] + dis_e
      dfs(i)

def main():
  dfs(K-1)
  ans = []
  for i in range(Q):
    x, y = map(int, input().split())
    ans.append(dist[x-1]+dist[y-1])
  print(*ans, sep = "\n")

if __name__ == "__main__":
  main()

Measured memory_bytes: 140540
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
using ll=long long;
static const ll mod = 1e9 + 7;
static const ll INF = 1LL << 50;
using namespace std;

int main(){
	string a,b,c;
	cin>>a>>b>>c;
	char pre=a[0];
	string next;
	a.erase(a.begin());
	while(1){
		if(pre=='a'){
			pre=a[0];
			if(a==""){
			cout<<"A"<<endl;
			return 0;}
			a.erase(a.begin());
		}
		else if(pre=='b'){
			pre=b[0];
			 if(b==""){
			cout<<"B"<<endl;
			return 0;
			 }
			b.erase(b.begin());
		}
		else {
			pre=c[0];
			 if(c==""){
			cout<<"C"<<endl;
			return 0;
		}
			c.erase(c.begin());
		}
		
	}

}


Measured memory_bytes: 256
import java.util.*;

class Main {

	static Scanner sc;

	static void solve() {

		int ans = 0;
		for (int i = 0; i < 5; ++i) {
			int tmp = sc.nextInt();
			if (tmp == 0) ans = i + 1;
		}

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

		solve();
    }
}


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

bool comp (string a, string b) {
    if (a < b) return true;
    else return false;
}

int main() {
    int n, l;
    vector<string> s;
    string a;
    cin >> n >> l;
    for (int i = 0; i < n; i++) {
        cin >> a;
        s.push_back(a);
    }
    sort(s.begin(), s.end(), comp);
    for (int i = 0; i < n; i++) {
        cout << s[i];
    }
    cout << endl;
}

Measured memory_bytes: 256
type int = integer;
var c : array[1..4] of char;
    i : int;
    a, b : int;
    
function isM(y : integer) : Boolean;
begin
  isM := (y >= 1) and (y <= 12);
end;
begin
  for i := 1 to 4 do read(c[i]);
  a := (int(c[1]) - int('0')) * 10 + (int(c[2]) - int('0'));
  b := (int(c[3]) - int('0')) * 10 + (int(c[4]) - int('0'));
  if isM(a) then
  begin
    if isM(b) then writeln('AMBIGUOUS')
    else writeln('MMYY')
  end
  else
  begin
    if isM(b) then writeln('YYMM')
    else writeln('NA')
  end;
end.

Measured memory_bytes: 128
object Main {

  import java.util.Scanner

  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)
    val writer = new java.io.PrintWriter(System.out)
    writer.println(solve(sc))
    writer.flush()
  }

  def solve(sc: Scanner): String = {
    val (n, m) = (sc.nextInt(), sc.nextInt())
    val cards = Array.fill(n)(sc.nextLong()).sorted
    debug(n, m, cards.toSeq)

    var cardsIdx = 0
    IndexedSeq.fill(m)((sc.nextInt(), sc.nextLong())).sortBy(_._2).reverse.foreach { case (b, c) =>
      var replaced = false
      var i = cardsIdx
      while (i < b + cardsIdx && i < cards.length && cards(i) < c) {
        cards(i) = c
        replaced = true
        i += 1
      }
      cardsIdx = i
    }
    cards.sum.toString
  }

  private def debug(x: Any): Unit = {
    if (System.getenv("LOCAL_DEBUG") != null) println(x)
  }
}


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

#define rep(i,n) for(int i=0; i<n; i++)
#define rept(i,a,b) for(int i=a; i<b; i++)
#define all(x) (x).begin(),(x).end()
#define fst first
#define sec	second
#define pb push_back

typedef long long ll;
typedef vector<int> vi;
typedef pair<long,long> P;

const int mod = 1e9 + 7;


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

	int n, k;
	string s;
	cin >> n >> k;
	cin >> s;

	ll ans = n-1;
	ll cnt = n-1;
	rep(i, n-1){
		if(s[i] != s[i+1]){
			cnt--;
		}
	}

	ans = min(ans, cnt+2*k);
	cout << ans << endl;
    return 0;
}



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

using namespace std;

class FizzBuzzSum
{
private:
  struct TestCase
  {
    unsigned long long N = 0;

    unsigned long long result = 0;
  };
  TestCase T = {};

public:
  void run()
  {
    Input();

    Calc();

    Output();
  }


private:
  void Calc()
  {
    int x = T.N / 15;
    int y = T.N % 15;

    T.result = 0;
    for (int i = 0; i < x; ++i)
    {
      int base = 15 * i * 8;
      T.result += (base + 60);
    }

    int base = 15 * x;
    for (int i = 1; i <= y; ++i)
    {
      switch (i)
      {
      case 1:
      case 2:
      case 4:
      case 7:
      case 8:
      case 11:
      case 13:
      case 14:
        T.result += (base + i);
        break;
      default:
        break;
      }
    }

  }

  void Input()
  {
    cin >> T.N;
  }

  void Output()
  {
    cout << T.result << "\n" << flush;
  }
};

int main()
{
  FizzBuzzSum prob = {};
  prob.run();

  return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
using namespace std;

#include <unordered_map>

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

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

    for (ll x = 1; x <= 3500; x++){
        for (ll y = 1; y <= 3500; y++){
            ll p = 4*x*y - n*y - n*x;
            ll q = x*y*n;
            if (p >= 1 && q % p == 0 && q / p <= 3500){
                printf("%lld %lld %lld\n", x, y, q/p);
                return 0;
            }
        }
    }

    return 0;
}





Measured memory_bytes: 256
from itertools import product

N = int(input())
ab = [tuple(map(int, input().split())) for _ in range(N-1)]
M = int(input())
uv = [tuple(map(int, input().split())) for _ in range(M)]


class Node:
    def __init__(self, nodeid, parent=None):
        self.nodeid = nodeid
        self.parent = parent
        self.children = []

    def add_child(self, nodeid, edgeid):
        child = Node(nodeid, parent=self)
        self.children.append((child, edgeid))

    def parents(self):
        if self.parent == None:
            return [self.nodeid]
        else:
            return [self.nodeid] + self.parent.parents()

    def path(self, to):
        if to == self.nodeid:
            return []
        for child, edgeid in self.children:
            try:
                ret = [edgeid] + child.path(to)
                return ret
            except ValueError:
                pass
        raise ValueError


root = Node(1)
nodes = {1: root}
leef = [root]
while len(leef) > 0:
    node = leef.pop()
    parentid = node.parent and node.parent.nodeid
    for i, (a, b) in enumerate(ab):
        if a == node.nodeid and b != parentid:
            node.add_child(b, i)
            leef.append(node.children[-1][0])
            nodes[b] = node.children[-1][0]
        elif b == node.nodeid and a != parentid:
            node.add_child(a, i)
            leef.append(node.children[-1][0])
            nodes[a] = node.children[-1][0]


constraints = [0]*M

for i, (u, v) in enumerate(uv):
    parents_u = nodes[u].parents()
    for p in nodes[v].parents():
        if p in parents_u:
            break
    for j in nodes[p].path(u):
        constraints[i] += pow(2, j)
    for j in nodes[p].path(v):
        constraints[i] += pow(2, j)

ans = 0
for idx in product([True, False], repeat=M):
    sumidx = sum(idx)
    constraint = 0
    for i, flg in enumerate(idx):
        if flg:
            constraint = constraint | constraints[i]
    C = bin(constraint)[2:].count('1')
    ans += pow(2, N-1-C) * ((-1)**(sumidx%2))

print(ans)


Measured memory_bytes: 74808
import sys
sys.setrecursionlimit(1000000000)
import math
from fractions import gcd
def lcm(a, b): return a * b // gcd(a, b)
from itertools import count, permutations
from functools import lru_cache
from collections import deque, defaultdict
from pprint import pprint
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
N1097 = 10**9 + 7

def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok

def get_inv(n, modp):
    return pow(n, modp-2, modp)

def factorials_list(n, modp):    # 10**6
    fs = [1]
    for i in range(1, n+1):
        fs.append(fs[-1] * i % modp)
    return fs

def invs_list(n, fs, modp):     # 10**6
    invs = [get_inv(fs[-1], modp)]
    for i in range(n, 1-1, -1):
        invs.append(invs[-1] * i % modp)
    invs.reverse()
    return invs

def comb(n, k, modp):
    num = 1
    for i in range(n, n-k, -1):
        num = num * i % modp
    den = 1
    for i in range(2, k+1):
        den = den * i % modp
    return num * get_inv(den, modp) % modp


def comb_from_list(n, k, modp, fs, invs):   
    return fs[n] * invs[n-k] * invs[k] % modp

#

def main():
    n,a,b=mis()
    print((pow(2, n, N1097) - comb(n, a, N1097) - comb(n, b, N1097) - 1) % N1097)

main()



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

long long sum(long long n) {
    return n * (n + 1) / 2;
}

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

    long long ans = sum(N) - sum(N/3) * 3 - sum(N/5) * 5 + sum(N/15) * 15;
    cout << ans << endl;

}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define FOR(v, a, b) for(int v = (a); v < (b); ++v)
#define FORE(v, a, b) for(int v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(int v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define LLI long long int
using namespace std;
template <typename T> using V = vector<T>;
template <typename T, typename U> using P = pair<T,U>;
template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}

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

  int n,k; cin >> n >> k;

  vector<int> h(n);
  REP(i,n) cin >> h[i];

  sort(ALL(h));

  int ans = 1e9;

  REPE(i,n-k){
    ans = min(ans, h[i+k-1] - h[i]);
  }
  
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 640
#include<stdio.h>
#define N 100

void bubble(int *,int);

int main(){

  int i,n,array[N];

  scanf("%d",&n);

  for(i=0;i<n;i++) scanf("%d",&array[i]);


  bubble(array,n);

  return 0;
}

void bubble(int A[],int n){
  int i,j,cnt=0,tmp,flag;

  flag=1;
  while(flag==1){
    flag=0;
    for(i=0;i<n;i++){
      for(j=n-1;j>i;j--){
	if(A[j]<A[j-1]){
	  tmp=A[j];
	  A[j]=A[j-1];
	  A[j-1]=tmp;
	  cnt++;
	  flag=1;
	}
      }
    }
  }

  for(i=0;i<n;i++){
    printf("%d",A[i]);
    if(i!=n-1)printf(" ");
  }
  printf("\n%d\n",cnt);
}



Measured memory_bytes: 2104
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int n,m;
    cin>>n>>m;
    int A[n][m];
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            cin>>A[i][j];
        }
    }
    int B[m];
    for(int i=0;i<m;i++){
        cin>>B[i];
    }
    for(int i=0;i<n;i++){
       int a=0;
        for(int j=0;j<m;j++){
            a=a+A[i][j]*B[j];
            if(j==m-1){
                cout<<a<<endl;
            }
        }
    }
}



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

// YYMM
// YY -> 00 - 99
// MM -> 01 - 12

int main(void)
{
    int S;
    cin >> S;

    int left = S / 100;
    int right = S % 100;

    // YYMM & MMYY possible
    if (right >= 1 && right <= 12 && left >= 1 && left <= 12)
    {
        cout << "AMBIGUOUS" << endl;
    }
    // YYMM
    else if (right >= 1 && right <= 12)
    {
        cout << "YYMM" << endl;
    }
    // MMYY
    else if (left >= 1 && left <= 12)
    {
        cout << "MMYY" << endl;
    }
    else
    {
        cout << "NA" << endl;
    }
    return (0);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main (){
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	int ans=0;
	int w=1;
	int i=1;
	w=a*b;
	i=c*d;
	ans=max(w,i);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] h = new int[N];
		for (int i = 0; i < N; i++) {
			h[i] = sc.nextInt();
		}
		int count = 1, max = h[0];
		for (int i = 1; i < N; i++) {
			if (h[i] >= max) {
				max = h[i];
				count++;
			}
		}
		System.out.println(count);
	}
}


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

using namespace std;

int main() {
	
	int n;

	scanf("%d", &n);

	multiset <int> mult;

	for(int i =0 ; i < n; i++){
		int val;
		scanf("%d", &val);
		mult.insert(val);
	}

	int m;

	scanf("%d", &m);

	bool falha = false;

	for(int i = 0; i < m; i++){
		int val;
		scanf("%d", &val);
		if(mult.find(val) == mult.end()){
			falha = true;
			break;
		}
		else{
			mult.erase(mult.find(val));
		}
	}

	if(falha) printf("NO\n");
	else printf("YES\n");

	return 0;
}

Measured memory_bytes: 9600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template <class T> ll size(const T &x) { return x.size(); }
#define rep(i,a,b) for(ll i = (a); i < (b); ++i)
#define iter(it,c) for(__typeof((c).begin()) it = (c).begin(); it != (c).end();++it)
#define MOD 1000000007
#define pb push_back
#define fs first
#define sc second
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;

const int INF = 2147493647;
const double pi = acos(-1);
const double EPS = 1e-9;

int main()
{
    string s;
    int n;
    cin >> n >> s;
    if(n < 3200) cout << "red" << endl;
    else cout << s << endl;
    return 0;
}


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

int main(void) {
	int a, b, c;
	char buf[128], *ch;

	fgets(buf, sizeof(buf), stdin);
	ch = strtok(buf, " ");
	a = atoi(ch);
	ch = strtok(NULL, " ");
	b = atoi(ch);
	ch = strtok(NULL, " ");
	c = atoi(ch);

	if((a - b) == (b - c)) {
		printf("YES\n");
	} else {
		printf("NO\n");
	}

	return 0;
}


Measured memory_bytes: 2008
#include<bits/stdc++.h>
using namespace std;
#define M 1000000007
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define gcd __gcd
#define in(a) scanf("%d",&a)
#define in2(a,b) scanf("%d%d",&a,&b)
#define in3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define read(v,i,n) for(i=0;i<n;i++)in(v[i])
#define sc(ch) scanf("%c",&ch)
#define sstr(str) scanf("%s",str)
#define pr(n) printf("%d ",n)
#define out(n) printf("%d\n",n)
#define inl(a) cin >> a
#define prl(a) cout << a << " "
#define outl(a) cout << a << endl
#define yes printf("YES\n")
#define no printf("NO\n")
#define lin printf("\n")
#define dbg(v,i,n) for(i=0;i<n;i++)pr(v[i]); lin
#define ck printf("continue\n")
#define all(vec) vec.begin(),vec.end()
#define asc(vec) sort(vec.begin(),vec.end())
#define lower(v,k) lower_bound(v.begin(),v.end(),k)-v.begin()
#define upper(v,k) upper_bound(v.begin(),v.end(),k)-v.begin()
#define ii pair<int,int>
#define vi vector<int>
#define vii vector<pair<int,int> >
#define vvi vector<vector<int> >
#define viii vector<pair<pair<int,int>,int> >
#define vvii vector<vector<pair<int,int> > >
#define lp(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) for(i=0;i<n;i++)
#define N 1000005
typedef long long int ll;
int main()
{
    int i,j,k,a,b,n,m,f,p;
    string str;
    in3(a,b,p);
    rep(i,10)
    {
        p=(a*p-b);
        out(p);
    }
}


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

int main()
{
  int cnt;
  char S1,S2,S3,T1,T2,T3;
  char S[4];
  char T[4];
  int result = 0;

  cnt = scanf("%s", &S);
  cnt = scanf("%s", &T);

  if (S[0] == T[0]) result++;
  if (S[1] == T[1]) result++;
  if (S[2] == T[2]) result++;
  
  printf("%d", result);

  return 0;
}



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

int main() {
  int N, M;
  cin >> N >> M;
  
  int a, b;
  vector<int> vec(M*2);
  for(int i=0; i<M; i++){
    cin >> a >> b;
    vec.at(i*2)=a;
    vec.at(i*2+1)=b;    
  }
  
  //出力
  for(int i=1; i<N+1; i++){
    int x=0;
    for(int j=0; j<M*2; j++){
      if(vec.at(j)==i){
        x++;
      }
    }
    cout << x << endl;
  }
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define mod 1000000007
#define all(c) begin(c),end(c)
template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
using ll = long long;
using vi = vector<int>;
int dd[] = { 0, 1, 0, -1, 0 }; //→↓←↑

vi dp;
vector<vi> T;
int N;
int calc(int u)
{
	if (dp[u] >= 0)return dp[u];

	int ret = INT_MAX;
	for (int i = 0; i < N; i++)
	{
		if (u >> i & 1)
		{
			int min = T[i][0];
			for (int j = 0; j < N; j++)
			{
				if (j == i) continue;
				if (u >> j & 1)
				{
					chmin(min, T[i][j + 1]);
				}
			}
			chmin(ret, min + calc(u ^ 1 << i));
		}
	}

	return dp[u] = ret;
}

void solve()
{
	while (true)
	{
		cin >> N;
		if (N == 0)break;
		T = vector<vi>(N, vi(N + 1));
		for (int i = 0; i < N; i++)
		{
			for (int j = 0; j < N + 1; j++)
			{
				cin >> T[i][j];
			}
		}
		//dp[i]: iで表す項目を終わらせているときの最小の時間
		dp = vi(1 << N, -1);
		dp[0] = 0;

		cout << calc((1 << N) - 1) << endl;
	}
}

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


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

using ll = long long int;
using P = std::pair<int, int>;

#define rep(i, n) for (int i = 1; i <= (n); ++i)
#define rag(con) std::begin(con), std::end(con)

int main()
{
    int n;

    std::cin >> n;

    std::map<int, int> mp;

    rep(i, n)
    {
        int a;
        std::cin >> a;
        mp[a]++;
    }

    std::vector<int> vec, sum;

    for (auto p : mp)
    {
        vec.push_back(p.second);
    }

    std::sort(rag(vec));

    sum.resize(vec.size());

    sum[0] = vec[0];

    rep(i, vec.size() - 1)
        sum[i] = sum[i - 1] + vec[i];

    rep(i, n)
    {
        int nn = n;
        while (1)
        {
            int mx = nn / i;
            int len = std::end(vec) - std::upper_bound(rag(vec), mx);
            int nnn = len * mx + sum[sum.size() - 1 - len];
            if (nnn == nn)
            {
                std::cout << nn / i << std::endl;
                break;
            }
            nn = nnn;
        }
    }

    return 0;
}

Measured memory_bytes: 19068
// #define _CRT_SECURE_NO_WARNINGS
// #define _USE_MATH_DEFINES	// M_PI=3.1415...
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <locale>
#include <cctype>
#include <sstream>
#include <iomanip>	// 20桁出力 cout << setprecision(20) << double;
#include <queue>
#include <bitset>	// bitset<8> bs1(131uL); // 10000011 bs1[0]は1 01stringからビット集合生成可
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<LL> VL;
typedef map<int, int> MAPII;
typedef multimap<int, char, greater<int> > MuMAPIC;
typedef vector<pair<int, int> > VPII;
typedef multimap<int, string, greater<int> > MuMIS;
typedef pair<int, int> P;
typedef pair<int, pair<P, P> > PP;

#define MP make_pair
#define FAST_IO  cin.tie(0); ios::sync_with_stdio(false);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FOR_REV(i,a,b) for(int i=(a);i>=(b);i--)
//for gcc (未test)
// #define FOREACH_IT(it,c) for(typeof(c)::iterator it=(c).begin(); it!=(c).end(); ++it)
//for Visual Studio
#define foreach_it(type,it,c) for(type::iterator it=c.begin(),c_end=c.end();it!=c_end;++it)
#define FOR_ITR(d) for(auto itr=d.begin(),d_end=d.end();itr!=d_end;++itr)	// C++11
// for Debug.
#define DUMP_VVI(b) FOR(i,0,b.size()){FOR(j,0,b[i].size())printf("%d ",b[i][j]);puts("");}
#define D_OUT(str,value) if(dbgF){cout<<str<<" : "<<value<<endl;}
// 入力をpush_back(d)やarray[d]に使う時に1行で書ける
// int INPUT_INT() {int d;cin>>d;return d;}
template<class T>T IN() { T d; cin >> d; return d; }
// 最大公約数（Greatest Common Divisor）
LL gcd(LL a, LL b) { return (b > 0) ? gcd(b, a%b) : a; }
// 最小公倍数（Least Common Multiple）
LL lcm(LL a, LL b) { return a / gcd(a, b) * b; }
// Y年はうるう年か否か
bool uruu(LL Y) { return (((Y % 4 == 0 && Y % 100 != 0) || Y % 400 == 0) ? true : false); }

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

// vector注意
// vec[i][j]の形に入力を入れるとき、vecは初期化してある必要がある.

// ------------------- include, typedef, define END. -------------------

int main() {
	FAST_IO;
	// for D_OUT(str, value)  ... cout<< str <<" : "<< value <<endl;
	bool dbgF = true;

	//コードはここから書く.

	int a, b, c;
	VI d;
	cin >> a >> b >> c;
	d.push_back(a);
	d.push_back(b);
	d.push_back(c);
	sort(d.begin(), d.end());
	cout << d[0] + d[1] << endl;


	return 0;
}

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

#define coutv(v) for (int i = 0; i < (v).size(); ++i) cout << v[i] << ' '; cout << endl;
#define coutvv(v) for (int i = 0; i < (v).size(); ++i) {for (int j = 0; j < (v[i]).size(); ++j) cout << v[i][j] << ' '; cout << endl;}
#define debugv(v) {for (int i = 0; i < (v).size(); ++i) cerr << v[i] << ' '; cerr << endl;}
#define debugvv(v) {for (int i = 0; i < (v).size(); ++i) {for (int j = 0; j < (v[i]).size(); ++j) cerr << v[i][j] << ' '; cerr << endl;}}
#define stringtovector(s, v) {for (int i = 0; i < (s).size(); ++i) v.push_back(s[i]);};
#define TC int TESTCASE; cin >> TESTCASE; while (TESTCASE--)
typedef long long ll;
const int mod = 1000000007;




int main() {
    string s;
    cin >> s;
    ll d = 0;
    for (int i = 0; i < s.size(); i++) {
        d += (int)s[i] - (int)'0';
    }
    if (d % 9 == 0) {
        cout << "Yes";
    } else {
        cout << "No";
    }
}





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

using namespace std;

void solve()
{
	int A, B;
	cin >> A >> B;
	cout << 6 - (A + B) << endl;
}

int main()
{
	solve();

	return 0;
}


Measured memory_bytes: 256
inp = input()
changed_input = inp.replace('BC', 'D')
A_count = 0
total_ans = 0
for st in changed_input:
    if st == 'A':
        A_count += 1
    elif st == 'D':
        total_ans += A_count
    else:
        A_count = 0
print(total_ans)

Measured memory_bytes: 3500
S = input()
K = int(input())
N = len(S)  # 桁数

# dp[i][j][k] : i桁目まで見て、非ゼロがj回出て、
# k=0ならそれまでの桁はNと一致、k=1なら既にN以下が決定してる
dp = [[[0] * 2 for _ in range(4)] for _ in range(105)]
dp[0][0][0] = 1

# i, j, kは遷移前のdpの状態
# ni, nj, nkは遷移先のdpの状態
for i in range(N):
    nd = int(S[i])
    for j in range(4):
        for k in range(2):
            for d in range(10):
                ni = i + 1
                nj = j
                nk = k
                if d != 0:  # 非ゼロを使うのでjを1つ増やす
                    nj += 1
                if nj > K:
                    continue
                if k == 0:
                    if d > nd:
                        continue
                    if d < nd:
                        nk += 1
                dp[ni][nj][nk] += dp[i][j][k]

ans = dp[N][K][0] + dp[N][K][1]
print(ans)


Measured memory_bytes: 3188
//HonestOrUnkind 2

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

int main(){
  ll n;cin >> n;
  vector<pair<ll,ll>> ab(n);
  rep(i,n) cin >> ab.at(i).first >> ab.at(i).second;
  sort(ab.begin(),ab.end());
  reverse(ab.begin(),ab.end());
  ll ans = 0;
  ans += ab.front().first + ab.front().second;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4724
//#include<bits/stdc++.h>
#include<iostream>
#include<vector>
#include<utility>
#include<cmath>
#include<map>
#include<functional>
#include<queue>
#include<set>
#include<stack>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0;i<(n);i++)
template<typename T =ll> using v = vector<T>;
template<typename T =ll> using vv = v<v<T>>;
template<typename T =ll,typename U =ll> using p = pair<T,U>;
template<typename T> T chmin(T &a,T b) {return a=min(a,b);}
template<typename T> T chmax(T &a,T b) {return a=max(a,b);}
const ll INF = (ll)1e9;

void a(){
    string n; cin >> n;
    if(n.find_first_of("7")!=string::npos){
        cout << "Yes"<<endl;
    }else{
        cout << "No"<<endl;
    }
}

void b(){
    ll n; cin >> n;
    ll sum =0;
    for(ll i=1;i<=n;i++){
        if(i%3==0&&i%5==0) continue;
        else if(i%3==0) continue;
        else if(i%5==0) continue;
        else sum+=i; 
    }
    cout << sum << endl;
}

ll gcd(ll a,ll b){
    return (b==0)?a:gcd(b,a%b);
}

ll ggcd(ll a,ll b,ll c){
    return gcd(gcd(a,b),c);
}
void c(){
    int k;
    cin >> k;
    ll ans =0;
    for(int a=1;a<=k;a++)
        for(int b=1;b<=k;b++)
            for(int c=1;c<=k;c++){
                ans +=ggcd(a,b,c);
            }

    cout << ans << endl;
}

void d(){

}

void e(){

}

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

Measured memory_bytes: 3196
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <cmath>
#include <limits>
#include <bitset> 
#include <iterator> 
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include<deque>
#include <regex>
#include <list> 
#define rep(i,n) for(ll i=0;i<(n); ++i)
#define per(i,n) for(ll i=n-1;i>=0; --i)
#define all(x) (x).begin(),(x).end()
#define _GLIBCXX_DEBUG
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
typedef long long ll;
const ll MOD = 1000000007;
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll getDigit(ll n) {
	ll cnt = 0;
	while (n != 0) {
		n /= 10;
		cnt++;
	}
	return cnt;
}
typedef pair<double,long long> pair_t;
bool comp(const pair_t& a, const pair_t& b) {
	if (a.first == b.first)return  a.second > b.second;
	else {
		return a.first > b.first;
	}
}

int main() {
	ll n,cnt=0,Mcnt=-INF;
	cin >> n;
	vector<ll>a(n);
	rep(i, n)cin >> a[i];
	vector<ll>bucket(100010);
	for (ll i = 0; i < n; i++) {
		if(a[i]+1 < 100000)bucket[a[i] + 1]++;
		bucket[a[i]]++;
		if(0 < a[i]-1)bucket[a[i] - 1]++;
	}
	cout << *max_element(all(bucket)) << endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <cmath>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define for(i, a, b) for(int (i)=a;(i)<(b);++(i))
#define rep(i, n)    for(i, 0, n)
#define sz(x)        ((int)(x).size())
#define inf          1<<25

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

//typedef vector<int> vi;
//typedef vector<long long> vl;
//typedef vector<double> vd;
//typedef pair<int,int> pii;
//typedef pair<long,long> pll;
//typedef long long ll;

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

int main() {
    string a, b;
    cin >> a >> b;
    
    int x = stoi(a + b);
    rep(i, sqrt(x)) if ((i+1) * (i+1) == x) {
        cout << "Yes" << endl;
        return 0;
    }
    
    cout << "No" << endl;
    return 0;
}

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

int main()
{
    std::string str;
    std::cin >> str;
    bool N = false, W = false, S = false, E = false;
    for (int i = 0; i < str.length(); i++)
    {
        if (str[i] == 'N') { N = true; }
        else if (str[i] == 'W')
        {
            W = true;
        }
        else if (str[i] == 'S')
        {
            S = true;
        }
        else
        {
            E = true;
        }
    }

    if (S & !N || !S & N || W & !E || !W & E) { std::cout << "No" << std::endl; }
    else
    {
        std::cout << "Yes" << std::endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;



int main(){
	string s;
	cin >> s;
	int p = 0;
	int sc = 0;
	int n = s.size();
	rep(i, n) {
		if(s[i] == 'g') {
			if(p > 0) sc++, p--;
			else p++;
		}
		else {
			if(p > 0) p--;
			else p++, sc--;
		}
	}
	cout << sc << endl;
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int inf = 1e9;
const int mod = 1e9 +7;

int main(){
	int lim = 100001;
	vector<int> mul(lim, 1);
	for(int i=2; i<lim; i++){
		for(int j=i*2; j<lim; j+=i){
			if(mul[j] < 2*j){
				mul[j] *= i;
			}
		}
	}
	vector<int> ans(lim, 0);
	for(int i=2; i<lim; i++){
		if(mul[i] >= 2*i){
			ans[i]++;
		}
		ans[i+1] += ans[i];
	}

	int n;
	cin >> n;
	for(int i=0; i<n; i++){
		int a;
		cin >> a;
		cout << ans[a] << endl;
	}
	return 0;
}


Measured memory_bytes: 3436
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        a: [i32;n]
    }

    let mut res = i32::max_value();
    for i in -100..100+1 {
        let sum:i32 = a.iter().map(|x|{ (x - i).pow(2) }).sum();
        res = std::cmp::min(res,sum);
    }
    println!("{}", res);
}


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

typedef long long ll;
typedef long double ld;

map <string, int> ima;

int main(){
    ios_base::sync_with_stdio(false), cin.tie(0);
    cout.precision(10);
    cout << fixed;

    int n;
    cin >> n;
    for(int i=1; i<=n; i++){
        string s;
        cin >> s;
        ima[s]++;
    }
    int res = 0;
    for(auto c : ima) res++;
    cout << res;
    return 0;
}


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

int main(){
  int a,b,c,x,i,j,k,ans;
  ans=0;
  cin >> a >> b >> c >> x;
  for(i=0;i<=a;i++){
    for(j=0;j<=b;j++){
      for(k=0;k<=c;k++){
        if(x==i*500+j*100+k*50){
          ans++;
        }
      }
    }
  }
  cout << ans << endl;
}


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

using namespace std;

typedef long long ll;

const ll MOD = 1000000007;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    double n, m, d; cin >> n >> m >> d;
    if(d == 0){
        cout << fixed << setprecision(12) << (m - 1) / n << endl;
    }else{
        cout << fixed << setprecision(12) << (2 * (n - d) * (m - 1)) / (n * n) << endl;
    }
}

Measured memory_bytes: 256
//By Don4ick 
//#define _GLIBCXX_DEBUG

#include <bits/stdc++.h>

typedef long long ll;
typedef long double ld;
typedef unsigned int ui;

#define forn(i, n) for (int i = 1; i <= n; i++)
#define pb push_back
#define all(x) x.begin(), x.end()
#define y1 qewr1234

const double PI = acos(-1.0);
const int DIR = 4;
const int X[] = {1, 0, -1, 0};
const int Y[] = {0, 1, 0, -1};

const int N = (int)1e5 + 228;

using namespace std;

int n;
vector < int > g[N];

int dfs(int v, int pr)
{
	int cnt = 0;
	for (auto to : g[v])
	{
		if (to == pr)
			continue;
		cnt += dfs(to, v);
	}
	if (cnt > 1)
	{
		cout << "First" << endl;
		exit(0);
	}           
	if (pr == -1 && cnt == 0)
	{
		cout << "First" << endl;
		exit(0);
	}
	return 1 - cnt;
}

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

	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);

	//~read
	scanf("%d", &n);
	forn(i, n - 1)
	{
		int v, u;
		scanf("%d%d", &v, &u);
		g[v].pb(u);
		g[u].pb(v);
	}
	//~solves
	if (n == 2)
	{	
		cout << "Second" << endl;
		return 0;
	}            
	int root = -1;
	forn(i, n)
	{
		if ((int)g[i].size() > 1)	
		{
			root = i;
			break;
		}
	}
	dfs(root, -1);
	cout << "Second" << endl;

	return 0;
}



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

using namespace std;
typedef long long ll;

#define rep(i, N) for (int i = 0; i < (int)N; i++)
const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,29)-1;


int main() {
  int path[4]={};
  rep(i,3) {
    int a, b; cin >> a >> b; a--; b--;
    path[a]++; path[b]++;
  }
  string result = "YES";
  rep(i,4) if (path[i]==3) result = "NO";
  cout << result << endl;
  return 0;
}

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

int main() {
    //n人、d日、x個
    int n, d, x, ans = 0;
    cin >> n >> d >> x;
    vector<int> a(n);
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    
    for (int i = 0; i < n; i++)
    {
        if (d % a[i] == 0)
        {
            ans += d / a[i];
        }
        else
        {
            ans += d / a[i] + 1;
        }
    }
    
    cout << ans + x << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <time.h>
#include <stdio.h>
#define int long long
using namespace std;
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
int mypow(int x, int y) {
	if (y == 0)return 1;
	if (y % 2)return mypow(x, y - 1)*x;
	else return mypow(x, y / 2)*mypow(x, y / 2);
}

/*ライブラリゾーン！！！！！！！！！！！！！！！*/

signed main(){
	int a, b;
	cin >> a >> b;
	if (a*b % 2) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	system("PAUSE");
	return 0;
}


Measured memory_bytes: 504
#include<bits/stdc++.h>
using namespace std;
#define		pb              push_back
#define		PB              pop_back
#define		nn              "\n"
#define     O_O             ios_base::sync_with_stdio(false); cin.tie(NULL)
#define		all(p)          p.begin(),p.end()
#define		zz(v)           v.size()
#define		ss              ' '
#define 	S(a)            scanf("%lld",&a)
#define 	SS(a,b)         scanf("%lld %lld",&a,&b)
#define 	SSS(a,b,c)      scanf("%lld %lld %lld",&a,&b,&c)
#define		gcd(a,b)        __gcd(a,b)
#define		lcm(a,b)        (a*b)/gcd(a,b)
#define		pi              acos(-1.0)
typedef		long long       ll;
typedef		vector<ll>      vll;

ll a[100500]={0};
string b[100500];
int main()
{
//O_O ;
    ll n,m,temp=0,temp2=0,temp3,w[100000]={0},ans=0;
    cin>>n>>m;
    for(ll i=1; i<=m; i++)
    {
        cin>>temp3;
        //a[temp3];
        cin>>b[temp3];
       // cout<<a[temp3]<<nn;
        if(a[temp3]==0&&b[temp3]=="WA")
        {
            w[temp3]++;
        }

        else if(a[temp3]==0&&b[temp3]=="AC")
        {
            temp++;
            a[temp3]=1;
            ans=ans+w[temp3];
            // cout<<temp<<nn;
        }

    }

    cout<<temp<<" "<<ans<<nn;


    return 0;
}


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

int main() {
  int n, m; cin >> n >> m;
  vector<pair<int,int>> vec(n);
  for (int i = 0; i < n; i++) {
    int a, b; cin >> a >> b;
    vec.at(i) = make_pair(a, b);
  }
  sort(vec.begin(), vec.end());
  int64_t ans = 0;
  int k = 0;
  for (int i = 0; i < n; i++) {
    int j = 0;
    while (k < m && j < vec.at(i).second) {
      ans += vec.at(i).first;
      k++;
      j++;
    }
    if (k == m) break;
  }
  cout << ans << endl;
  return 0;
}

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


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

if(0<a && a<=b){
cout<<"Positive"<<endl;

}
if(a<=b && b<0){
if((b-(a+1))%2==0){
cout<<"Positive"<<endl;
}
if((b-(a+1))%2!=0){
cout<<"Negative"<<endl;

}
}
if(a<=0 && 0<=b){
cout<<"Zero"<<endl;
}




  return 0;
}

 




Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <functional>
#include <cmath>
#include <string>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
const int MOD = 1000000007;

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

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

    bool zero=false;
    vector<int> a(n);
    rep(i,n){
        a[i] = l + i;
        if(a[i] == 0)zero = true;
    }

    int ans=0;
    if(l>=0){
        rep(i,n-1){
            ans += a[i+1];
        }
    }
    else{
        if(zero){
            rep(i,n){
                ans += a[i];
            }
        }
        else{
            rep(i,n-1){
                ans += a[i];
            }
        }
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256