akhauriyash/Code-Regression huggingface dataset:
void main()
{
    long n = rdElem;
    long[] a = rdRow;

    bool minus;
    bool zero;
    long result;
    long amin = 1L << 60;
    foreach (x; a)
    {
        result += x.abs;
        amin = min(amin, x.abs);
        if (x < 0) minus ^= true;
        if (x == 0) zero = true;
    }
    if (minus && !zero) result -= 2 * amin;

    result.writeln;
}

T rdElem(T = long)()
{
    //import std.stdio : readln;
    //import std.string : chomp;
    //import std.conv : to;

    return readln.chomp.to!T;
}

alias rdStr = rdElem!string;

dchar[] rdDchar()
{
    //import std.conv : to;

    return rdStr.to!(dchar[]);
}

T[] rdRow(T = long)()
{
    //import std.stdio : readln;
    //import std.array : split;
    //import std.conv : to;

    return readln.split.to!(T[]);
}

T[] rdCol(T = long)(long col)
{
    //import std.range : iota;
    //import std.algorithm : map;
    //import std.array : array;

    return iota(col).map!(x => rdElem!T).array;
}

T[][] rdMat(T = long)(long col)
{
    //import std.range : iota;
    //import std.algorithm : map;
    //import std.array : array;

    return iota(col).map!(x => rdRow!T).array;
}

void wrMat(T = long)(T[][] mat)
{
    //import std.stdio : write, writeln;

    foreach (row; mat)
    {
        foreach (j, compo; row)
        {
            compo.write;
            if (j == row.length - 1) writeln;
            else " ".write;
        }
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;

Measured memory_bytes: 4404
class Weigthed_Graph:
    #入力定義
    def __init__(self,vertex=[]):
        self.vertex=list(vertex)
        self.edge_number=0
        self.adjacent={v:{} for v in vertex}
    
    #頂点の追加
    def add_vertex(self,*adder):
        for u in adder:
            if u not in self.adjacent:
                self.adjacent[u]={}
                self.vertex.append(u)

    #辺の追加
    def add_edge(self,From,To,Weight):
        for w in [From,To]:
            if w not in self.adjacent:
                self.add_vertex(w)

        self.adjacent[From][To]=Weight
        
    #辺を除く
    def remove_edge(self,From,To):
        for w in [From,To]:
            if w not in self.adjacent:
                self.add_vertex(w)

        try:
            del self.adjacent[From][To]
        except:
            pass

    #頂点を除く
    def remove_vertex(self,*v):
        for u in v:
            for w in self.vertex:
                try:
                    del self.adjacent[w][u]
                except:
                    pass
            del self.adjacent[u]
    #Walkの追加

    #Cycleの追加
        
    #頂点の交換
            
    #グラフに頂点が存在するか否か
    def vertex_exist(self,v):
        try:
            _=self.adjacent[v]
            return True
        except:
            return False

    #グラフに辺が存在するか否か
    def edge_exist(self,From,To):
        try:
            _=self.adjacent[From][To]
            return True
        except:
            return False

    #出近傍
    def in_neighbohood(self,v):
        try:
            return list(self.adjacent[v].keys())
        except:
            return None

    #出次数
    def in_degree(self,v):
        try:
            return len(self.adjacent[v])
        except:
            pass
        

    #頂点数
    def vertex_count(self):
        return len(self.vertex)

    #辺数
    
    #頂点vを含む連結成分

    #距離

    #最短路

def Dijkstra(G,From,To):
    inf=float("inf")

    Q={v:inf for v in G.vertex}
    Q[From]=0
    
    while Q:
        u=min(Q,key=lambda x:Q[x])        
        if u==To:
            return Q[u]
        
        for v in G.adjacent[u]:
            if v in Q:
                Q[v]=min(Q[v],Q[u]+G.adjacent[u][v])

        del Q[u]
#-------------------------------------------------
X,Y=map(int,input().split())

A=sorted([X,Y,-X,-Y,0])
W=Weigthed_Graph(A)
for k in range(4):
    W.add_edge(A[k],A[k+1],A[k+1]-A[k])
W.add_edge(X,-X,1)
W.add_edge(-X,X,1)
W.add_edge(Y,-Y,1)
W.add_edge(-Y,Y,1)
print(Dijkstra(W,X,Y))


Measured memory_bytes: 62456
arr = Array.new
while line = gets
  arr << line
end
arr.each do |i|
  a = i.split(",")
  a.map!{|j| j.to_i}
  l = a[0..9]
  v = a[10..11]
  sum = 0
  0.upto(l.length - 1) do |j|
    sum += l[j]
  end
  c = sum * (v[0] / (v[0] + v[1]).to_f)
  sum = 0
  j = 0
  until c <= sum
    sum += l[j]
    j += 1
  end
  p j 
end

Measured memory_bytes: 6136
#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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define RVSORT(v) sort(v.rbegin(), v.rend());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

int gcd(int a,int b){return b?gcd(b,a%b):a;}

ll modpow(ll n,ll k){
  if(k == 1){
    return n;
  }else if(k == 0){
    return 1;
  }else if(k%2==0){
    ll memo = modpow(n,k/2)%MOD;
    return memo*memo%MOD;
  }else{
    return n * modpow(n,k-1)%MOD;
  }
}

int main(){

  string a,b;cin>>a>>b;

  cout<<b<<a<<endl;
 

  return 0;
}


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

int main(){
    int N;
    cin >> N;
    int T[N];
    rep(i,N) cin >> T[i];
    int M;
    cin >> M;
    int ans[M] = {0};
    rep(i,M){
        int P,X;
        cin >> P >> X;
        rep(j,N){
            if(j == P-1) ans[i] += X;
            else ans[i] += T[j];
        }
    }
    rep(i,M) cout << ans[i] << endl;
}

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

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

template <typename T>
void printv(const vector<T> &v)
{
    int sz = v.size();
    for (int i = 0; i < sz; i++)
    {
        cout << v[i] << " \n"[i == sz - 1];
    }
}

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

    int n;cin>>n;
    map<ll,ll> ret;
    for(int i=0;i<n;i++)
    {
        ll a;cin>>a;
        if(a!=1)ret[a] += a;
        for(int j=2;j*j<=a;j++)
        {
            if(a%j) continue;
            ret[j] += a;
            if(j*j!=a) ret[a/j] += a;
        }
    }
    ll ma = 0;
    for(auto p:ret) ma = max(ma, p.second);
    cout << ma << endl;
}



Measured memory_bytes: 4444
/**
 *      purpose : 
 *      author  : kyomukyomupurin
 *      created : 
**/

// input/output
#include <iostream>
#include <fstream>
#include <sstream>
// container class
#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// math, algorithm
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
// etc
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstring>
#include <chrono>
#include <iomanip>
#include <random>
#include <utility>
// using-directive
using namespace std;
// alias template
using int64 = int64_t;
using vi = vector<int>;
using vl = vector<int64_t>;
using pii = pair<int, int>;
using pll = pair<int64_t, int64_t>;
// text macro replacement
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define print(x) cout << (x) << '\n'
#define debug(x) cerr << #x << ": " << (x) << '\n'
// variadic template
template<typename T> inline void chmin(T &a, T b) {if (a > b) a = b; return;}
template<typename T> inline void chmax(T &a, T b) {if (a < b) a = b; return;}
// constant
const int INF = (1<<30) - 1;
const int64_t INF64 = (1LL<<62) - 1;
const int MOD = 1000000007;

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

  int a, b, c; cin >> a >> b >> c;
  if (a - b >= c) {
    print(0);
  } else {
    cout << c - (a - b) << '\n';
  }

  return 0;
}

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

