akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

class Node
{
public:
    int key;
    Node *next;
    Node *prev;

    Node()
    {
        this->prev = this;
        this->next = this;
    }
    Node(int key, Node *prev, Node *next)
    {
        this->key = key;
        this->prev = prev;
        this->next = next;
    }
};

class DoublyLinkedList
{
public:
    class Node *nil;

    DoublyLinkedList()
    {
        nil = new Node();
    }

    void print_list()
    {
        Node *cur = nil->next;
        while (cur != nil)
        {
            cout << cur->key;
            cur = cur->next;
            if (cur != nil)
                cout << " ";
        }
        cout << endl;
    }

    void insert(int x)
    {
        Node *node = new Node(x, nil, nil->next);
        nil->next->prev = node;
        nil->next = node;
    }

    void delete_node(Node *node)
    {
        if (node == nil)
            return;
        node->next->prev = node->prev;
        node->prev->next = node->next;
        delete (node);
    }

    Node *search(int x)
    {
        Node *cur = nil->next;
        while (cur != nil && cur->key != x)
        {
            cur = cur->next;
        }
        return cur;
    }

    void delete_key(int x)
    {
        delete_node(search(x));
    }

    void delete_first()
    {
        delete_node(nil->next);
    }

    void delete_last()
    {
        delete_node(nil->prev);
    }
};

int main()
{
    DoublyLinkedList *list = new DoublyLinkedList();

    int n;
    scanf("%d", &n);

    for (int i = 0; i < n; i++)
    {
        char order[10];
        int num;
        scanf("%s", order);

        if (order[0] == 'i')
        {
            scanf("%d", &num);
            list->insert(num);
        }
        else if (order[0] == 'd')
        {
            if (strlen(order) > 6)
            {
                if (order[6] == 'F')
                {
                    list->delete_first();
                }
                else if (order[6] == 'L')
                {
                    list->delete_last();
                }
            }
            else
            {
                cin >> num;
                list->delete_key(num);
            }
        }
    }
    list->print_list();
}



Measured memory_bytes: 34400
// 2018/01/15 Tazoe

#include <iostream>
#include <algorithm>
using namespace std;

int main()
{
	while(true){
		int x, y, s;
		cin >> x >> y >> s;

		if(x==0 && y==0 && s==0)
			break;

		int tmax = -1;

		for(int a=1; a<=s-1; a++){
			int ax = a*(100+x)/100;
			int ay = a*(100+y)/100;

			for(int b=1; b<=s-1; b++){
				int bx = b*(100+x)/100;
				int by = b*(100+y)/100;

				if(ax+bx==s){
					tmax = max(tmax, ay+by);
				}
				else if(ax+bx>s){
					break;
				}
			}
		}

		cout << tmax << endl;
	}

	return 0;
}



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

using namespace std;

void printv(vector<int> &v) {
    vector<int>::iterator it = v.begin();
    cout << *it;
    ++it;
    while(it != v.end()) {
        cout << " " << *it;
        ++it;
    }
    cout << endl;
}

int main()
{
    int n;

    while(cin >> n, n) {

        vector<int> a, b;

        for(int i = 0; i < n; ++i) {
            int ai;
            cin >> ai;
            a.push_back(ai);
        }

        for(int i = 0; i < n; ++i) {
            int bi;
            cin >> bi;
            b.push_back(bi);
        }

        sort(a.begin(), a.end(), greater<int>());
        sort(b.begin(), b.end(), greater<int>());

        /*
        printv(a);
        printv(b);
        */

        int idx = 0;
        int wp[40000] = { 0 };
        for(int i = 0; i < n; ++i) {
            while(idx < n && b[i] < a[idx]) {
                ++idx;
            }
            if(idx >= n) break;
            wp[idx] = b[i];
            ++idx;
        }

        /*
        for(int i = 0; i < n; ++i) {
            cout << wp[i] << " ";
        }
        cout << endl;
        */

        int k = 1;
        int she_win = 0;
        do {
            she_win += !!wp[k - 1];
            if(k - she_win > k / 2) break;
            ++k;
        } while(k <= n);

        if(k >= n) {
            cout << "NA" << endl;
        } else {
            cout << k << endl;
        }

    }

    return 0;
}

Measured memory_bytes: 3572
//
//  abc153_Serval_Monster.cpp
//  learningCplusplus
//
//  Created by Tran Duc Chinh on 2020/04/04.
//  Copyright © 2020 Tran Duc Chinh. All rights reserved.
//

#include <iostream>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
ll mod = 1000000007;
#define PI 3.14159265


int main(int argc, const char* argv[]) {

  int h, a;
  std::cin >> h >> a;

  int sum = (h + a - 1) / a;
  std::cout << sum << std::endl;


  return 0;
}


