akhauriyash/Code-Regression huggingface dataset:
/*************************************************************************
    > File Name: test.cpp
    > Author: Akira 
    > Mail: qaq.febr2.qaq@gmail.com 
 ************************************************************************/

#include<bits/stdc++.h>
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
#define MST(a,b) memset(a,b,sizeof(a))
#define CLR(a) MST(a,0)
#define Sqr(a) ((a)*(a))
using namespace std;

#define MaxN 100001
#define MaxM MaxN*10
#define INF 0x3f3f3f3f
#define PI 3.1415926535897932384626
const int mod = 1E9+7;
const double eps = 1e-6;
#define bug cout<<88888888<<endl;
#define debug(x) cout << #x" = " << x << endl;
LL N;
void solve()
{
    int len = INF;
    for(LL i=1;i*i<=N;i++)
    {
        if( N%i == 0)
        {
            LL cnt = N/i;
            int tmp = 0;
            while(cnt)
            {
                cnt/=10;
                tmp++;
            }
            len = min(len,tmp);
        }
    }
    printf("%d\n", len);
}
int main()
{
    //std::ios::sync_with_stdio(false);
    scanf("%lld",&N);
    solve();
    //system("pause");
}


Measured memory_bytes: 256
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)

	n := getNextInt(scanner)
	counter := make([]int, n)
	for i := 0; i < n; i++ {
		a := getNextInt(scanner) - 1
		counter[a]++
	}
	sort.Ints(counter)
	ss := make([]int, n+1)
	for i := 0; i < n; i++ {
		ss[i+1] = ss[i] + counter[i]
	}

	for k := 1; k <= n; k++ {
		l := -1
		r := n/k + 1
		for l+1 < r {
			m := (l + r) >> 1
			ll := -1
			rr := n
			for ll+1 < rr {
				mm := (ll + rr) >> 1
				if counter[mm] < m {
					ll = mm
					continue
				}
				rr = mm
			}

			if (n-rr)*m+ss[rr] < m*k {
				r = m
				continue
			}

			l = m
		}
		fmt.Println(l)
	}
	writer.Flush()
}


Measured memory_bytes: 8576
#include <bits/stdc++.h>
#define FOR(I,X,Y) for(int (I)=(X);(I)<(Y);(I)++)
#define REP(I,X,Y) for(int (I)=(Y)-1;(I)>=(X);(I)--)
#define ALL(X) (X).begin(),(X).end()
#define INF 1000000007
#define LINF 1000000000000000007
typedef long long ll;
using namespace std;

int D[10];

bool check(int n){
  string s = "0123456789",N = to_string(n);
  FOR(i,0,10){
    if(D[i]){
      FOR(j,0,N.size()){
        if(N[j] == s[i]){
          return 0;
        }
      }
    }
  }
  return 1;
}