bc = []
for i in range(m):
    temp = list(map(int, input().split()))
    bc.append(temp)

bc_sorted = sorted(bc, key = lambda x:x[1], reverse = True)
temp = 0

for i in range(m):
    for j in range(temp,min(n,temp+bc_sorted[i][0])):
        if a_sort[j] < bc_sorted[i][1]:
            a_sort[j] = bc_sorted[i][1]
            temp += 1
        else:
            break

print(int(sum(a_sort)))

Measured memory_bytes: 34508
count = gets.chomp.to_i
dishes = gets.chomp.split
points = gets.chomp.split
bonuses = gets.chomp.split
result = 0
count.times do |i|
	result+=points[i].to_i
	if dishes[i].to_i - dishes[i - 1].to_i == 1 && i != 0
		result += bonuses[dishes[i-1].to_i-1].to_i
	end
end
puts result

Measured memory_bytes: 1788
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	
	private static boolean checkFourCard(int[] group){
		boolean flag = false;
		for(int i=1; i<group.length; ++i){
			if(group[i] == 4){
				flag = true;
			}
		}
		return flag;
	}
	
	private static boolean checkFullHouse(int[] group){
		boolean two=false, three=false;
		
		for(int i=1; i<group.length; ++i){
			if(group[i] == 2){
				two = true;
			}else if(group[i] == 3){
				three = true;
			}
		}
		if(two && three){
			return true;
		}else{
			return false;
		}
	}
	
	private static boolean checkStraight(int[] group){
		boolean flag = false;
		int count = 0;
		
		for(int i=1; i<group.length; ++i){
			if(group[i] == 1){
				//またいだ回数
				int over = 0;
				for(int j=i; j<i+5; ++j){
					over += j/group.length;
					if(over > 1){	//2まで行ったら、
						return false;
					}
					
					int num = j%13;
					if(num == 0){ num = 13; }
					if(group[num] == 1){
						++count;
					}else{
						count = 0;
						break;
					}
				}
				if(count == 5){
					flag = true;
					break;
				}
			}
		}
		
		return flag;
	}
	private static boolean checkThreeCard(int[] group){
		boolean flag = false;
		
		for(int i=1; i<group.length; ++i){
			//main で else if やっているから大丈夫だけど、full house 誤認防止
			if(group[i] == 2){
				return false;
			}else if(group[i] == 3){		//four cardもfalseで帰る。
				flag = true;
			}
		}
		
		return flag;
	}
	
	private static boolean checkTwoPair(int[] group){
		boolean flag = false;
		
		for(int i=1; i<group.length; ++i){
			if(flag){		//one pair あった上で見つかったら、
				if(group[i] == 2){
					return true;
				}
			}
			if(group[i] == 2){
				flag = true;
			}
		}
		
		return false;
	}
	
	private static boolean checkOnePair(int[] group){
		boolean flag = false;
		
		for(int i=1; i<group.length; ++i){
			if(flag){		//one pair あった上で見つかったら、
				if(group[i] == 2 || group[i] == 3){
					flag = false;
				}
			}
			if(group[i] == 2){
				flag = true;
			}
		}
		
		return flag;
	}
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner scan = new Scanner(System.in);
		int hand[] = new int [5];
		
		while(scan.hasNext()){
			String[] str = scan.next().split(",");
			for(int i=0; i<str.length; ++i){
				hand[i] = Integer.parseInt(str[i]);
			}
			
			int group[] = new int [14];	//添字がカードナンバと対応。０は欠番
			Arrays.fill(group, 0);
			for(int i=0; i<hand.length; ++i){
				++group[hand[i]];
			}
			
			if(checkFourCard(group)){
				System.out.println("four card");
			}else if(checkFullHouse(group)){
				System.out.println("full house");
			}else if(checkStraight(group)){
				System.out.println("straight");
			}else if(checkThreeCard(group)){
				System.out.println("three card");
			}else if(checkTwoPair(group)){
				System.out.println("two pair");
			}else if(checkOnePair(group)){
				System.out.println("one pair");
			}else{
				System.out.println("null");
			}
		}
	}
}