Measured memory_bytes: 256
function Main(input) {
  input = input.replace(/\n/g, ' ');
  input = input.split(" ");
  var A = input[0];
  var B = input[1];
  var C = input[2];
  var D = input[3];
  var ans  = 0;
  var Sado  = Math.abs(C*30+D/2-D*6);
  if(Sado > 180){Sado=360-Sado;}
  var p = A*A+B*B;
  var q = 2*A*B;
  ans = Math.sqrt(p - q*Math.cos(Sado*(Math.PI/180)));
  console.log(ans);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 30092
#include <iostream>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <cstdlib>

using namespace std;
//DP用
template<class T> inline bool chmin(T& a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

//a^n mod を計算する関数
long long modpow(long long a,long long n,long long mod) {
    long long res = 1;
    while(n > 0) {
        if(n % 2 == 1) {
            res = res * a % mod;
        }
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

//a^(-1) mod すなわちaの逆元を返す関数
long long modinv(long long a,long long mod) {
    return modpow(a,mod-2,mod);
}

//最大公約数をを返す関数
long long gcd (long long a,long long b) {
    if(a % b == 0) {
        return b;
    }else {
        return (gcd(b,a%b));
    }
}

const long long INF = 1LL << 60;
const long long P = 1000000007;

//nCkを求める関数
long long conbi (long long n,long long k) {
    long long res = 1;
    long long inv;
    for(long long i = n-k+1; i <= n; i++) {
        res *= i;
        res %= P;
    }
    for(long long i = 1; i <= k; i++) {
        inv = modinv(i,P);
        res *= inv;
        res %= P;
    }
    return res;
}

int main() {
    int a,b;
    cin >> a >> b;
    if(a <= 2*b) {
        cout << 0;
    }else {
        cout << a-2*b;
    }
    return 0;
}



Measured memory_bytes: 888
#pragma region Macros

#include <bits/stdc++.h>
using namespace std;

using ll = long long;
#define int ll
using vi = vector<int>;
using vvi = vector<vi>;

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

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

// debug methods
// usage: debug(x,y);
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0, a1, a2, a3, a4, x, ...) x
#define debug_1(x1) cout << #x1 << ": " << x1 << endl
#define debug_2(x1, x2) cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << endl
#define debug_3(x1, x2, x3) cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " << x3 << endl
#define debug_4(x1, x2, x3, x4) cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " << x3 << ", " #x4 << ": " << x4 << endl
#define debug_5(x1, x2, x3, x4, x5) cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " << x3 << ", " #x4 << ": " << x4 << ", " #x5 << ": " << x5 << endl
#ifdef _DEBUG
#define debug(...)                                                        \
    CHOOSE((__VA_ARGS__, debug_5, debug_4, debug_3, debug_2, debug_1, ~)) \
    (__VA_ARGS__)
#else
#define debug(...)
#endif

#pragma endregion

void Main() {
    char A;
    cin >> A;
    if (isupper(A)) {
        cout << "A";
        return;
    }

    cout << "a";
}

#pragma region main
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    Main();
    cout << flush;
}
#pragma endregion


Measured memory_bytes: 3648
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		String t = sc.next();
		int n = s.length();
		int m = t.length();
		String[] subs = new String[n-m+1];
		Arrays.fill(subs, "|");
		String ans = "";
		if(n>=m){
			boolean bl = false;
			for(int i=0; i<=n-m; i++){
				bl = false;
				for(int j=0; j<=m-1; j++){
					if(s.charAt(i+j)!=t.charAt(j) && s.charAt(i+j)!='?'){
						bl = true;
						break;
					}
				}
				if(bl==false){
					subs[i] = s.substring(0, i) + t + s.substring(i+m);
					subs[i] = subs[i].replaceAll("\\?", "a");
				}
			}
			Arrays.sort(subs);
			ans = subs[0];
          	if(ans.equals("|"))ans = "UNRESTORABLE";
		}
		else ans = "UNRESTORABLE";
		System.out.println(ans);
	}
}

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

int main() {
  int N;
  string s, t;
  cin >> N >> s >> t;
  
  int x = N;
  for (int i = 0; i < N; i++) {
    string S, T;
    S = s.substr(i);
    T = t.substr(0,N-i);
    if (S == T) {
      x = i;
      break;
    }
  }
  
  cout << N + x << endl;
}

Measured memory_bytes: 256
def main():
    N=int(input())
    A=list(map(int,input().split()))
    total=sum(A)
    tmp=0
    for a in A:
        tmp+=a
        if 2*tmp>=total:
            break
    re_A=reversed(A)
    re_tmp=0
    for re_a in re_A:
        re_tmp+=re_a
        if 2*re_tmp>=total:
            break
    if tmp>re_tmp:
        print(2*re_tmp-total)
    else:
        print(2*tmp-total)
        
    
if __name__=='__main__':
    main()


Measured memory_bytes: 26220
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

a, b = [0], [0]
for i in range(N):
    a.append(a[i] + A[i])
for i in range(M):
    b.append(b[i] + B[i])

ans, j = 0, M
for i in range(N + 1):
    if a[i] > K:
        break
    while b[j] > K - a[i]:
         j -= 1
    ans = max(ans, i + j)
print(ans)

Measured memory_bytes: 47372
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 10e8
#define INF 1<<30
#define MOD 1000000007
#define mod 10007
#define REP(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define REPE(i, a, n) for (ll i = a; i <= (ll)(n); i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<int,int>Pin;
typedef pair<ll,ll>Pll;
template<class T> using V=vector<T>;
long long GCD(long long a, long long b) {return b?GCD(b,a%b):a;}
long long LCM(long long a, long long b) {return a/GCD(a,b)*b;}
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
int ddx[8]={-1,0,1,0,1,1,-1,-1};
int ddy[8]={0,-1,0,1,1,-1,1,-1};
ll cmp(pair<ll,ll>a,pair<ll,ll> b){
        if(a.se!=b.se)
        return a.se<b.se;
        else
        return a.fi<b.fi;
}
//----------------------------------------------------------------------
int a[4][3][10];
//----------------------------------------------------------------------
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------  
    //ll begin_time=clock();
    //------------------------------
    int n;cin>>n;
    
    for(int i=0;i<n;i++){
        int b,f,r,v;cin>>b>>f>>r>>v;
        a[b-1][f-1][r-1]+=v;
    }
    for(int i=0;i<3;i++){
        for(int j=0;j<10;j++)cout<<" "<<a[0][i][j];cout<<endl;
    }
    cout<<"####################"<<endl;
    for(int i=0;i<3;i++){
        for(int j=0;j<10;j++)cout<<" "<<a[1][i][j];cout<<endl;
    }
    cout<<"####################"<<endl;
    for(int i=0;i<3;i++){
        for(int j=0;j<10;j++)cout<<" "<<a[2][i][j];cout<<endl;
    }
    cout<<"####################"<<endl;
    for(int i=0;i<3;i++){
        for(int j=0;j<10;j++)cout<<" "<<a[3][i][j];cout<<endl;
    }
    //-------------------------------  
    //ll end_time=clock();cout<<"time="<<end_time-begin_time<<"ms"<<endl;
    //-------------------------------
    return 0;
}
//----------------------------------------------------------------------


