int main(){
  bool kanou0desuka = 0;
  int minkanouyatu = INF;
  int N,K,y;
  cin >> N >> K;
  FOR(i,0,N){
    cin >> y;
    D[y] = 1;
  }
  FOR(i,N,100000){
    if(check(i)){
      cout << i << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 256
gets
a = gets.chomp.split(" ").map(&:to_i)
count_a = Hash.new(0)
ans = 0

a.each do |i|
    count_a[i.to_s] += 1
end

count_a.each do |num, counted|
    if num.to_i > counted then
        ans += counted
    elsif num.to_i < counted then
        ans += counted - num.to_i
    end
end

puts ans

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

int main() {
    int N;
    cin >> N;
    vector<int> vec(N);
    for(int i = 0; i < N; i++){
        cin >> vec.at(i);
    }
sort(vec.begin(),vec.end());
reverse(vec.begin(),vec.end());

int count = 1;
for(int i=0;i<N-1;i++){
    if(vec.at(i)>vec.at(i+1))
    count++;
}
cout << count <<endl;

}

Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

h, w, a, b = map(int, readline().split())
ans_1 = '1' * a + '0' * (w - a)
ans_2 = '0' * a + '1' * (w - a)
for i in range(b):
    print(ans_1)
for i in range(h - b):
    print(ans_2)


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

int main() {
  int N;
  cin >> N;
  int c_0 = 0;
  int c_1 = 0;
  int c_2 = 0;
  int c_3 = 0;
  
  for(int i=0;i < N;i++){
    string S;
    cin >> S;
    
    if(S == "AC")++c_0;
    else if(S == "WA")++c_1;
    else if(S == "TLE")++c_2;
    else if(S == "RE")++c_3;
  }
  cout << "AC x " << c_0 << endl; 
  cout << "WA x " << c_1 << endl; 
  cout << "TLE x " << c_2 << endl; 
  cout << "RE x " << c_3 << endl; 
}


Measured memory_bytes: 3552
#![allow(unused_imports, unused_variables, dead_code)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

trait InputValue {
    fn parse(s: &str) -> Self;
}

fn read<T: InputValue>() -> T {
    let mut buf = String::new();
    let _ = stdin().read_line(&mut buf);
    T::parse(&buf.trim())
}

fn readnc<T: InputValue>() -> Vec<T> {
    let mut vec = vec![];
    let line: String = read();
    for token in line.split_whitespace() {
        vec.push(T::parse(token));
    }
    vec
}

fn readn<T: InputValue>(n: usize) -> Vec<T> {
    let mut vec = vec![];
    for _ in 0..n {
        vec.push(read());
    }
    vec
}

macro_rules! parse_single_value {
    ($($t:ty),*) => {
        $(
            impl InputValue for $t {
                fn parse(s: &str) -> $t { s.parse().unwrap() }
            }
        )*
	}
}
parse_single_value!(i32, i64, f32, f64, usize, String);

macro_rules! parse_tuple {
	($($t:ident),*) => {
		impl<$($t),*> InputValue for ($($t),*) where $($t: InputValue),* {
			fn parse(s: &str) -> ($($t),*) {
				let mut tokens = s.split_whitespace();
				let t = ($($t::parse(tokens.next().unwrap())),*);
				t
			}
		}
	}
}
parse_tuple!(A, B);
parse_tuple!(A, B, C);

// ===

const MOD: i64 = 1000000007;

fn powmod(a: i64, p: i64, m: i64) -> i64 {
    let mut ret = 1i64;
    let mut aa = a;
    let mut pp = p;
    while pp >= 1 {
        if pp & 1 == 1 {
            ret *= aa;
            ret %= m;
        }
        aa = aa * aa % m;
        pp >>= 1;
    }
    ret
}

fn inv(a: i64, m: i64) -> i64 {
    powmod(a, m-2, m)
}


fn main() {
    let n: usize = read();
    let s: String = read();


    let mut dp: Vec<Vec<i64>> = vec![vec![0; n+1]; 2];
    dp[0][0] = 1;

    for i in 0..n {
        let fr = i % 2;
        let to = 1 - fr;
        for k in 0..n+1 {
            dp[to][k] = 0;
        }

        for k in 0..n+1 {
            let base = dp[fr][k];
            if base == 0 {
                continue;
            }

            let tk = max(k as i32 - 1, 0) as usize;
            dp[to][tk] += base;
            dp[to][tk] %= MOD;

            if k + 1 <= n {
                dp[to][k+1] += base * 2 % MOD;
                dp[to][k+1] %= MOD;
            }
        }
    }

    let total = dp[n%2][s.len()];
    let inv2 = inv(2, MOD);
    println!("{}", total * powmod(inv2, s.len() as i64, MOD) % MOD);
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define cina(a, n) for (int i = 0; i < n; ++i){ cin >> a[i]; }
#define ll long long
#define ld long double

using namespace std;

int main () {
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int n, k;
	cin >> n >> k;
	int p[n];
	cina(p, n);
	sort(p, p+n);
	int ans = 0;
	for (int i = 0; i < k; ++i) {
		ans += p[i];
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 3588
#![allow(unused_imports, unused_variables, dead_code, non_snake_case, unused_macros)]
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

fn getline() -> String{
    let mut res = String::new();
    std::io::stdin().read_line(&mut res).ok();
    res
}

macro_rules! readl {
    ($t: ty) => {
        {
            let s = getline();
            s.trim().parse::<$t>().unwrap()
        }
    };
    ($( $t: ty),+ ) => {
        {
            let s = getline();
            let mut iter = s.trim().split(' ');
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*) 
        }
    };
}

macro_rules! readlvec {
    ($t: ty) => {
        {
            let s = getline();
            let iter = s.trim().split(' ');
            iter.map(|x| x.parse().unwrap()).collect::<Vec<$t>>()
        }
    }
}

macro_rules! mvec {
    ($v: expr, $s: expr) => {
        vec![$v; $s]
    };
    ($v: expr, $s: expr, $($t: expr),*) => {
        vec![mvec!($v, $($t),*); $s]
    };
}

macro_rules! debug {
    ($x: expr) => {
        println!("{}: {:?}", stringify!($x), $x)
    }
}

fn printiter<'a, T>(v: &'a T)
where
    &'a T: std::iter::IntoIterator, 
    <&'a T as std::iter::IntoIterator>::Item: std::fmt::Display {
    for (i,e) in v.into_iter().enumerate() {
        if i != 0 {
            print!(" ");
        }
        print!("{}", e);
    }
    println!("");
}

struct ContestPrinter {
    s: String,
}

impl ContestPrinter {
    fn new() -> ContestPrinter {
        ContestPrinter {
        s: String::new(),
        }
    }

    fn print<T>(&mut self, x: T)
        where T: std::fmt::Display {
        self.s.push_str(format!("{}", x).as_str());
    }

    fn println<T>(&mut self, x: T)
        where T: std::fmt::Display {
        self.s.push_str(format!("{}\n", x).as_str());
    }
}

impl std::ops::Drop for ContestPrinter {
    fn drop(&mut self) {
        print!("{}", self.s);
    }
}

fn is_max_i64(num: i64) -> bool { if num == i64::max_value() { true } else { false } }

fn main() {
    let mut pr = ContestPrinter::new();
    
    let (N, C) = readl!(usize, usize);
    let mut cnt: Vec<Vec<i32>> = vec![vec![0; 100005]; C];

    for i in 0..N {
        let (s, t, mut c) = readl!(usize, usize, usize); c -= 1;
        cnt[c][s] += 1;
        cnt[c][t + 1] -= 1;
    }

    let mut ans = 0;
    for i in 1..100005 {
        let mut dup = 0;
        for j in 0..C {
            cnt[j][i] += cnt[j][i-1];
            if cnt[j][i] > 0 { dup += 1; }
        }
        ans = max(ans, dup);
    }

    pr.println(ans);
}

Measured memory_bytes: 18684
#include"bits/stdc++.h"
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define INF 1e+9


int main() {
	int n,x,a_num_1=0,a_num_2=0,b_num_1=0,b_num_2=0,a_kind,b_kind,a_ans,b_ans;
	cin >> n;
	vector<int> a, b;
	for (int i = 0; i < n; i += 2)
	{
		cin >> x;
		a.push_back(x);
		cin >> x;
		b.push_back(x);
	}

	sort(a.begin(), a.end());
	sort(b.begin(), b.end());

	int a_num =1; a_kind=a_ans = a[0];
	for (int i = 1; i < a.size(); i++)
	{
		if (a[i] == a_kind) a_num++;
		else {
			if (a_num > a_num_1) { a_num_2 = a_num_1; a_num_1 = a_num; a_ans = a_kind; }
			else if (a_num > a_num_2) { a_num_2= a_num; }
			a_kind = a[i];
			a_num = 1;
		}
	}
	if (a_num > a_num_1) { a_num_2 = a_num_1; a_num_1 = a_num; a_ans = a_kind; }

	int b_num = 1; b_kind = b_ans = b[0];
	for (int i = 1; i < b.size(); i++)
	{
		if (b[i] == b_kind) b_num++;
		else {
			if (b_num > b_num_1) { b_num_2 = b_num_1; b_num_1 = b_num; b_ans = b_kind; }
			else if (b_num > b_num_2) { b_num_2 = b_num; }
			b_kind = b[i];
			b_num = 1;
		}
	}
	if (b_num > b_num_1) { b_num_2 = b_num_1; b_num_1 = b_num; b_ans = b_kind; }

	int ans;
	if (a_ans != b_ans)
	{
		ans = n - a_num_1 - b_num_1;
	}
	else
	{
		ans = n - max((a_num_1 + b_num_2), (a_num_2 + b_num_1));
	}
	cout << ans << endl;

	return 0;
}

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

#define vi vector<int>

int main() {

    int N, Q;
    cin >> N >> Q;

    pair<string, int> tmp;
    // vi p;
    queue<pair<string, int>> qp;
    string name;
    int time;
    for (int i = 0; i < N; i++) {
        cin >> name >> time;
        tmp.first  = name;
        tmp.second = time;
        qp.push(tmp);
    }

    int count = 0;
    while (!qp.empty()) {
        tmp = qp.front();
        qp.pop();
        if (tmp.second > Q) {
            tmp.second -= Q;
            count += Q;
            qp.push(tmp);

        }
        else {
            count += tmp.second;
            cout << tmp.first << " " << count << endl;
        }
    }

    return 0;
}



Measured memory_bytes: 6324
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }
int main(int argc, char* argv[]) {
   int H,W,h,w;
   cin >> H >> W >> h >> w;
   int sum = H*W;
   cout << sum - w*H - h*W + h*w << endl; 
    return 0;
}


Measured memory_bytes: 256
import sys

def solve():
    input = sys.stdin.readline
    K = int(input())
    A = [int(a) for a in input().split()]
    if A[K-1] != 2: print(-1)
    else:
        minN, maxN = 2, 3
        for i in reversed(range(K - 1)):
            if maxN < A[i]: 
                print(-1)
                break
            else:
                lb = (minN - 1) // A[i]
                hb = maxN // A[i]
                if lb == hb: 
                    print(-1)
                    break
                else:
                    minN = A[i] * (lb + 1)
                    maxN = A[i] * hb + A[i] - 1
        else: print(minN, maxN)
    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 14196
#include<bits/stdc++.h>
using namespace std;
#define pb          push_back
#define vi          vector<int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define endl        "\n"
#define fast        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define int         long long int
#define mod         1000000007
#define test        int t;cin>>t;while(t--)
#define REP(i,a,b)  for(int i=a,i<=b;i++)
#define MAXN        200001

void solve(int arr[],int n){

    deque<int>ans;
    for(int i=0;i<n;i++){
        if(i&1)
            ans.push_front(arr[i]);
        else
            ans.push_back(arr[i]);
    }

    if(n&1){
        reverse(all(ans));
        for(auto x:ans){
            cout<<x<<" ";
        }
        cout<<endl;
    }
    else
    {
        for(auto x:ans){
            cout<<x<<" ";
        }
        cout<<endl;
    }
}

int32_t main()
{
    int n;cin>>n;
    int arr[n];

    for(int i=0;i<n;i++){
        cin>>arr[i];
    }

    solve(arr,n);
    return 0;
}

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

char op(int i, int pos) {
  char res;
  res = (i & 1 << pos) ? '+' : '-';
  return res;
}

int main() {
  char A, B, C, D;
  cin >> A >> B >> C >> D;

  int a = A - '0';
  int b = B - '0';
  int c = C - '0';
  int d = D - '0';

  rep(i, 2 * 2 * 2) {
    int n = a;
    n += (i & 1 << 0) ? b : -b;
    n += (i & 1 << 1) ? c : -c;
    n += (i & 1 << 2) ? d : -d;
    if (n == 7) {
      string ans;
      ans.push_back(A);
      ans.push_back(op(i, 0));
      ans.push_back(B);
      ans.push_back(op(i, 1));
      ans.push_back(C);
      ans.push_back(op(i, 2));
      ans.push_back(D);
      ans += "=7";
      cout << ans << endl;
      return 0;
    }
  }
}

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

int main()
{
    int count=0;
    string ch;
    getline(cin,ch);
    while(count < ch.size()){
        if(ch[count] == ' '){
        cout << ' ';
        }else if(islower(ch[count])) {
            ch[count] = toupper(ch[count]);
            cout << ch[count];
        }
        else if(isupper(ch[count])){
            ch[count] = tolower(ch[count]);
            cout << ch[count];
        }
        else cout << ch[count];
        count ++;
    }
    cout << endl;
    return 0;
}

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

#define MAXN 200010
#define LEN 1000010

int n,tot=1;
int son[LEN][26],cnt[LEN],alpha[MAXN][26];
unordered_map<int,int> val[LEN];
char tmp[LEN];
string s[MAXN];
long long ans,mul;

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;++i)
	{
		scanf("%s",tmp+1);
		s[i]=(tmp+1);
		int m=strlen(tmp+1),now=1,las;
		for(int j=m;j>=1;--j)
		{
			las=now;
			if(!son[now][tmp[j]-'a'])son[now][tmp[j]-'a']=++tot;
			now=son[now][tmp[j]-'a'];
			++alpha[i][tmp[j]-'a'];
		}
		++val[las][tmp[1]-'a'];
		++cnt[now];
	}
	for(int i=1;i<=n;++i)
	{
		int m=s[i].length(),now=1;
		for(auto v : val[now])
		{
			if(alpha[i][v.first])ans+=v.second;
		}
		for(int j=m-1;j>=0;--j)
		{
			now=son[now][s[i][j]-'a'];
			--alpha[i][s[i][j]-'a'];
			for(auto v : val[now])
			{
				if(alpha[i][v.first])ans+=v.second;
			}
		}
		mul+=cnt[now];
	}
	printf("%lld\n",ans-n);
}