Measured memory_bytes: 12000
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

N = int(input())
W = list(map(int, input().split()))

d = sum(W)
ans = 10 ** 10

for i in range(N):
    d -= 2 * W[i]
    if ans > abs(d):
        ans = abs(d)

print(ans)


Measured memory_bytes: 38496
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<list>
#include<string>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<ctime>
using namespace std;

typedef long long ll;

bool debug = false;
const double INF = 1000001;
const double eps = 1e-10;
clock_t START, END;

//basic defitition
struct Point {
	int i;
	double x, y;
	Point(double x = 0, double y = 0, int i = 0) :x(x), y(y), i(i) {}
	bool operator < (const Point& rhs) const {
		return x < rhs.x;
	}
};
int dcmp(double x) {
	if (fabs(x) < eps) return 0; else return x < 0 ? -1 : 1;
}
double Distance(Point P, Point Q) {
	double _ans = sqrt(fabs(P.x - Q.x) * fabs(P.x - Q.x) + fabs(P.y - Q.y) * fabs(P.y - Q.y));
	return _ans;
}

double shortestdistance = 0;
vector<Point> S_X, S_Y;

double divide(int L, int R) {
	if (R - L <= 2) {
		for (int i = L; i < R; i++) {
			for (int j = i + 1; j <= R; j++) {
				if (S_Y[i].y > S_Y[j].y) {
					swap(S_Y[i].x, S_Y[j].x);
					swap(S_Y[i].y, S_Y[j].y);
				}
			}
		}
		switch (R - L) {
		case 2: return min(Distance(S_X[L + 1], S_X[R]), min(Distance(S_X[L], S_X[R]), Distance(S_X[L], S_X[L + 1]))); break;
		case 1: return Distance(S_X[L], S_X[R]); break;
		default: return INF;
		}
	}
	else {
		int M = L + (R - L) / 2;
		double _min = min(divide(L, M), divide(M + 1, R));
		double l = (R - L) % 2 ? (S_X[M].x + S_X[M + 1].x) / 2 : S_X[M].x;
		vector<Point> Y, T;
		int i, j;
		for (i = L, j = M + 1; i <= M && j <= R;) {
			if (S_Y[i].y <= S_Y[j].y) {
				if (dcmp(S_Y[i].x - l + _min) >= 0 && dcmp(l + _min - S_Y[i].x) >= 0)
					Y.push_back(S_Y[i]);
				T.push_back(S_Y[i]);
				i++;
			}
			else {
				if (dcmp(S_Y[j].x - l + _min) >= 0 && dcmp(l + _min - S_Y[j].x) >= 0)
					Y.push_back(S_Y[j]);
				T.push_back(S_Y[j]);
				j++;
			}
		}
		while (i <= M) {
			if (dcmp(S_Y[i].x - l + _min) >= 0 && dcmp(l + _min - S_Y[i].x) >= 0)
				Y.push_back(S_Y[i]);
			T.push_back(S_Y[i++]);
		}
		while (j <= R) {
			if (dcmp(S_Y[j].x - l + _min) >= 0 && dcmp(l + _min - S_Y[j].x) >= 0)
				Y.push_back(S_Y[j]);
			T.push_back(S_Y[j++]);
		}
		for (i = L, j = 0; i <= R; i++, j++)
			S_Y[i] = T[j];
		int N = Y.size();
		for (i = 0; i < N; i++) {
			for (j = i + 1; j <= i + 6 && j < N; j++) {
				_min = min(_min, Distance(Y[i], Y[j]));
			}
		}
		Y.clear();
		//printf("%.10lf\n", _min);
		return _min;
	}
}

int main(void)
{
	if (debug) {
		START = clock();
		freopen("in19.txt", "r", stdin);
		freopen("out.txt", "w", stdout);
	}
	int n;
	double x, y;
	cin >> n;
	for (int i = 0; i < n; i++) {
		scanf("%lf%lf", &x, &y);
		S_X.push_back(Point(x, y, i));
		S_Y.push_back(Point(x, y, i));
	}
	sort(S_X.begin(), S_X.end());
	sort(S_Y.begin(), S_Y.end());
	double ans = divide(0, n - 1);
	printf("%.6lf\n", ans);
	if (debug) {
		END = clock();
		double endtime = (double)(END - START) / 1000;
		printf("total time = %lf s", endtime);
	}
	return 0;
}


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

char f(char sw1, char sw2, char tf) {
  if ((sw2 == 'S' && tf == 'o') || (sw2 == 'W' && tf == 'x'))
    return sw1;
  return sw1 == 'S' ? 'W' : 'S';
}

int main() {
  int n;
  string s;
  cin >> n >> s;
  string t[4] = {"SS", "SW", "WS", "WW"};
  for (int i = 0; i < 4; i++) {
    string ans = t[i];
    for (int j = 0; j < n-2; j++) {
      ans += f(ans[j], ans[j+1], s[j+1]);
    }
    if (f(ans[n-2], ans[n-1], s[n-1]) != ans[0]) continue;
    if (f(ans[n-1], ans[0], s[0]) != ans[1]) continue;
    cout << ans << endl;
    return 0;
  }
  cout << -1 << endl;
}