Measured memory_bytes: 3148
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iterator>
#pragma warning(disable:4996)
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define MOD 1000000007
using namespace std;

long c[10][10];

int main(int argc, char* argv[])
{
    long h, w;
    scanf("%ld%ld", &h, &w);

    long i,j,k;
    for(i=0; i<10; i++) {
        for(j=0; j<10; j++) {
            scanf("%ld", &c[i][j]);
        }
    }

    for(k=0; k<10; k++) {
        for(i=0; i<10; i++) {
            for(j=0; j<10; j++) {
                c[i][j] = MIN(c[i][j], c[i][k]+c[k][j]);
            }
        }
    }

    ll sum=0;
    for(i=0; i<h; i++) {
        for(j=0; j<w; j++) {
            long  a;
            scanf("%ld", &a);
            if(a>=0) {
                sum+=c[a][1];
            }
        }
    }
    printf("%lld\n", sum);
 
    return 0;
}


Measured memory_bytes: 128
N = int(input())
A = list(input().split())
odd = []
even = []

for i in range(N):
    if i % 2 == 1:
        odd.append(A[i])
    else:
        even.append(A[i])

if N % 2 == 0:
    odd = odd[::-1]
    odd.extend(even)
    ans = odd
else:
    even = even[::-1]
    even.extend(odd)
    ans = even

print(" ".join(ans))


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

void fnInput(vector<int> &a_rviTarget, vector<int> &a_rviSearch)
{
  int iTargetCnt;
  cin >> iTargetCnt;

  a_rviTarget.resize(iTargetCnt + 1);
  for (int i = 0; i < iTargetCnt; i++)
    cin >> a_rviTarget[i];

  int iSearchCnt;
  cin >> iSearchCnt;

  a_rviSearch.resize(iSearchCnt);
  for (int i = 0; i < iSearchCnt; i++)
    cin >> a_rviSearch[i];
}

void fnLinearSearch(vector<int> &a_rviTarget, const vector<int> &a_cnrviSearch, int &a_riFound)
{
  size_t zMaxSize = a_rviTarget.size() - 1;
  for (size_t zi = 0; zi < a_cnrviSearch.size(); zi++)
  {
    a_rviTarget[zMaxSize] = a_cnrviSearch[zi];
    size_t zj = 0;
    while (a_rviTarget[zj] != a_cnrviSearch[zi])
      zj++;
    if (zj != zMaxSize)
      a_riFound++;
  }
}

void fnResultOut(int a_iFound)
{
  cout << a_iFound << endl;
}

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

  vector<int> viTarget, viSearch;
  int iFound = 0;

  fnInput(viTarget, viSearch);
  fnLinearSearch(viTarget, viSearch, iFound);
  fnResultOut(iFound);

  return 0;
}

Measured memory_bytes: 1236
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);

        for(int i = 0; i < 20_000; i++){
            int a = scanner.nextInt();
            String op = scanner.next();
            int b = scanner.nextInt();

            if(op.equals("?")){
                break;
            }else if(op.equals("+")){
                System.out.println(a+b);
            }else if(op.equals("-")){
                System.out.println(a-b);
            }else if(op.equals("*")){
                System.out.println(a*b);
            }else if(op.equals("/")){
                System.out.println(a/b);
            }
        }
        scanner.close();
    }
}


Measured memory_bytes: 26300
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define pb push_back
#define mod 1000000007
#define infi 1900000000
#define infl 1100000000000000000
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template<typename T> using ve = vector<T>;
template<typename T> using pq2 = priority_queue<T>;
template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>;