Measured memory_bytes: 170944
#include <iostream>
#include <string>
#include <vector>
#include <stack>
using namespace std;

int main(void) {
	int n, q, T, ans = 0;
	cin >> n;
	vector<int> S(n);
	for (int i = 0;i < n;i++)cin >> S[i];
	cin >> q;
	for (int i = 0;i < q;i++) {
		cin >> T;
		for (int j = 0;j < n;j++) {
			if (T == S[j]) {
				ans++; break;
			}
		}
	}
	cout << ans << endl;
	return 0;
}


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

long D[100][6];

void rotate(long n, long a, long b, long c, long d){
    swap(D[n][a], D[n][b]);
    swap(D[n][b], D[n][c]);
    swap(D[n][c], D[n][d]);
}

void spin(long n, char c)
{
    if(c=='E'){ rotate(n, 0, 3, 5, 2);
        //swap(D[n][0],D[n][3]);swap(D[n][3],D[n][5]);swap(D[n][5],D[n][2]);
    }
    else if(c=='W'){ rotate(n, 0, 2, 5, 3);
        //swap(D[n][0],D[n][2]);swap(D[n][2],D[n][5]);swap(D[n][5],D[n][3]);
    }
    else if(c=='S'){ //rotate(n, 0, 1, 4, 5);
        swap(D[n][0],D[n][1]);swap(D[n][0],D[n][4]);swap(D[n][4],D[n][5]);
    }
    else if(c=='N'){ rotate(n, 0, 1, 5, 4);
        //swap(D[n][0],D[n][1]);swap(D[n][1],D[n][5]);swap(D[n][5],D[n][4]);
    }
}