Measured memory_bytes: 776
#include<bits/stdc++.h>
using namespace std;
int a[100005];
int f[100005];
main()
{
    int n,k;
    cin>>n>>k;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    for(int i=2;i<=n;i++)
    {
        f[i]=f[i-1]+abs(a[i-1]-a[i]);
        for(int j=2;j<=k;j++)
            if(i>j)
            f[i]=min(f[i],f[i-j]+abs(a[i]-a[i-j]));
    }
    cout<<f[n];
}


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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<pll> vpll;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

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

  ll n,u,v;
  cin >> n >> u >> v;
  u--;
  v--;

  vector<vll> g(n);
  REP(i, n-1){
    ll a,b;
    cin >> a >> b;
    a--;
    b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }

  bool visited[n];
  REP(i, n)
    visited[i] = false;

  queue<pll> que;
  que.push(pll(v,0));
  visited[v] = true;
  vll dist(n, 0);
  ll cur;
  while(!que.empty()){
    pll now = que.front();
    que.pop();
    for(ll i = 0; i<g[now.FI].size(); i++){
      ll next = g[now.FI][i];
      if(visited[next])
        continue;

      visited[next] = true;
      dist[next] = now.SE+1;
      que.push(pll(next, now.SE+1));
    }
  }


  REP(i, n)
    visited[i] = false;

  que.push(pll(u, 0));
  visited[u] = true;
  pll ans = pll(dist[u],0);
  while(!que.empty()){
    pll now = que.front();
    que.pop();
    for(ll i = 0; i<g[now.FI].size(); i++){
      ll next = g[now.FI][i];
      if(visited[next] || dist[next]<=now.SE+1)
        continue;

      visited[next] = true;
      if(ans.FI < dist[next]){
        ans.FI = dist[next];
        ans.SE = now.SE+1;
      }
      que.push(pll(next, now.SE+1));
    }
  }

  cout << ans.FI-1 << endl;
}


Measured memory_bytes: 7424
#include <stdio.h>

int main()
{
	int N;

	int before_height = 0;
	int len = -1;
	int ans = 0;

	scanf("%d", &N);

	for (int i = 0; i < N; ++i)
	{
		int H;

		scanf("%d", &H);
		if (H <= before_height)
		{
			len++;
			if (len > ans) ans = len;
		}
		else
		{
			len = 0;
		}
		before_height = H;
	}

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

	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,m,n) for(int i=m; i<n; i++)