int main()
{

    int N;
    cin >> N;
    vi a(N);
    in(N,a);
    int ans = 1e9+10;
    reps(i,-100,101){
        int cost = 0;
        rep(j,N) cost += (a[j]-i)*(a[j]-i);
        ans = min(cost,ans);
    }
    cout << ans << endl;
    
    
    

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define repr(i,from,to) for(int (i)=(from);(i)<(to);(i)++)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
#define vprint(x) for(auto a:(x)) cout << x << endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) { a = b; return true;}
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) { a = b; return true;}
    return false;
}
int main(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m;cin>>n>>m;
    vector<string> a(n),b(m);
    rep(i,n){cin>>a.at(i);}
    rep(i,m){cin>>b.at(i);}
    rep(i,n-m+1){
        rep(j,n-m+1){
            bool flg=true;
            rep(ii,m){
                rep(jj,m){
                    flg &= b[ii][jj]==a[i+ii][j+jj];
                }
            }
            if (flg){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#152d
N = int(input()) #2*10**5

#N 以下の正の整数の組 (A,B)であって、次の条件を満たすものの個数を求めてください。
#A,Bを先頭に 0 のつかない 10 進数表記で表したときに、 A の末尾の桁が B の先頭の桁に等しく、 A の先頭の桁が B の末尾の桁に等しい

#桁数算出
import math
N_digits = int(math.log10(N)//1 + 1) 

#末尾9通り、先頭9通り……先頭に0はつかないので
safe_number = [1,2,3,4,5,6,7,8,9]
ht_comb_list = dict()

def get_OK_comb_number(head_number,tail_number):
    #1桁のパターンを計算。
    if head_number == tail_number and head_number <= N:
        ht_comb = 1
    else:
        ht_comb = 0

    #2桁のパターンを計算。
    if head_number*10 + tail_number <= N:
        ht_comb += 1

        #3桁以降のパターンを計算
        base_number = 2

        while base_number+1 <= N_digits:
            max_number = head_number*10**(base_number)  + 10**(base_number) -10 + tail_number
            #print(base_number+1,"桁")
            if max_number <= N:
                #print(10**(base_number-1))
                ht_comb += 10**(base_number-1)
            else:
                last_digit = N - ((N//10) * 10)
                max_number = N
                max_number -= last_digit
                max_number += tail_number
                if max_number > N:
                    max_number-= 10

                min_number = head_number*10**(base_number) + tail_number
                #print(max_number,min_number)
                #print(1+(max_number-min_number)//10)

                if max_number >= min_number:
                    ht_comb += 1+(max_number-min_number)//10
            
                break

            base_number += 1

    #print("(",head_number,",",tail_number,"):",ht_comb)
    return ht_comb


for head_number in safe_number:
    for tail_number in safe_number:
        ht_comb_list[(head_number,tail_number)] = get_OK_comb_number(head_number,tail_number)       

ans = 0

for head_number in safe_number:
    for tail_number in safe_number:
        #print((head_number,tail_number),ht_comb_list[(head_number,tail_number)],end="")
        ans += ht_comb_list[(head_number,tail_number)] * ht_comb_list[(tail_number,head_number)]
    #print("")

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 2e9
#define EPS 1e-9
#define MAX LLONG_MAX
#define MIN LLONG_MIN
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define endl "\n"
#define FOR(i,a,b) for (long long i = a; i < b; i++)
#define REV(i,a,b) for (long long i = a; i > b; i--)
#define mset(a, v) memset(a, v, sizeof(a))
#define fd(n) fixed<<setprecision(n)
typedef std::pair<int, int> pii;
typedef std::vector<long long> vi;
typedef std::vector<vi> vvi;
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

ll solve(ll x,ull y,ll p) {
    ll res = 1;
    x = x % p;
    while (y > 0) {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
   
   ll n,i;
   cin>>n;
   ll a[n]={0};
   map<ll,ll> v;
   for(i=0;i<n;i++)
   	cin>>a[i];


   
   for(i=0;i<n;i++)
      {v[a[i]]++;
	  }
   
    ll l=v.size();
    ll f[n]={0},ans=0;
    
    for(auto xx : v)
         {
         	ans= ans + (xx.second*(xx.second-1))/2;
               	
		 }
      
      ll y[n]={0},g[n]={0},j[n]={0};
      
      for(i=0;i<n;i++)
       {
       	   j[i]=(v[a[i]]*(v[a[i]]-1))/2;
		   v[a[i]]--;
       	   y[i]=v[a[i]];
       	   v[a[i]]++;
       	   g[i]=(y[i]*(y[i]-1))/2;
       	
	   }
      
        ll org=0;
    for(i=0;i<n;i++)
    {
      org= ans + g[i]-	j[i];
      cout<<org<<endl;
      org=0;
	}
   
     
  
}


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

int main() {
  int64_t n;
  cin>>n;
  vector<int64_t> p(n);
  for(int i=0;i<n;i++){
    cin>>p.at(i);
  }
  int64_t count=0;
  int64_t ans=0;
  for(int i=0;i<n;i++){
    if(p.at(i)==i+1){
      count++;
    }
    else{
      ans+=((count+1)/2);
      count=0;
    }
  }
  ans+=((count+1)/2);
  cout<<ans;
}

Measured memory_bytes: 1024
/*
String[]の初期化、整数の型がlongになっているか
関数（splitとかcontainsとか）内では"+"とかは正規表現となされるので"\\+"とする
配列のコピーはarr1=arr.clone()
HashSet<>[]はおのおの初期化した？？？？？
負の数の割り算は絶対値が小さいほうに切り捨てられるex.-1/2=0ので、ある値>kみたいな式だとバグらせやすいので注意
ある値>=kとして、切り上げた値をとるべき
toLowerCase()はアルファベット以外に対して行ってもエラーにはならない
 */
//入力終了→Ctrl+D
import java.time.Year;
import java.util.*;
import java.awt.*;
import java.awt.Graphics.*;
import static java.lang.System.*;
import static java.lang.Math.*;
public class Main {
    public static void main(String[] $) {
        Scanner sc = new Scanner(in);
        int n=sc.nextInt();
        int[] a=new int[n];
        for (int i = 0; i < n; i++) {
            a[i]=sc.nextInt();
            if(i<n-1)out.print(a[i]+" ");
            else out.println(a[i]);
        }
        for (int i = 1; i < n; i++) {
            int v=a[i];
            int j=i-1;
            while (j>=0&&a[j]>v){
                a[j+1]=a[j];
                j--;
            }
            a[j+1]=v;
            for(int k=0;k<n;k++){
                out.print(a[k]);
                if(k<n-1)out.print(" ");
            }
            out.println();
        }
    }
}


Measured memory_bytes: 34416
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll mod = 1000000007;

ll r(ll x, ll y) {
  if (y == 0) return 1;
  else if (y % 2 == 0) return r(x, y/2) * r(x, y/2) % mod;
  else return x * r(x, (y-1)/2) % mod * r(x, (y-1)/2) % mod;
}
  
int main() {
  int n, k;
  cin >> n >> k;
  if (500 * n >= k) cout << "Yes" <<endl;
  else cout << "No" <<endl;
} 


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

int main() {
    int N,K;
    cin >> N >> K ;
    int h[N];
    for(int i=0;i<N;i++){
        cin >> h[i];
    }
    int count;
    for(int i=0;i<N;i++){
        if(h[i] >= K) count++;
    }  
    cout << count << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
//#define in freopen("in.txt","r",stdin)
//#define out freopen("out.txt","w",stdout) 
ll n,m,i,j,k,t,l,r;
ll a,b,c,d,g;
char A,C,X,Y,Z;
ll ans,MAX,MIN,sum;
ll ax[2000500];
ll R[10000]={0},G[10000]={0},B[10000]={0};
char str[5000];
ll dx[12];
ll bx[500];


int main()
{
    t=1;
    //scanf("%lld",&t);
    while(t--)
    {
        sum=0;
        cin >> n;
        scanf("%s",str);
        r=0;
        b=0;
        g=0;
        for(i=1;i<=n;i++)
        {
            if(str[i-1]=='R') R[i]++;
            if(str[i-1]=='G') G[i]++;
            if(str[i-1]=='B') B[i]++;
            R[i]+=R[i-1];
            B[i]+=B[i-1];
            G[i]+=G[i-1];
        }
        for(i=1;i<=n-2;i++)
        {
            if(str[i-1]=='G') sum+=(R[n]-R[i])*(B[n]-B[i]);
            if(str[i-1]=='R') sum+=(G[n]-G[i])*(B[n]-B[i]);
            if(str[i-1]=='B') sum+=(R[n]-R[i])*(G[n]-G[i]);
        }
        for(i=1;i<=n;i++)
        {
        	for(j=i+1;j<=n;j++)
        	{
        		k=j+(j-i);
        		if(k>n) break;
        		if(str[k-1]!=str[j-1]&&str[i-1]!=str[j-1]&&str[i-1]!=str[k-1])
        		sum--;
			}
		}
        printf("%lld\n",sum);
    }
	return 0;
}

Measured memory_bytes: 3844
using System;
using System.Linq;

public class Test
{
	public static void Main()
	{
		
		var a = Console.ReadLine().Split().Select(b => int.Parse(b)).ToArray();
		int x = a[0];
		int n = a[1];
		int ans = x;
		int sa = 0;
		int atcoder = 1000000000;
		int counter = 0;
		
		if(n==0){
			Console.WriteLine(x);
		}else{
			var p = Console.ReadLine().Split().Select(q => int.Parse(q)).ToArray();
		
		for(int i=0;i!=atcoder;i++){
			
			for(int j=0;j!=n;j++){
				if(p[j]==ans){counter++;}
			}
			if(counter==0){
				break;
			}else{
				sa = -1-sa;
				ans += sa;
				counter = 0;
			}
			for(int k=0;k!=n;k++){
				if(p[k]==ans){counter++;}
			}
			if(counter==0){
				break;
			}else{
				sa = 1-sa;
				ans += sa;
				counter = 0;
			}
			
		}
		Console.WriteLine(ans);
		
		}
	}
}

Measured memory_bytes: 28136
import sys
c = []
for i in range(3):
  c.append(list(map(int, input().split())))
  
for i in range(2):
  arr1 = c[i]
  arr2 = c[i+1]
  
  d = arr1[2] - arr2[2]
  for j in range(2):
    if d != arr1[j]-arr2[j]:
      print('No')
      sys.exit(0)
  
for i in range(2):
  d = c[2][i] - c[2][i+1]
  for j in range(2):
    if d != c[j][i]-c[j][i+1]:
      print('No')
      sys.exit(0)
  
      
    
print('Yes')

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define rep(i,n,m) for(int i = (n); i <(m); i++)
#define rrep(i,n,m) for(int i = (n) - 1; i >=(m); i--)
using namespace std;
using ll = long long;
const ll MAXV = 1e+12;

int main()
{
    int n, k;
    cin >> n >> k;
    vector<ll> a_values(n);
    rep(i, 0, n) cin >> a_values[i];

    vector<ll> csum(n+1, 0);
    rep(i, 0, n) csum[i+1] = csum[i] + a_values[i];

    vector<ll> values;
    rep(i, 0, n)
        rep(j, i+1, n)
            values.push_back(csum[j+1]-csum[i]);
    
    ll base = 1;
    while (base < MAXV) base <<= 1;

    while (base)
    {
        int num = 0;
        vector<ll> new_values;

        for (auto v: values)
        {
            if (base & v)
            {
                new_values.push_back(v);
                ++num;
            }
        }

        if (num >= k)
            swap(values, new_values);
        base >>= 1;
    }

    ll ans = values[0];
    for (auto v: values)
        ans &= v;

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

Measured memory_bytes: 6132
#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;
int main(){
    int n;
    cin >> n;
    vector<int>a,b;
    a.resize(n);
    b.resize(n-1);
    for(int i=0;i<n-1;i++)cin>>b[i];
    a[0]=b[0];
    for(int i=0;i<n-2;i++){
        a[i+1] = min(b[i],b[i+1]);
    }
    a[n-1]=b[n-2];
    int sum = 0;
    for(int i=0;i<n;i++)sum += a[i];
    cout << sum << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define bs binary_search
#define pb push_back
#define pp pair<ll,ll>
#define F first 
#define S second 
#define lc "\n"
ll power(ll x,ll y,ll p){ll res=1;x=x%p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;} 
ll MAX=1e18 , MIN=-1e18 , MOD=1000000007;
int main() 
{
    fastio
    int s,w; cin>>s>>w;
    if(w>=s) cout<<"unsafe"; else cout<<"safe";
    return 0;
}

Measured memory_bytes: 3664
//Hariom_Pandey

#include<bits/stdc++.h>
using namespace std;

int main(){
    string str, str2;
    cin>>str>>str2;
    int cnt=0;
    for(int i=0; i<str.size(); i++){
        
        if(str[i]!=str2[i]) cnt++;
  
    }
    cout<<cnt;
}


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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm(a, b) (a)/__gcd((a),(b))*(b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 200005;

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

vector<int> Div(int n) {
    vector<int> ret;
    for(int i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);

            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

LL dp[3005][6005];

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

    int n, t;
    cin >> n >> t;
    vector<LP> v(n);
    for(int i = 0; i < n; ++i) {
        cin >> v[i].F >> v[i].S;

    }
    sort(all(v));

    LL res = 0;
    for(int i = 0; i < n; ++i) {
        for(int j = 1; j <= t + 3000; ++j) {
            if(i == 0) {
                if(v[i].F <= j) {
                    dp[i][j] = v[i].S;

                }
            } else {
                dp[i][j] = dp[i - 1][j];
                if(v[i].F <= j && j - v[i].F < t) {
                    dp[i][j] = max(dp[i][j], dp[i - 1][j - v[i].F] + v[i].S);

                }
            }
            res = max(res, dp[i][j]);
        }
    }

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



Measured memory_bytes: 141056
n, m = map(int, input().split())
p = []
s = []
for i in range(m):
    p_i, s_i = input().split()
    p.append(int(p_i))
    s.append(s_i)

correct = [0]*n
penalty = [0]*n

for i in range(m):
    no = p[i]
    if correct[no-1] == 1:
        continue
    elif s[i] == 'WA':
        penalty[no-1] += 1
    elif s[i] == 'AC':
        correct[no-1] = 1

pen = 0
for i in range(n):
    if correct[i] == 1:
        pen += penalty[i]
print(sum(correct), pen)

Measured memory_bytes: 21528
#include <bits/stdc++.h>
#define int long long
#pragma GCC optimize("O3,Ofast,no-stack-protector,unroll-loops,fast-math")
#pragma GCC target("avx,avx2,sse")
using namespace std;

int calc(int a, int b, int k) {
    if (a >= b) {
        return a - b;
    } else {
        return k - (b - a);
    }
}

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

    int k, n;
    cin >> k >> n;
    vector<int> kek(n);
    for (int i = 0; i < n; i++) {
        cin >> kek[i];
    }
    int best = k;
    for (int i = 0; i < n; i++) {
        int j = (i + 1) % n;
        best = min(best, k - calc(kek[j], kek[i], k));
    }
    cout << best << '\n';

    fflush(stdout);
    return 0;
}


Measured memory_bytes: 4748
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;
#define INF 0x3f3f3f3f
const int maxn=2e6+10,mod=1e9+7;
#define _rep(i,a,b) for(int i=(a);i<=(b);++i)
int r1,r2,c1,c2;
long long fac[maxn],inv[maxn],finv[maxn],ans;
void init()
{
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<=2e6+5;i++)
    {
        fac[i]=fac[i-1]*i%mod;
        inv[i]=(mod-mod/i)*inv[mod%i]%mod;
        //cout<<i<<" "<<inv[i]<<endl;
        finv[i]=finv[i-1]*inv[i]%mod;
    }
}
long long C(long long n,long long a)
{    
    if(n<a||n<0||a<0) return 0;
    return fac[n]*(finv[a]*finv[n-a]%mod)%mod;
}
int main()
{
    #ifdef __LOCAL__
        freopen("1.in","r",stdin);
        freopen("1.out","w",stdout);
    #endif
    cin>>r1>>c1>>r2>>c2;
    init();
    for(int i=r1;i<=r2;i++)
    {
        ans=(ans+C(i+1+c2,i+1)-C(i+c1,i+1)+mod)%mod;
    }
    cout<<ans<<endl;
    return 0;
}

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

public class Main {
	public static void main(String[] args) throws IOException{
		BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
		String [] string = bufferedReader.readLine().split(" ");
		
		Integer a = Integer.parseInt(string[0]);
		Integer b = Integer.parseInt(string[1]);
		
		Integer dInteger = 0;
		Integer rInteger = 0;
		Double d;
		
		dInteger = a / b;
		rInteger = a % b;
		d = (double)a / (double)b;
		
		final String FORMAT = "%d %d %f";
		
		String s = String.format(FORMAT, dInteger,rInteger,d);
		System.out.println(s);
	}
}

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

int n,b[15],p[4][4],a[4][4];

int main()
{
	for (int i=1 ; i<=3 ; i++)
	    for (int j=1 ; j<=3 ; j++)
	        scanf("%d",&a[i][j]);
	
	scanf("%d",&n);
	for (int i=1 ; i<=n ; i++)
	{
		scanf("%d",&b[i]);
		for (int k=1 ; k<=3 ; k++)
		    for (int j=1 ; j<=3 ; j++)
		        if (b[i]==a[k][j]) p[k][j]=1;
	}
	
	for (int i=1 ; i<=3 ; i++)
	{
		if (p[i][1] && p[i][2] && p[i][3]) {
			printf("Yes\n");
			return 0;
		}
		if (p[1][i] && p[2][i] && p[3][i])
		{
			printf("Yes\n");
			return 0; 
		}
	}
	
	if(p[1][1] && p[2][2] && p[3][3]) 
	{
		printf("Yes\n");
		return 0;
	}
	if (p[1][3] && p[2][2] && p[3][1])
	{
		printf("Yes\n");
		return 0;
	}
	
	printf("No\n");
	return 0;
}

Measured memory_bytes: 256
package main

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

func liner_search(A []int, n, key int) bool {
	A = append(A, key) // 番兵
	i := 0
	for A[i] != key {
		i++
	}
	return i != n+1
}

func main() {

	var count int

	scanner := bufio.NewScanner(os.Stdin)

	scanner.Scan()
	n, _ := strconv.Atoi(scanner.Text())

	S := make([]int, n+1)
	scanner.Scan()
	sS := strings.Fields(scanner.Text())
	for i := 0; i < n; i++ {
		S[i], _ = strconv.Atoi(sS[i])
	}

	scanner.Scan()
	q, _ := strconv.Atoi(scanner.Text())

	T := make([]int, q)
	scanner.Scan()
	sT := strings.Fields(scanner.Text())
	for i := range T {
		T[i], _ = strconv.Atoi(sT[i])
	}

	for _, v := range T {
		if !liner_search(S, n, v) {
			continue
		}
		count++
	}
	fmt.Println(count)
}


Measured memory_bytes: 6728
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using loop = int;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(loop (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(loop (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(loop (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(loop (i)=(n);(i)>=(a);--(i))
#define each(i, a) for(auto &i : a)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause") //comment out this on AOJ.
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }

int main() {
    init();

    string s, t; cin >> s >> t;
    FOR(i, 0, t.length())cout << s[i] << t[i];
    if (s.length() > t.length())cout << s.back();
    cout << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
#define fi first
#define se second
#define sz(x) int(x.size())
using namespace std;
using ll = long long;
using P = pair<int ,int>;
const int INF = 1001001001;
const int MOD = 1000000007;
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 (b<a) {a=b; return 1;} return 0;}

#ifdef _DEBUG
#include "debug.h"
#else
#define debug(...)
#define print(...)
#endif

int main() {
    string n; cin >> n;
    ll tot = 0;
    reverse(all(n));
    rep(i, sz(n)) {
        tot += n[i]-'0';
    }
    debug(tot);
    if (tot%9) cout << "No" << endl;
    else cout << "Yes" << endl;
}

Measured memory_bytes: 3708
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <cmath>
#include <vector>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <queue>

typedef long long ll;
const ll LL_MAX (1LL<<60);

#define rep(i,s,e) for(ll i=(s); i<(e); i++) 

using namespace std;

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

    string s;
    cin >>s;

    ll cnt(0);
    ll n (s.size());
    rep(i,0,n/2)
        if (s[i] != s[n-1-i]) cnt++; 

    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100000000000
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define P pair<int, int>
#define PP pair<P,P>
#define T tuple<int,int,int> 
using namespace std;
 
int main(){
    int d; cin >> d;
    vector<int> c(26);
    vector<P> C;
    rep(i,26){
        cin >> c[i];
        C.emplace_back(c[i],i);
    }
    sort(all(C));
    reverse(all(C));
    vector<vector<int> > s(d);
    rep(i,d)rep(j,26){
        int a; cin >> a;
        s[i].push_back(a);
    }
 
    //vector<int> ld(26,0);
    vector<vector<int> > ds(26);
    vector<int> days(d,25);
    //rep(i,d) days[i]=i%26;

    //ll ans=0;
    rep(i,d){
        int t=days[i];
        ds[t].push_back(i);
        /*
        ld[t]=i+1;
        ans+=s[i][t];
        rep(j,26){
            ans-=c[j]*(i+1-ld[j]);
        }
        */
    }
    rep(i,3000){
        rep(ss,26)rep(D,d){
        int Q=C[ss].second;
        int pd=days[D];
        if(pd==Q) continue;
        int be,af,be2,af2;
        int r,l;
        l=-1;
        r=ds[pd].size();
        while(l+1<r){
            int c=(l+r)/2;
            if(ds[pd][c]<=D) l=c;
            else r=c;
        }
        if(r==ds[pd].size()) af=d;
        else af=ds[pd][r];
        l=-1;
        r=ds[pd].size();
        while(l+1<r){
            int c=(l+r)/2;
            if(ds[pd][c]>=D) r=c;
            else l=c;
        }
        if(l==-1) be=-1;
        else be=ds[pd][l];

        int l2=-1;
        r=ds[Q].size();
        while(l2+1<r){
            int c=(l2+r)/2;
            if(ds[Q][c]<=D) l2=c;
            else r=c;
        }
        if(r==ds[Q].size()) af2=d;
        else af2=ds[Q][r];
        l2=-1;
        r=ds[Q].size();
        while(l2+1<r){
            int c=(l2+r)/2;
            if(ds[Q][c]>=D) r=c;
            else l2=c;
        }
        if(l2==-1) be2=-1;
        else be2=ds[Q][l2];

        if(c[Q]*(D-be2)*(af2-D)+s[D][Q]-c[pd]*(D-be)*(af-D)-s[D][pd]>0){
            days[D]=Q;
            ds[pd].erase(ds[pd].begin()+l+1);
            ds[Q].insert(ds[Q].begin()+l2+1,D);
        }
    }
    }
    rep(i,d) cout << days[i]+1 << endl;
return 0;
}

Measured memory_bytes: 3720
import sys
input = sys.stdin.readline
n, m = map(int, input().split())
k = []
for _ in range(m):
    a, b = map(int, input().split())
    c = list(map(int, input().split()))
    k.append((a, sum([2 ** (i-1) for i in c])))

C = 2 ** n
INF = 10 ** 6

dp = [[INF for _ in range(C)] for __ in range(m + 1)]
for i in range(m+1):
    dp[i][0] = 0

for i, ki in enumerate(k):
    for j in range(C):
        dp[i+1][j] = dp[i][j]
    for j in range(C):
        dp[i+1][j | ki[1]] = min(dp[i+1][j | ki[1]], dp[i][j] + ki[0])

ans = dp[m][C-1]
if ans == INF:
    print(-1)
else:
    print(ans)


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

stores = dict()
for n in range(N):
    S, P = input().split()
    if S not in stores:
        stores[S] = []
    stores[S].append((int(P), n+1))

sorted_stores = sorted(list(stores.keys()))

for s in sorted_stores:
    stores[s].sort(key=lambda x: x[0], reverse=True)

    for ss in stores[s]:
        print(ss[1])


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

int main() {
	long n, m;
	cin >> n >> m;
	pair<long, long> P[n];
	for (int i = 0; i < n; i++) {
		cin >> P[i].first >> P[i].second;
	}
	sort(P, P + n);
	long cnt = 0;
	long ans = 0;
	for (int i = 0; i < n; i++) {
		if (cnt >= m) break;
		ans += P[i].first * min(m - cnt, P[i].second);
		cnt += P[i].second;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
#include<cmath>
#include<iomanip>
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define sz(a) (int)a.size()
using namespace std;

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

	int n;
	cin >> n;
	set<string> se;
	rep(i, n) {
		string si;
		cin >> si;
		se.insert(si);
	}
	cout << sz(se) << endl;
}

Measured memory_bytes: 19180
import math


class Sieve:
    """Sieve of Eratosthenes.

    List primes up to n.
    """

    def __init__(self, n):
        self.__prime = []
        self.__is_prime = [i >= 2 for i in range(n + 1)]

        for i in range(2, int(math.sqrt(n)) + 1):
            if self.__is_prime[i]:
                for j in range(i * i, n + 1, i):
                    self.__is_prime[j] = False

        for i in range(2, n + 1):
            if self.__is_prime[i]:
                self.__prime.append(i)

    def prime(self):
        return self.__prime

    def is_prime(self, n):
        return self.__is_prime[n]


def bf(N, a):
    p = Sieve(max(a) + 1).prime()  # len <= 9952

    prime_to_power = {}
    for prime in p:
        prime_to_power[prime] = 0

    for i in range(N):
        ai = a[i]
        for prime in p:
            power = 0
            while ai % prime == 0:
                ai //= prime
                power += 1
            prime_to_power[prime] = max(prime_to_power[prime], power)
    lcm = 1
    for prime in prime_to_power:
        lcm *= prime ** prime_to_power[prime]
    m = lcm - 1
    ans = 0
    for ai in a:
        ans += m % ai
    return ans


def al(N, a):
    return sum(a) - len(a)


if __name__ == '__main__':
    N = int(input())  # 2 <= N <= 3000
    a = list(map(int, input().split()))  # 2 <= ai <= 100000
    # print(bf(N, a))
    print(al(N, a))

Measured memory_bytes: 3316
let readIntArray () =
    stdin.ReadLine().Split(" ") |> Array.map int64

readIntArray ()

let rec solve partSum sum list =
    match list with
    | x :: xx ->
        if partSum = -1L
        then solve x 0L xx
        else solve ((partSum + x) % 1000000007L) (sum + x * partSum % 1000000007L) xx
    | [] -> sum % 1000000007L

()
|> readIntArray
|> Array.toList
|> solve -1L 0L
|> printfn "%d"


Measured memory_bytes: 56824
#pragma GCC optimize "trapv" 
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define rep(i,a,n)     for(int i=a;i<n;i++)
#define rep3(n)        for(int i=0;i<n;i++)
#define inarr(arr,n)   rep(i,a,n)cin>>arr[i]
#define ll             long long int
#define pb             push_back
#define all(v)         v.begin(),v.end()
#define endl           "\n"
#define eb             emplace_back
#define x              first
#define y              second
#define gcd(a,b)       __gcd(a,b)
#define mem1(a)        memset(a,-1,sizeof(a))
#define pres(a,x)      a.find(x)!=a.end()
#define sz(a)          (int)a.size()
#define pii            pair<int,int>
#define IOS            ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ret            return 0
#define pi             3.1415926536
#define hell           1000000007
#define narak          998244353
#define elasped_time 1.0 * clock() / CLOCKS_PER_SEC
const int inf1=1e9;
const ll inf2=1e18;
const int N=100000;
using namespace std;
using namespace __gnu_pbds;
#define ordered_set tree<pii, null_type,less<pii>, rb_tree_tag,tree_order_statistics_node_update>
int dirs[4][2] ={{1,0},{-1,0},{0,1},{0,-1}};
ll dp[N+1][2];
vector<int>g[N+1];
void dfs(int u,int p){
    dp[u][0]++;
    dp[u][1]++;
    for(auto i:g[u]){
        if(i!=p){
           dfs(i,u);
           dp[u][1]=dp[i][0]*dp[u][1]%hell;
           dp[u][0]=(dp[u][0]*(dp[i][0]+dp[i][1]))%hell;
        }
    }
}
int solve(){
   int n;cin>>n;         
   rep3(n-1){
       int a,b;cin>>a>>b;
       g[a].pb(b);
       g[b].pb(a);
   }          
   dfs(1,0);
   cout<<(dp[1][0]+dp[1][1])%hell<<endl;
 ret;
}
int main(){
    IOS;
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    #ifdef cat
    cat();
    #endif
    int t=1;//cin>>t;
    while(t--){
        solve();
    }
    ret;
}
 

Measured memory_bytes: 14208
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <cmath>
#include <cstdio>
#include <istream>
#include <sstream>
#include <iomanip>
#include <iterator>
#include <climits>
using namespace std;

typedef ostringstream OSS;
typedef istringstream ISS;

typedef vector<int> VI;
typedef vector< VI > VVI;

typedef long long LL;

typedef pair<int, int> PII;
typedef vector<PII> VPII;

#define X first
#define Y second

const char OK = '.';
const char BAD = '#';
const char USER = '@';

int W, H;
int cnt;
vector<string> ts;
vector<vector<bool>> done;

void dfs(int y, int x) {
	if (y < 0 || x < 0 || y >= H || x >= W) return;
	if (done[y][x]) return;
	if (ts[y][x] == BAD) return;
	
	done[y][x] = true;
	cnt++;

	for (int dx = -1; dx <= 1; dx++) {
		for (int dy = -1; dy <= 1; dy++) {
			if (!dy ^ !dx) {
				dfs(y + dy, x + dx);
			}
		}
	}
}

int main(void) {
	while (cin >> W >> H, W) {
		ts = vector<string>(H);
		done = vector<vector<bool>>(H, vector<bool>(W));
		for (auto &line : ts) cin >> line;

		cnt = 0;

		for (int y = 0; y < H; y++) {
			for (int x = 0; x < W; x++) {
				if (ts[y][x] == USER) {
					dfs(y, x);
				}
			}
		}

		cout << cnt << endl;
	}

	return 0;
}

Measured memory_bytes: 1244