int main() {
    int ans = 0;
    int n;
    cin >> n;
    for (int i = 0; i < n ; ++i) {
        for (int j = 0; j < 6; ++j) {
            cin >> D[i][j];
        }
    }
    for (int i = 0; i < n ; ++i) {
        for (int j = i + 1 ; j <= n ; ++j) {
            char SWS[8]={"SSSWSSS"};
            for(int k=0; k < 8; ++k){
                if(D[i][1] == D[j][1])break;
                spin(j,SWS[k]);
            }
            for(int k=0;k<4;++k){
                if(D[i][0] == D[j][0]){
                    if(D[i][1] == D[j][1] && D[i][2] == D[j][2] && D[i][3]==D[j][3] && D[i][4] == D[j][4] && D[i][5] == D[j][5])
                        ans++;
                }
                spin(j,'W');
            }
        }
    }

    if (ans == 0) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 1160
import math
n=int(input())
div=[]
for i in range(1,math.ceil(n**0.5)+1):
    if n%i==0:
        div.append(i)
        if i!=n//i:
            div.append(n//i)
div.sort()
if len(div)%2==0:
    print(div[len(div)//2]+div[len(div)//2-1]-2)
else:
    print(div[len(div)//2]*2-2)

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

typedef long long int ll;
typedef unsigned long long int ull;
#define rep(i,n) for(ll i=0;i<(n);i++)

using namespace std;


struct Node{
    char c;
    ll cost;
    bool operator< (const Node &r) const{
        return cost < r.cost;
    }
};

int main(){
    ll n, k;
    cin >> n >> k;
    string p[n];
    rep(i, n)   cin >> p[i];

    map<char, ll> m;
    set<char> keyset;
    rep(i, n){
        m[p[i][0]]++;
        keyset.insert(p[i][0]);
    }

    priority_queue<Node> q;
    for(char key : keyset){
        q.push({key, m[key]});
    }

    ll cnt = 0;
    while(true){
        vector<Node> v;
        rep(i, k){
            if(q.empty())   break;
            v.push_back(q.top());
            q.pop();
        }

        if((ll)v.size() < k)    break;
        if(v[k-1].cost <= 0)    break;
        cnt++;

        rep(i, k){
            q.push({v[i].c, v[i].cost-1});
        }
    }

    cout << cnt << endl;

    return 0;
}

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

int main() {
	int x, y;

	while (cin >> x >> y) {
		if (x == 0 && y == 0)	break;
		if (x < y) cout << x << " " << y << endl;
		else cout << y << " " << x << endl;
	}

	return 0;
}

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

namespace ConsoleApp44 {
    class Program {
        static void Main(string[] args) {
            var st = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

            int H = st[0];
            int W = st[1];

            if (H % 3 == 0 || W % 3 == 0) {
                Console.WriteLine(0);
                return;
            }




            //一回目が横割りの時
            int ans_tate_yoko = 0;
            //一回目が縦割りの時
            int ans_yoko_tate = 0;

            int[] cand = new int[3];

            int ans_tate_tate = 0;
            int ans_yoko_yoko = 0;

            //縦縦に切るとき
            cand[0] = H * (W / 3);
            cand[1] = H * ((W - W / 3) / 2);
            cand[2] = H * (W - W / 3 - (W - W / 3) / 2);

            Array.Sort(cand);
            ans_tate_tate = cand[2] - cand[0];

            //横横に切るとき
            cand[0] = W * (H / 3);
            cand[1] = W * ((H - H / 3) / 2);
            cand[2] = W * (H - H / 3 - (H - H / 3) / 2);

            Array.Sort(cand);
            ans_yoko_yoko = cand[2] - cand[0];

            if (H % 3 == 1) {
                cand[0] = (W / 2) * (H - H / 3);
                cand[1] = (W - W / 2) * (H - H / 3);
                cand[2] = W * (H / 3);

                Array.Sort(cand);

                ans_tate_yoko = cand[2] - cand[0];
            } else if (H % 3 == 2) {
                cand[0] = (W / 2) * (H - H / 3 - 1);
                cand[1] = (W - W / 2) * (H - H / 3 - 1);
                cand[2] = W * (H / 3 + 1);

                Array.Sort(cand);

                ans_tate_yoko = cand[2] - cand[0];
            }

            if (W % 3 == 1) {
                cand[0] = (H / 2) * (W - W / 3);
                cand[1] = (H - H / 2) * (W - W / 3);
                cand[2] = H * (W / 3);

                Array.Sort(cand);

                ans_yoko_tate = cand[2] - cand[0];
            } else if (W % 3 == 2) {
                cand[0] = (H / 2) * (W - W / 3 - 1);
                cand[1] = (H - H / 2) * (W - W / 3 - 1);
                cand[2] = H * (W / 3 + 1);

                Array.Sort(cand);

                ans_yoko_tate = cand[2] - cand[0];
            }


            Console.WriteLine(Math.Min(Math.Min(Math.Min(ans_tate_yoko, ans_yoko_tate), ans_tate_tate), ans_yoko_yoko));
        }
    }
}


Measured memory_bytes: 13396
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
#define MAX 20000
 
typedef struct {
  int data[MAX+2];
  int head, tail;
} Stack;
 
void init(Stack *st) {
  st->head = st->tail = 0;
}
 
void push(Stack *st, int x) {
  if(st->tail == MAX+2) return;
  st->data[(st->tail)++] = x;
}
 
int pop(Stack *st) {
  return st->data[--(st->tail)];
}
 
int empty(Stack *st) {
  return st->head == st->tail;
}
 
int size(Stack *st) {
  return st->tail - st->head;
}
 
int main() {
  char buf[MAX+2];
  int len, ans = 0;  
  Stack st1, st2, st3, st4;
  int cnt = 0;
  int i, j;
   
  scanf("%s", buf);
  len = strlen(buf);
 
  init(&st1);
  init(&st2);
  init(&st3);
  init(&st4);
   
  for(i = 0; i < len; i++) {
    if(buf[i] == '\\') {
      push(&st1, i);
    } else if(buf[i] == '/') {
      if(size(&st1) > 0) {
    int sum = 0;
    j = pop(&st1);
    ans += i - j;
    sum += i - j;
    while(size(&st2) > 0) {
      int top2 = pop(&st2), top3 = pop(&st3);
      if(top2 < j) {
        push(&st2, top2);
        push(&st3, top3);
        break;
      }
      sum += top3;
    }
    push(&st2, j);
    push(&st3, sum);
      }
    }
  }
  while(size(&st3) > 0) {
    push(&st4, pop(&st3));
    cnt++;
  }
  printf("%d\n%d", ans, cnt);    
  for(i = 0; i < cnt; i++) {
    printf(" %d", pop(&st4));
  }
  puts("");
   
  return 0;
}

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

int main(){
    int N;
    cin>>N;
    string s;
    cin>>s;
    string ans="No";
    if(s.length()%2==0){
        bool flag=false;
        for(int i=0;i<N/2;i++){
            if(s[i]!=s[i+N/2]){
                flag=true;
                break;
            }
        }
        if(!flag)ans="Yes";
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
/**
 * C - 一次元リバーシ / 1D Reversi
 * https://atcoder.jp/contests/abc047/tasks/arc063_a
 **/
#include<iostream>
#include<string>

using namespace std;

int main() {
    string S; cin >> S;
    int ans = 0;
    char target = S[0];
    for(int i=1; i<S.length(); i++) {
        if(target!=S[i]) {
            target = S[i];
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
    string S, T;
    cin >> S >> T;
    bool check = false;
    if (T.length() - S.length() == 1) {
        check = true;
        for (int i = 0; i < S.length(); i++) {
            if (T[i] != S[i]) {
                check = false;
            }
        }
    }
    if (check) {
        cout << "Yes";
    }
    else {
        cout << "No";
    }
}

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

using namespace std;

int main() {
	int N, M,ansa=0,ansb=0;
	cin >> N >> M;
	vector<int> P(M),AC(N,0),WA(N,0);
	vector<string> S(M);
	for (size_t i = 0; i < M; i++)
	{
		cin >> P.at(i) >> S.at(i);
		if (S.at(i)=="WA"&&AC.at(P.at(i)-1)==0)
		{
			WA.at(P.at(i)-1)++;
		}
		else
		{
			AC.at(P.at(i)-1)=1;
		}
	}
	for (size_t i = 0; i < N; i++)
	{
		if (AC.at(i))
		{
			ansa++;
			ansb += WA.at(i);
		}
	}
	cout << ansa << endl << ansb;

}

Measured memory_bytes: 6912
#include<algorithm>
#include<iostream>
#include<stdio.h>
#include<iostream>
#include<stdio.h>
#include<vector>
#include<set>
#include<string>
#include<iomanip>
#include<queue>
#include<functional>
#include<cmath>
#include<map>
#include<tuple>
#define rep(i,n) for(int i=0; i<(int)n; i++)//n回繰り返す
#define rrep(i,n)for(int i=n-1;i>=0;i--)
#define REP(i,n) for (int i = 1; i <= (int)n; i++)//i=1からi=nまで
#define RREP(i,n)for(int i=n;i>=1;i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using graph = vector<vector<int>>;
const ll mod = pow(10, 9) + 7;
const int INF = 1e9;
const ll LINF = 1e18;
const double pi = 3.14159265358979323846;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
    string s, t; cin >> s >> t;
    int ans = 0;
    rep(i, s.size()) {
        if (s[i] != t[i]) {
            ans++;

        }
    }
    cout << ans << endl;
}


    





















Measured memory_bytes: 3856
#include <iostream>
#include <cstdio>
#include <cmath>
#define ll long long

ll a,b,c,k;

int main(){
	std::cin>>a>>b>>c>>k;
	if(abs(a-b)>1e18){
		puts("Unfair");
		return 0;
	}
	if(k&1){
		std::cout<<b-a;
	}else{
		std::cout<<a-b;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <tuple>
#include <stdio.h>
#include <bitset>
#include <limits.h>
#include <complex>
#include <deque>
#include <iomanip>
using namespace std;
#define pi pair<int32,int32>
#define pl pair<int64,int64>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define en cout << endl //セミコロンつけろ
//#define MM 1000000000
//#define MOD MM+7
const int MM = 1e9;
const int MOD = MM+7;
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
// 'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122
template<typename T>
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
template<typename T>
T LCM(T x,T y){
    T gc = GCD(x,y);
    return x*y/gc;
}

long long pow_mod(long long n,long long k,long long m){
    if (k == 0){
        return 1;
    } else if (k % 2 == 1){
        return pow_mod(n,k-1,m)*n % m;
    } else {
        long long t = pow_mod(n,k/2,m);
        return t*t % m;
    }
}

const int COM_MAX = 500500;
long long fac[COM_MAX],finv[COM_MAX],inv[COM_MAX];
void init(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < COM_MAX; i++){
        fac[i] = fac[i-1]*i%MOD;
        inv[i] = MOD - inv[MOD%i]*(MOD/i)%MOD;
        finv[i] = finv[i-1]*inv[i]%MOD;
    }
}
long long COM(int n,int k){
    if(n < k || n < 0 || k < 0) return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}

int par[100010],dep[100010];
void init(int N){
    for(int i = 0; i < N; i++){
        par[i] = i;
        dep[i] = 0;
    }
}

int find(int x){
    if (x == par[x]) return x;
    return par[x] = find(par[x]);
}

void merge(int a,int b){
    a = find(a);
    b = find(b);
    if (dep[a] > dep[b]){
        par[b] = a;
        dep[a] += b;
    } else {
        par[a] = b;
        dep[b] += a;
    }
}

pair<int,int> mx_semx(map<int,int> mp){
    int mx = 0,se_mx = 0,mx_in = 0,se_mx_in = 0;
    for(int i = 0; i < 100001; i++){
        if (mp[i] > mx){
            se_mx = mx;
            mx = mp[i];
            se_mx_in = mx_in;
            mx_in = i;
        } else if (se_mx < mp[i]){
            se_mx = mp[i];
            se_mx_in = i;
        }
    }
    pair<int,int> p = make_pair(mx_in,se_mx_in);

    return p;
}



int main(){
    int N; cin >> N;
    int v[N];
    map<int,int> mp1,mp2;
    for(int i = 0; i < N; i++){
        cin >> v[i];
        if (i % 2 == 0) mp1[v[i]]++;
        else mp2[v[i]]++;
    }
    int ans = 0;
    pair<int,int> fi = mx_semx(mp1),se = mx_semx(mp2);
    if (fi.first != se.first){
        ans = N - mp1[fi.first] - mp2[se.first];
    } else {
        int tmp = N - mp1[fi.second] - mp2[se.first];
        int tmp2 = N - mp1[fi.first] - mp2[se.second];
        ans = min(tmp,tmp2);
    }
    cout << ans << endl;
}


Measured memory_bytes: 9984
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
using namespace std;

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007

struct BIT {
  int n;
  vector<int> xs;
  BIT (int n) : n(n) {
    xs.resize(n+1);
  }
  void add(int i, int v) {
    for (int x=i+1; x<=n; x+=x&-x) xs[x] += v;
  }
  int sum(int i) {
    int s = 0;
    for (int x=i+1; x>0; x-=x&-x) s += xs[x];
    return s;
  }
  int sum(int a, int b) {
    return sum(b) - sum(a-1);
  }
};


int H, W, N;
int X1[100000], Y1[100000], X2[100000], Y2[100000];

P mp(int a, int b) {
  if (a > b) swap(a, b);
  return P(a, b);
}
bool edge(int x, int y) {
  return (x == 0 || x == W) || (y == 0 || y == H);
}
int g(int x, int y) {
  if (y == 0) return x;
  if (x == W) return W+y;
  if (y == H) return W+H+W-x;
  if (x == 0) return W+H+W+H-y;
  return -1;
}
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> H >> W >> N;
  int R = 1;
  vector<int> xs;
  vector<P> G;
  rep(i, N) {
    cin >> Y1[i] >> X1[i] >> Y2[i] >> X2[i];
    if (edge(X1[i], Y1[i]) && edge(X2[i], Y2[i])) {
      int a = g(X1[i], Y1[i]), b = g(X2[i], Y2[i]);
      xs.pb(a);
      xs.pb(b);
      G.pb(mp(a, b));
    }
  }
  sort(all(xs));
  uniq(xs);
  BIT bit(xs.size()+1);
  rep(i, G.size()) {
    int l = G[i]._1, r = G[i]._2;
    int cl = lower_bound(all(xs), l) - xs.begin();
    int cr = lower_bound(all(xs), r) - xs.begin();
    G[i] = P(cr, cl);
  }
  sort(all(G));
  rep(i, G.size()) {
    int l = G[i]._2, r = G[i]._1;
    if (bit.sum(l) > 0) {
      cout << "NO\n";
      return 0;
    }
    bit.add(l, 1);
    bit.add(r, -1);
  }
  cout<<"YES\n";
  return 0;
}


Measured memory_bytes: 4332
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;

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

const ll INF = 1e18;
const int MOD = 1e9 + 7;

// 4近傍、8近傍
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main() {
  // 入力
  int N;
  cin >> N;
  ll a[N];
  for (int i = 0; i < N; i++) cin >> a[i];

  // 累積和
  for (int i = 1; i < N; i++) a[i] += a[i-1];

  ll ans = INF;
  for (int i = 0; i < N - 1; i++) {
    ans = min(ans, llabs(a[i] - (a[N-1] - a[i])));
  }

  // 解答
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define ll long long
#define M 1000000007
#define sz(a) (ll)a.size()
#define pll pair<ll,ll>
#define rep(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define sep(i,a,b) for(ll i=(ll)a;i>=(ll)b;i--)
#define mll map<ll,ll>
#define vl vector<ll>
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(a) a.begin(),a.end()
#define F first
#define S second
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
ll n,t,dp[3005][3005];
pll a[3005];
ll f(ll i,ll r)
{
    if(i==n or r==0)
        return 0;
    if(dp[i][r]!=-1)
        return dp[i][r];
    dp[i][r]=max(f(i+1,r),a[i].S+f(i+1,max(0LL,r-a[i].F)));
    return dp[i][r];
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    memset(dp,-1,sizeof(dp));
    cin>>n>>t;
    rep(i,0,n)
        cin>>a[i].F>>a[i].S;
    sort(a,a+n);
    cout<<f(0,t);
}


Measured memory_bytes: 71040
s=input()
cnt1=0
cnt2=0
for i in range(len(s)):
    if i%2==1 and s[i]=='0':
        cnt1+=1
    elif i%2==0 and s[i]=='1':
        cnt1+=1
    if i%2==0 and s[i]=='0':
        cnt2+=1
    elif i%2==1 and s[i]=='1':
        cnt2+=1
print(min(cnt1,cnt2))


Measured memory_bytes: 3188
n = [0,0,0,0,0,0,0,0,0,0]

for i in range( 0, 10 ):
    n[i] = int(input())

mv = 0
ma = 0

for i in range( 0, 3 ):
    for j in range( 0, 10 ):
        if mv < n[j]:
            mv = n[j]
            ma = j
    print( mv )
    n[ma] = -1
    mv = 0

Measured memory_bytes: 7632
#include <bits/stdc++.h>
using namespace std;
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define in(x,y,h,w) x >= 0 && x < h && y >= 0 && y < w

#define int long long
//using ll = long long;
using P = pair<int,int>;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;

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

signed main(){
	int n,a,b;
	cin >> n >> a >> b;
	cout << min(a,b) << " " << max(0ll,a + b - n) << endl;
}

Measured memory_bytes: 256
N, A, B, K = map(int, input().split())
mod = 998244353

# 階乗 & 逆元計算
factorial = [1]
inverse = [1]
for i in range(1, N+2):
    factorial.append(factorial[-1] * i % mod)
    inverse.append(pow(factorial[-1], mod-2, mod))


# 組み合わせ計算
def nCr(n, r):
    if n < r or r < 0:
        return 0
    elif r == 0:
        return 1
    return factorial[n] * inverse[r] * inverse[n - r] % mod


ans = 0
for x in range(N+1):
    y = (K-A*x) / B
    if y == int(y):
        ans += nCr(N, x) * nCr(N, int(y)) % mod

print(ans % mod)


Measured memory_bytes: 79472
#include <stdio.h>

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

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

  for(i=0;i<N;i++)
    {
     minj = i;
     for(j=i;j<N;j++)
       {
         if(A[j] < A[minj]) minj = j;
       }
         if(minj != i)
         {
              n = A[i];
              A[i] = A[minj];
              A[minj] = n;
              swap++;
         }
    }

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



Measured memory_bytes: 2108
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll max(ll a,ll b){
    if(a>b)return a;
    else return b;
}
int main(void){
    int N;cin>>N;
    vector<vector<ll>>V(N,vector<ll>(3));
    ll high=0;
    for(int i=0;i<N;i++){cin>>V[i][0]>>V[i][1]>>V[i][2];high=max(high,V[i][2]);}
    ll x,y,z;
    bool ans=false;
    for(int i=0;i<101;i++){
        for(int j=0;j<101;j++){
            for(ll h=high;h<high+101;h++){
                for(int k=0;k<N;k++){
                    x=V[k][0];y=V[k][1];z=V[k][2];
                    if(z!=max(h-abs(i-x)-abs(j-y),0))break;
                    else if(k==N-1){
                        ans=true;
                        x=i;y=j;z=h;
                    }
                }
                if(ans)break;
            }
            if(ans)break;
        }
        if(ans)break;
    }
    cout<<x<<' '<<y<<' '<<z<<endl;
}

Measured memory_bytes: 256
s = input()
n = 3
t=[]
for i in range(1<<n):
    ans = int(s[0])
    k=1
    for j in range(n):
        if 1&(i>>j):
            ans += int(s[k:(j+2)])
            t.append("+")
        else: 
            ans -= int(s[k:(j+2)]) 
            t.append("-")
        k=j+2
    if ans==7:
        print(s[0]+t[0]+s[1]+t[1]+s[2]+t[2]+s[3]+"=7")
        break;
    ans = int(s[0])
    t=[]

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n) ;i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b){ a = b; return 1; } return 0; }



int main(int argc, char const *argv[]) {
  int n; cin >> n;
  vector<int> mp(n,0);
  rep(i,n-1){
    int a; cin >> a;
    a--;
    mp[a]++;
  }
  rep(i,n) cout << mp[i] << endl;
  return 0;
}


Measured memory_bytes: 4048
"海岸縁"
while True:
    T, D, L = map(int, input().split())
    if T == 0:
        break
    ans = 0
    wet = False
    desserttime = 0
    for i in range(T):
        if wet:
            ans += 1
        x = int(input())
        if x >= L:
            desserttime = D
        elif desserttime > 0:
            desserttime -= 1

        if desserttime == 0:
            wet = False
        else:
            wet = True

    print(ans)



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

int main(){

  int n;
  int a[300][300];
  int b[300];
  int ans[300] = {};

  cin >> n;

  for(int i=0;i<n;i++)  cin >> a[i][0] >> a[i][1] >> a[i][2];

  for(int l=0;l<3;l++){
    memset(b,0,sizeof(b));

    for(int i=0;i<n;i++){
      for(int j=0;j<i;j++){
	if(a[i][l] == a[j][l]){
	  b[i] = 1;
	  b[j] = 1;
	}
      }
    }

    for(int i=0;i<n;i++){
      if(b[i] == 0) ans[i] += a[i][l];
    }

  }

  for(int i=0;i<n;i++) cout << ans[i] << endl;

}

Measured memory_bytes: 1392
INF=10**9+7
n=int(input())
A=list(map(int,input().split()))
S=[sum(A)]
ans=0
for i in range(len(A)):
    key=S[-1]
    S.append(key-A[i])
    ans+=(A[i]*S[-1])
    
print(ans%INF)

Measured memory_bytes: 31424
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby
    #from itertools import product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    n,k = map(int, input().split())
    a = list(map(int, input().split()))

    #ibit目が0である数と1である数
    zero, one = [0]*40, [0]*40

    for i in range(n):
        for bit in range(40):
            if (a[i]>>bit) & 1:
                one[bit] += 1
            else:
                zero[bit] += 1
    #貪欲な方
    res1 = 0
    #貪欲じゃない方
    res2 = 0
    flag = 0
    for i in range(39, -1, -1):
        if flag == 0:
            if (k>>i) & 1:
                res1 += 2**i * one[i]
                res2 += 2**i * zero[i]
                flag = 1
            else:
                res1 += 2**i * one[i]
                res2 += 2**i * one[i]
        else:
            if (k>>i) & 1:
                res1 = max(res1 + 2**i * max(one[i], zero[i]), res2 + 2**i * one[i])
                res2 += 2**i * zero[i]
            else:
                res1 += 2**i * max(one[i], zero[i])
                res2 += 2**i * one[i]
    print(max(res1, res2))

if __name__ == '__main__':
    main()

Measured memory_bytes: 63192
from fractions import gcd
n = int(input())
lcm = list(map(int, input().split()))
ans = [1] * n
while len(lcm) < (1 << 14):
  lcm.append(1)
  ans.append(0)
for i in range(13, -1, -1):
  bit = 1 << i
  for j in range(bit):
    new = lcm[j] // gcd(lcm[j], lcm[j | bit]) * lcm[j | bit]
    ans[j] = new // lcm[j] * ans[j] + new // lcm[j | bit] * ans[j | bit]
    lcm[j] = new
print(ans[0] % 1000000007)
    
  


Measured memory_bytes: 6368
#include <bits/stdc++.h>
  
using namespace std;
 
#define endl "\n"
 
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef pair<int,int> PII;
typedef vector<PII> VPI;
 
const int INF=2e9;
const int MX=100005;
const int MOD=1000000007;

long long int power(long long int a,long long int b)
{
    a %= MOD;
    long long int res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % MOD;
        a = a * a % MOD;
        b >>= 1;
    }
    return res;
}
bool isprime(int n)
{
    if(n==1)
    return 0;
    int i;
    for(i=2;i*i<=n;i++)
    {
        if(n%i==0)
        return false;
    }
    return true;
}


//vector<int> sieve(100001);
// void SIEVE()
// {
//     int i,j;
//     for(i=0;i<=100000;i++)
//     sieve[i]=i;
//     for(i=2;i*i<=100000;i++)
//     {
//         if(sieve[i]!=i)
//         continue;
//         for(j=i*i;j<=100000;j=j+i)
//         {
//             if(sieve[j]==j)
//             sieve[j]=i;
//         }
//     }
// }


/*_______________________________________________*/
vector<vector<int>> graph;
vector<int> vis;
void dfs(int i)
{
    if(vis[i])
    return ;
    vis[i]=1;
    for(auto j: graph[i])
    {
        if(!vis[j])
        dfs(j);
    }
    return ;
}



int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,m,i;
    cin>>n>>m;
    graph.resize(n+1);
    vis.resize(n+1);
    for(i=0;i<m;i++)
    {
        int x,y;
        cin>>x>>y;
        graph[x].push_back(y);
        graph[y].push_back(x);
    }
    int ans=0;
    dfs(1);
    for(i=1;i<=n;i++)
    {
        if(vis[i]==0)
        {
            ans++;
            dfs(i);
        }
    }
    cout<<ans;
}


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

int main(){
    int n;
    while(cin>>n,n){
        vector<int> a;
        for(int i=0,t;i<n;++i){
            cin>>t;
            a.push_back(t);
        }
        string s,ans;
        cin>>s;

        string alpha;
        map<char, int> alphaM;
        int id = 0;
        for(char c = 'a'; c <= 'z'; c++) {
            alpha.push_back(c);
            alphaM[c] = id++;
        }
        for(char c = 'A'; c <= 'Z'; c++) {
            alpha.push_back(c);
            alphaM[c] = id++;
        }


        for(int i=0;i<s.size();++i){
            int x=a[i%a.size()];
            int id2 = alphaM[s[i]];
            ans += alpha[(id2-x+52)%52];
        }
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 1228
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split("\n");
//	tmp = input[1].split(" ");
	//文字列から10進数に変換するときはparseIntを使います
	var n = parseInt(input[0], 10);
    
    var  total = 0;
    for(i=1;i<=n;i++){
    var tmp = input[i].split(" ");
    var a =　Number(tmp[0], 10);
    var b = tmp[1];
//      console.log(tmp[0],tmp[1],a,b);
    if (b=='BTC'){total = total +a*380000.0;}
    else{total = total +a}
    }
	console.log(total);
    
	
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
# read https://img.atcoder.jp/abc172/editorial.pdf

class Modulo
  attr_accessor :num, :mod

  def initialize(mod, init = 0)
    @mod = mod
    @num = init % @mod
    @com_init_max = 0
  end

  def com(n, k, max = nil)
    max = n if max.nil?
    com_init(max) if @com_init_max < max
    return 0 if n < k
    return 0 if n < 0 || k < 0
    @fac[n] * (@finv[k] * @finv[n - k] % @mod) % @mod
  end

  def to_s
    @num.to_s
  end

  def to_i
    @num.to_i
  end

  private

  def com_init(max)
    @com_init_max = max
    @fac = [0] * (max + 1)
    @finv = [0] * (max + 1)
    inv = [0] * (max + 1)
    @fac[0] = 1
    @fac[1] = 1
    @finv[0] = 1
    @finv[1] = 1
    inv[1] = 1;
    2.upto(max) do |i|
      @fac[i] = (@fac[i - 1] * i) % @mod
      inv[i] = @mod - inv[@mod % i] * (@mod / i) % @mod
      @finv[i] = @finv[i - 1] * inv[i] % @mod
    end
  end
end


MOD  = 10** 9 + 7

N, M = gets.chomp.split.map(&:to_i)

ans = 0
nCk = 1
sign = -1
mPk = 1
m_kPn_k_list = [1]
1.upto(N) do |k|
  m_kPn_k_list << (m_kPn_k_list[-1] * (M - N + k) ) % MOD 
end
m_kPn_k_list.reverse!

modulo = Modulo.new(MOD)

0.upto(N) do |k|
  nCk = modulo.com(N, k, N)
  sign *= -1
  mPk = (mPk * (M + 1 - k)) % MOD if k > 0
  m_kPn_k = m_kPn_k_list[k]
  ans = (ans + (nCk % MOD) * sign * mPk * ((m_kPn_k % MOD)**2)) % MOD
end

puts ans


Measured memory_bytes: 30036
#include <iostream>
#include <cmath>
#include <vector>

int main()
{
    int H;
    int N;
    std::cin >> H >> N;

    std::vector<int> A(N, 0);
    for(int i=0; i<N; ++i)
        std::cin >> A[i];

    for(int i=0; i<N; ++i)
        H -= A[i];

    if(H<=0)
        std::cout << "Yes" << std::endl;
    else
        std::cout << "No" << std::endl;

    return 0;
}


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

int number[100005];

int main() {
    int N, K, A;
    cin >> N >> K;
    for (int i = 0; i < N; i++) number[i] = 0;
    for (int i = 0; i < N; i++) {
        cin >> A;
        number[A]++;
    }
    for (int i = 0; i < 100005; i++) {
        if (number[i] != 0) {
            N -= number[i];
            break;
        }
    }
    int min_count = N / (K - 1) + (N % (K - 1) == 0 ? 0 : 1);
    cout << min_count << endl;
    return 0;
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String s = scan.next();
		scan.close();
		for(int i=0;i<s.length();i++) {
			System.out.print("x");
		}
		System.out.println();

	}
}

Measured memory_bytes: 22608
import sys
input = sys.stdin.readline
n = int(input())
a = [0]*n
b = [0]*n
c = [0]*n
for i in range(n):
    a[i],b[i],c[i] = map(int,input().split())

dpa = [a[0]]+[0]*(n-1)
dpb = [b[0]]+[0]*(n-1)
dpc = [c[0]]+[0]*(n-1)
for i in range(1,n):
    dpa[i] = max(dpb[i-1],dpc[i-1]) + a[i]
    dpb[i] = max(dpc[i-1],dpa[i-1]) + b[i]
    dpc[i] = max(dpa[i-1],dpb[i-1]) + c[i]
print(max(dpa[-1],dpb[-1],dpc[-1]))


Measured memory_bytes: 48732