#define co(n) cout << n << endl
using namespace std;
int main(){
  int a, b, c;
  cin >> a >> b;
  c=max((a+b), (a-b));
  co(max(c, a*b));
  
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

//Leaky Cryptography
public class Main{

	int[][] a;
	int[] cs, t;
	char[] key;
	
	boolean dfs(int k, int c){
		if(k==-1)return true;
		key[k] = '0';
		int x = c;
		for(int i=0;i<8;i++)x+=a[i][k];
		if(x%2==cs[k]){
			if(dfs(k-1, x/2))return true;
		}
		key[k] = '1';
		x = c;
		for(int i=0;i<8;i++)x+=(a[i][k]+1)%2;
		if(x%2==(cs[k]+1)%2){
			if(dfs(k-1, x/2))return true;
		}
		return false;
	}
	
	int[] make(String s){
		int[] r = new int[32];
		long x = Long.parseLong(s, 16);
		int i = 31;
		while(x>0){
			r[i--] = (int) (x%2);
			x>>=1;
		}
		return r;
	}
	
	void run(){
		Scanner sc = new Scanner(System.in);
		int T = sc.nextInt();
		while(T--!=0){
			a = new int[8][32];
			for(int i=0;i<8;i++)a[i] = make(sc.next());
			cs = make(sc.next());
			key = new char[32];
			dfs(31, 0);
			long l = Long.parseLong(new String(key), 2);
			System.out.println(String.format("%h", l));
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 12000
#include <string>
#include <sstream>
#include <iostream>
#include <vector>
#include <math.h>
#include <algorithm>
#include <functional>
#include <map>
#include <unordered_map>  
#include <climits>

using namespace std;


class Main {
public:
	vector<string> qualify(string result,int a,int b) {
		int notOthers = 0;
		int abroad = 0;
		vector<string> ans;
		for (int i = 0;i < result.size();i++) {
			if (result[i] == 'a' && notOthers < a + b) {
				notOthers++;
				ans.push_back("Yes");
			}
			else if (result[i] == 'b' && notOthers < a + b && abroad < b) {
				notOthers++;
				abroad++;
				ans.push_back("Yes");
			}
			else {
				ans.push_back("No");
			}
		}
		return ans;
	}
};

int main()
{
	Main m;
	int n, a, b;
	string s;
	string correct = "CODEFESTIVAL2016";

	cin >> n >> a >> b;
	cin >> s;

	vector<string> ans = m.qualify(s,a,b);
	for (int i = 0;i < n;i++) {
		cout << ans[i] << endl;
	}

    return 0;
}



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

struct Edge {
    int from;
    int to;
    int color;
};

struct Vertex {
    int id;
    bool visited;
    vector<Edge*> next;
};
void dfs(int pos, vector<Vertex>& v, int from = -1);
int main(void) {
    // グラフは木

    int64_t N,a,b;
    cin >> N;
    
    vector<Edge> e(N-1);
    vector<Vertex> v(N);

    for(int i=0;i<(N-1);i++) {
        cin >> a >> b;
        --a;--b;
        
        e[i].from= a;
        e[i].to = b;
        e[i].color = -1;
        v[a].id = a;
        v[b].id = b;
        v[a].visited = false;
        v[b].visited = false;
        v[a].next.push_back(&e[i]);
        v[b].next.push_back(&e[i]);
    }
    
    int maxsum = 0;
    for(auto it:v) {
        if(maxsum < it.next.size()) {
            maxsum = it.next.size();
        }
    }

    dfs(0,v);
    cout << maxsum << "\n";
    for(auto it:e) {
        cout << it.color << "\n";
    }
        
    return 0;
}

void dfs(int pos, vector<Vertex>& v, int from)  {
    if(v[pos].visited) return;

    v[pos].visited = true;
    
    unordered_set<int> colorset;
    for(int i = 0;i <v[pos].next.size();i++) {
        if(v[pos].next[i]->color != -1) {
            colorset.insert(v[pos].next[i]->color);
        }
    }
    if(colorset.size() == v[pos].next.size()) {
        return ;
    }
    
    int k = 1;
    for(int i = 0;i <v[pos].next.size();i++) {
        while(colorset.find(k) != colorset.end()) {
//printf("pos:%d, from:%d, k:%d, to:\n",pos,from,k, v[pos].next[i]->to);
            k++;
        }
        if(v[pos].next[i]->to == from) continue;
        if(v[pos].next[i]->color != -1) continue;
        v[pos].next[i]->color = k;
        colorset.insert(k);
        dfs(v[pos].next[i]->to, v, pos);
    }
}


Measured memory_bytes: 22912
#include<iostream>
#include<vector>
#include<map>
#include<string>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<deque>
using namespace std;
#define rep(i,x,n) for(int i=x;i<n;i++)
using ll=long long;

int n;
string s;

ll gcl(ll x,ll y){
    if(x<y) swap(x,y);
    while(y>0){
        ll t=x%y;
        x=y;
        y=t;
    }
    return x;
}

ll fac(int n){
    if(n==0||n==1) return 1;
    return n*fac(n-1);
}

int main(){
    ll x;cin>>x;
    ll ans=(x+10)/11*2;
    if(ans/2*11-5>=x) ans--;
    cout<<ans<<endl;
}

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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;

constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

template<typename T>
void Unique(vector<T> &v){
  sort(all(v));
  v.erase(unique(all(v)),v.end());
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

void Ans(bool f){
  if(f) cout << "YES"<<endl;
  else cout << "NO"<<endl;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  double ans;
  vary(double,dp,51,0);
  dp[0] = 0;
  dp[1] = inf;
  dp[2] = 380;
  dp[3] = 550;
  dp[4] = 380*2;
  dp[5] = 850;
  dp[6] = 550 * 2;
  REP(i,7,51){
    ans = 380 + dp[i-2];
    ans = min(ans,550 + dp[i-3]);
    ans = min(ans,850 + dp[i-5]);
    if(i >= 10)
      ans = min(ans,dp[i-10] + 380 * 5 * 0.8);
    if(i >= 12)
      ans = min(ans,dp[i-12] + 550 * 4 * 0.85);
    if(i >= 15)
      ans = min(ans,dp[i-15] + 850 * 3 * 0.88);
    dp[i] += ans;
  }
  while(cin>>n&&n){
    cout << dp[n/100] << endl;
  }
  return 0;
}

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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
  for (auto val : array)
    std::cout << val << ", ";
  std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << std::setprecision(10);

  string s; std::cin >> s;
  int ans = 0, len = s.size();
  rep(i, len) ans += s[i]-'0';
  chmax(ans, (s[0]-'0'-1) + (len-1) * 9);
  std::cout << ans << "\n";
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        new Main().run();
    }

    private void run() {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        long ans = 0;
        for(int i = 1; i < N; i++) {
            ans += i;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 23124
# coding: utf-8
# Your code here!

a = []
try :
    while True:
        a.append(int(input()))
except EOFError:
    pass

counts = [0] * 101

for n in a:
    counts[n] += 1
    
for n in range(len(a)):
    if counts[n] == max(counts):
        print(n)


Measured memory_bytes: 5604
#自力で書いた

from collections import deque
n = int(input())
l = [input() for i in range(n)]

diam = -1    
for i in range(n):
    queue = deque([i])
    dist = [-1]*n
    dist[i] = 0
    while queue:
        u = queue.popleft()
        d = dist[u]
        ll = l[u]
        for v in range(n):
            if ll[v]=="1":
                if dist[v]==-1: #未踏.
                    dist[v] = d + 1
                    queue.append(v)
                else:
                    if abs(d-dist[v]) != 1:
                        print(-1)
                        exit()
    diam = max(diam, max(dist))

print(diam + 1)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define RI(a) scanf("%d",&a)
#define RII(a,b) scanf("%d%d",&a,&b)
#define RIII(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define F first
#define S second
#define REP(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#ifdef leowang
#define debug(...) do{\
	fprintf(stderr,"%s - %d : (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
	DO(__VA_ARGS_);\
}while(0)
template<typename I> void _DO(I&&x){cerr<<x<<endl;}
template<typename I,typename...T> void _DO(I&&x,T&&...tail){cerr<<x<<", ";_DO(tail...);}
#else
#define debug(...)
#endif
//}}}
const ll maxn=100005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=2000000000;

vector<vector<int>> c={{2,1,2,2},{3,2,2,3},{5,2,5,10},{7,4,4,14},{11,6,6,33},{13,5,10,130},{17,6,17,102},{19,10,10,95},{23,12,12,138},{29,11,22,638},{31,16,16,248},{37,14,28,1036},{41,18,24,2952},{43,22,22,473},{47,24,24,564},{53,24,30,2120},{59,30,30,885},{61,23,46,2806},{67,34,34,1139},{71,36,36,1278},{73,21,146,3066},{79,40,40,1580},{83,42,42,1743},{89,30,89,2670},{97,28,194,2716},{101,34,101,3434},{103,52,52,2678},{107,54,54,2889},{109,30,545,654},{113,30,678,1695},{131,38,262,2489},{137,36,1233,1644},{139,36,1668,2502},{151,42,453,2114},{163,42,2282,3423},{173,48,519,2768},{181,48,1086,2896},{191,52,764,2483},{223,60,1115,2676},{229,60,2290,2748},{263,70,1841,2630},{271,72,2168,2439}};

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

	for(int i=0;i<c.size();i++){
		if(n%c[i][0]==0){
			cout<<c[i][1]*n/c[i][0]<<' '<<c[i][2]*n/c[i][0]<<' '<<c[i][3]*n/c[i][0]<<'\n';
			return 0;
		}
	}

	return 0;
}


Measured memory_bytes: 256
//package com.atcoder.contest174.d;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
        FastScanner fs = new FastScanner();
        int n = fs.nextInt();
        char[] a = fs.next().toCharArray();
        int ans = 0;
        List<Integer> ws = new ArrayList<>(), rs = new ArrayList<>();
        for(int i=0; i<n; ++i)
            if(a[i] == 'W') ws.add(i);
            else rs.add(i);
        int wIdx = 0, rIdx = rs.size()-1;
        while(wIdx < ws.size() && rIdx >= 0) {
            if(ws.get(wIdx) < rs.get(rIdx)) {
                ans++;
            }
            wIdx++;
            rIdx--;
        }
        System.out.println(ans);
    }

    static class FastScanner {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer("");

        String next() {
            while (!st.hasMoreTokens())
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        int[] readArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++) a[i] = nextInt();
            return a;
        }

        long nextLong() {
            return Long.parseLong(next());
        }
    }
}


Measured memory_bytes: 42772
//#include<bits/stdc++.h>
#pragma GCC optimize(2)
#pragma G++ optimize(2)
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<cstring>
#include<utility>
#include<iostream>
#include<algorithm>
#include<functional>
#include<unordered_map>
using namespace std;

#define ios ios::sync_with_stdio(false)
#define ll long long
#define pa pair<int,int>
#define mk make_pair
#define sc(n) scanf("%d",&n)
#define ss(s) scanf("%s",s)
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define of(i,a,b) for(int i=a;i>=b;i--)
#define mem(a,b) memset(a,b,sizeof a)
#define uint unsigned int
#define vr vector<int>
#define pi acos(-1)

const ll inf = 0x3f3f3f3f;
const ll mod = 1e9 + 7.;
const ll N = 1e6 + 7;

int n, m, t;

int main()
{
	int a, b;
	cin >> a >> b;
	int ans = max(0, a - 2 * b);
	cout << ans << endl;

	return 0;
}

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

#define uni(x)      (x).resize(unique(all(x)) - (x).begin())
#define fprint(v)   for(auto x : v) cout << x << ' '
#define ALL(x)      (x).begin(), (x).end()
#define MP(x, y)    make_pair(x, y)
#define PII         pair<int, int>
#define SZ(x)       int((x).size())
#define PB(x)       push_back(x)
#define ll          long long
#define S           second 
#define F           first
#define nl          '\n'

using namespace std;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
mt19937_64 rnd;

const int N = 2e5 + 5;
vector<int> v = {100, 101, 102, 103, 104, 105};
int dp[N];
int solve(int n){
    if(n < 0){
        return 0;
    }
    if(n == 0){
        return 1;
    }
    if(dp[n] != -1){
        return dp[n];
    }
    int ans = -1;
    for(auto x : v){
        ans = max(ans, solve(n - x));
    }
    return dp[n] = ans;
}
int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    int n;
    cin >> n;
    memset(dp, -1, sizeof(dp));
    cout << solve(n);
    return 0;
}
/*
    1. Overflow Check (*, +)
    2. Index check (0 - based or 1 - based)
    3. Check for n = 1, 2, 3, 4....
    4. Corner Cases
*/

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

int main() {
  string str1,str2;
  cin >> str1 >> str2;
  int A,B;
  cin >> A >> B;
  string str3;
  cin >> str3;
  
  if (str3 == str1) {
    cout << A - 1 << " " << B <<endl;
  }
  else {
    cout << A << " " << B - 1 <<endl;
  }
  

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+10;
char a[maxn];
char b[maxn];
vector<int>c[30];
int main()
{
	scanf("%s %s",a,b);
	int n=strlen(a);
	int m=strlen(b);
	long long sum=0;
	for(int i=0;i<n;i++)
	{
		c[a[i]-'a'].push_back(i+1);
	}
	int j;
	int x=b[0]-'a';
	if(c[x].empty())
	{
		printf("-1\n");
		return 0;
	}
	int k=c[x][0];
	sum+=k;
	for(int i=1;i<m;i++)
	{
		x=b[i]-'a';
		if(c[x].empty())
	{
		printf("-1\n");
		return 0;
	}
		j=upper_bound(c[x].begin(),c[x].end(),k)-c[x].begin();
		if(j==c[x].end()-c[x].begin())sum+=c[x][0]+n-k,k=c[x][0];
		else {
			sum+=c[x][j]-k;
			k=c[x][j]; 
		}
	}
	printf("%lld\n",sum);
}

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

int main() {
    int N;
    cin >> N;
    vector<char> S(N);
    rep(i, N) cin >> S.at(i);

    bool hasYellow = false;
    rep(i, N) {
        if (S.at(i) == 'Y') hasYellow = true;
    }
    string ans = hasYellow ? "Four" : "Three";

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3604
import java.util.*;

public class Main {
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String s = sc.next();

        Set<String> results = new HashSet<>();
        for(int i = 0 ; i < 1000 ; i++){
            String v = String.valueOf(i);
            if(i < 10){
                v = "00" + v;
            }else if(i < 100){
                v = "0" + v;
            }

            String s1 = s;
            int index1 = s1.indexOf(v.charAt(0));
            if(index1 < 0){
                continue;
            }
            String s2 = s1.substring(index1 + 1);
            int index2 = s2.indexOf(v.charAt(1));
            if(index2 < 0){
                continue;
            }
            String s3 = s2.substring(index2 + 1);
            int index3 = s3.indexOf(v.charAt(2));
            if(index3 < 0){
                continue;
            }
            results.add(v);
        }
        System.out.println(results.size());
    }

}


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

int main() {
  int n;
  cin >> n;
  
  vector<vector<int>> v(n + 1, vector<int>(26));
  for(int i = 0; i < n; i++){
    string s;
    cin >> s;
    for(int j = 0; j < s.size(); j++){
      v.at(i).at(s.at(j) - 'a')++;
    }
  }
  
  for(int i = 0; i < 26; i++){
    int keep = 50;
    for(int j = 0; j < n; j++){
      keep = min(keep, v.at(j).at(i));
    }
    v.at(n).at(i) = keep;
  }
  
  for(int i = 0; i < 26; i++){
    char c = i + 'a';
    for(int j = 0; j < v.at(n).at(i); j++){
      cout << c;
    }
  }
  cout << endl;
}

Measured memory_bytes: 256
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

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

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let n: usize = iterator.next().unwrap().parse().unwrap();
    let mut a: Vec<isize> = (0..n).map(|_| iterator.next().unwrap().parse().unwrap()).collect();
    a.sort();

    let mut result = String::new();
    let mut x: isize = a.remove(n - 1);
    let mut y: isize = a.remove(0);
    for ai in a {
        if ai < 0 {
            result.push_str(&format!("{} {}\n", x, ai));
            x -= ai;
        } else {
            result.push_str(&format!("{} {}\n", y, ai));
            y -= ai;
        }
    }
    result.push_str(&format!("{} {}\n", x, y));
    x -= y;
    result = format!("{}\n{}", x, result);
    result.trim().to_string()
}


Measured memory_bytes: 6260
#include<algorithm>
#include<iostream>
#include<functional>
#include<cmath>
#include<iomanip>
using namespace std;
int main(){
  int n,m,ans[100];
  cin>>n>>m;
  for(int j=0;j<100;j++){
    ans[j]=0;
  }
  for(int i=0;i<m;i++){
    int x,y;
    cin>>x>>y;
    ans[x]++;
    ans[y]++;
  }
  for(int k=1;k<n+1;k++){
    cout<<ans[k]<<endl;
  }
}

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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define ALL(x) x.begin(),x.end()
#define EPS (1e-8)
#define equals(a,b) (fabs((a)-(b))<EPS)

using namespace std;

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

inline bool LT(double a,double b) { return !equals(a,b) && a < b; }
inline bool LTE(double a,double b) { return equals(a,b) || a < b; }

#define MAX 100
int H,W,mini[MAX][MAX];
string s[MAX];
int d[] = {0,1,0,-1};

int calc_min() {
  deque<int> deq;
  deq.push_back(0);
  rep(i,H) rep(j,W) mini[i][j] = INT_MAX;
  mini[0][0] = 0;
  while( !deq.empty() ) {
    int cur = deq.front(); deq.pop_front();
    int x = cur % W, y = cur / W;
    rep(i,4) {
      int nx = x + d[i], ny = y + d[(i+1)%4];
      if( !( 0 <= nx && nx < W && 0 <= ny && ny < H ) ) continue;
      if( s[ny][nx] == '#' ) continue;
      if( mini[ny][nx] > mini[y][x] + 1 ) {
	mini[ny][nx] = mini[y][x] + 1;
	deq.push_back(nx+ny*W);
      }
    }
  }
  return mini[H-1][W-1];
}

void compute() {
  int cnt = 0;
  rep(i,H) rep(j,W) if( s[i][j] == '.' ) ++cnt;
  int tmp = calc_min();
  if( tmp == INT_MAX ) {
    puts("-1");
    return;
  }
  cout << cnt - calc_min() - 1 << endl;
}

int main() {
  cin >> H >> W;
  rep(i,H) cin >> s[i];
  compute();
  return 0;
}


Measured memory_bytes: 256
/*input
10 998244353
10 9 8 7 5 6 3 4 2 1
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define eb emplace_back
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define EL cout<<'\n'
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}
template<typename T>
ostream& operator<<(ostream& out,vector<T> V){
	REP(i,SZ(V)) out<<V[i]<<((i!=SZ(V)-1)?" ":"");
	return out;
}
#define version 20190814
//}}}
const ll maxn=300005;
const ll maxlg=20;
const ll INF64=1e18;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const ld PI=acos(-1);
const ld eps=1e-9;
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		b>>=1;
	}
	return res;
}

ll n,k;
ll a[maxn];
int main(){
	IOS;
	cin>>n>>k;
	REP(i,n) cin>>a[i];

	ll ans=0;

	REP(i,n) for(int j=i+1;j<n;j++){
		if(a[i]>a[j]) ans+=k;
	}
	ans%=MOD;

	REP(i,n) REP(j,n) if(a[i]>a[j]){
		ans+=(k-1)*k/2;
		ans%=MOD;
	}
	cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 256
import numpy as np
N,M = map(int, input().split())

A = np.zeros(N)
B = np.zeros(N)
for i in range(N):
    a, b = map(int, input().split())
    A[i] = a
    B[i] = b 
index = np.argsort(A)
A = A[index]
B = B[index]

m = 0
n = 0
ans = 0
while m != M:
    hon = B[n]
    yen = A[n]
    if M - m - hon >= 0:
        m += hon
        ans += yen * hon
        n += 1
    else:
        ans += yen * (M - m)
        break
print(int(ans))


Measured memory_bytes: 21528
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vll vector<ll>
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(int argc, char const *argv[]) {
  string s;std::cin >> s;
  s[5] = s[13] = ' ';
  std::cout << s << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>

using namespace std;

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

    if (a >= 13) {
        cout << b << endl;
    } else if (a >= 6) {
        cout << b / 2 << endl;
    } else {
        cout << 0 << endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	int a[4001]={};
	for(int i=0;i<=1000;i++) {
		for(int j=0;j<=1000;j++) {
			a[i+j]++;
		}
	}
	int n;
	while(cin>>n){
	long long int all=0;
	for(int i=0;i<=1000;i++) {
		for(int j=0;j<=1000&&j<=n-i;j++) {
			all+=a[n-i-j];
		}
	}
	cout<<all<<endl;}
	return 0;
}



Measured memory_bytes: 3112
#include <iostream>
using namespace std;
int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);

	int n,k,s;
	cin >> n;
	cin >> k;
	cin >> s;
  	
  for (int i = 0; i < n; i++)
  {
    if (i < k) cout << s << " ";
    else if (s < 1000000000) cout << s + 1 << " ";
    else cout << 1 << " ";
  }
}



Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int INF=1e9;

int main(){
    int n,h;
    cin>>n>>h;
    int amax=-1;
    priority_queue<int> pq;
    for(int i=0;i<n;i++){
        int a,b;
        cin>>a>>b;
        amax=max(amax,a);
        pq.push(b);
    }
    int ans=0;
    while(pq.size()&&pq.top()>amax&&h>0){
        h-=pq.top();
        pq.pop();
        ans++;
    }
    if(h>0)ans+=(h+amax-1)/amax;
    cout<<ans<<endl;
}


Measured memory_bytes: 892
#include <cstdio>
#include <queue>
#include <vector>
#include <utility>
#include <algorithm>
using namespace std;

typedef pair<int, int> P;

const int INF = 1000000000;

int route[100][100];
int n, m;

int min_cost();

int main()
{
	while (scanf("%d", &n) * n != 0){
		scanf("%d", &m);
		fill(&route[0][0], &route[99][99], INF);
		for (int i = 0; i < m; i++){
			int a, b, cost;
			
			scanf("%d,%d,%d", &a, &b, &cost);
			cost = cost / 100 - 1;
			route[a][b] = cost;
			route[b][a] = cost;
		}
		printf("%d\n", min_cost());
	}
	
	return 0;
}

int min_cost()
{
	priority_queue<P, vector<P>, greater<P> > prim_route;
	bool point[100] = {false};
	int sum = 0;
	
	prim_route.push(P(0, 0));
	while (!prim_route.empty()){
		pair<int, int> p = prim_route.top();
		prim_route.pop();
		int from = p.second;
		
		if (point[from]){
			continue;
		}
		point[p.second] = true;
		sum += p.first;
		for (int i = 0; i < n; i++){
			if (route[from][i] != INF){
				prim_route.push(P(route[from][i], i));
			}
		}
	}
	
	return sum;
}

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

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;

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

    int n;
    cin >> n;
    int ans = 0;
    while (n > 1) {
        n = ceil(n / 3.);
        ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3168
#include <stdio.h>

int main()
{
  int i,j,minj,A[100],N,count=0,c;

  scanf("%d",&N);

  if(N < 1 || N > 100) return 0;

  for( i = 0 ; i < N ; i++ )
    {
      scanf("%d",&A[i]);
    }

  for( i = 0 ; i <= N-1 ; i++ )
    {
      minj = i;
      for( j = i ; j <= N-1 ; j++ )
	{
	  if(A[j] < A[minj])
	    {
	      minj = j;
	    }
	}
      if(i != minj)
	{
	  c = A[i];
	  A[i] = A[minj];
	  A[minj] = c;
	  count++;
	}
    }

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



Measured memory_bytes: 2144
(defun split (input stack-string output-list)
  (let ((chara (car input)))
    (case chara
          ((nil) (append output-list (list stack-string)))
          (#\space (split (cdr input)
                                  '()
                                  (append output-list (list stack-string))))
          (otherwise (split (cdr input)
                                    (concatenate 'string stack-string (list chara))
                                    output-list)))))

(defun input-to-list (input)
  (mapcar #'parse-integer (split (concatenate 'list input)
                                 '()
                                 '())))

(defparameter param (input-to-list (read-line)))
(labels ((zenka (xi r de num)
                (let ((next (- (* xi r) de)))
                  (format t "~a~%" next)
                  (if (eq num 10)
                      1
                      (zenka next r de (1+ num))))))
        (zenka (nth 2 param) (nth 0 param) (nth 1 param) 1))

Measured memory_bytes: 12900