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

#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

int time_stamp;
int M[N+1][N+1];

void dfs(int n, int vertex, int d[], int f[], int color[]) {  
  color[vertex] = GRAY;
  d[vertex] = ++time_stamp;
  for (int i = 1; i <= n; i++) {    
    if (M[vertex][i] && color[i] == WHITE) {
      dfs(n, i, d, f, color);
    }
  }
  color[vertex] = BLACK;
  f[vertex] = ++time_stamp;
}

void search(int n, int d[], int f[], int color[]) {
  // 初期状態
  for (int i = 1; i <= n; i++) color[i] = WHITE;
  time_stamp = 0;
  // dfs
  for (int i = 1; i <= n; i++) {
    if (color[i] == WHITE) {
      dfs(n, i, d, f, color);
    }
  }
}

int main() {
  int i, j, n, u, k, v, d[N+1], f[N+1], color[N+1];
  
  cin >> n;
  // 隣接行列を取得
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= n; j++) {
      M[i][j] = 0;
    }
  }
  for (i = 0; i < n; i++) {
    cin >> u >> k;
    for (j = 0; j < k; j++) {
      cin >> v;
      M[u][v] = 1;
    }
  }

  search(n, d, f, color);

  for (i = 1; i <= n; i++) cout << i << " " << d[i] << " " << f[i] << endl;    

  return 0;
}



Measured memory_bytes: 3108
#include<iostream>
#include<algorithm>
using namespace std;
/*
	1.left可以取到，right取不到
	2.大于key时  为midle+1-right
	3.小于key时  为left - midle
*/
int a[100000];
int binary_search(int left, int right, int key) {
	if (left >= right) return 0;
	int midle = (left + right) / 2;
	if (a[midle] == key) return 1;
	if (a[midle] > key) return binary_search(left, midle, key);
	else return binary_search(midle + 1, right, key);
}
int main(void) {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	int m;
	cin >> m;
	int all = 0;
	for (int i = 0; i < m; i++) {
		int key;
		cin >> key;
		//if (binary_search(0, n, key))all++;
		int* m = lower_bound(a, a + n, key);
		if (*m == key) all++;
	}
	cout << all << endl;
	return 0;

}


Measured memory_bytes: 3424
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
	string s;
	ll k;
	cin >> s >> k;
	int n = s.size();
	for (int i = 0; i < n; i++) {
		if (s[i] != '1') {
			cout << s[i] << endl;
			return 0;
		}
		else {
			if (i + 1 == k) {
				cout << s[i] << endl;
				return 0;
			}
		}
	}
	cout << s[n - 1] << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
using ll = long long;
using graph = std::vector<std::vector<ll>>;

using namespace std;
ll memo[101][2][4]; //桁、未満、0以外の数
void init(){
    for (int yi = 0; yi < 101; ++yi) {
        for (int xi = 0; xi < 2; ++xi) {
            for (int zi = 0; zi < 4; ++zi) {
                memo[yi][xi][zi] = 0;
            }
        }
    }
}
vector<int> genDigit(string x){
    vector<int> result = vector<int>(101);
    for (int i = 0; i < 101; ++i) {
        result[i] = 0;
    }
    for(int i = 0; i < x.size(); i++){
        result[i] = x[x.size() - i - 1] -'0';
    }
    return result;
}

int main() {
    string N;
    cin >> N;
    ll K;
    cin >> K;
    init();
    auto dig = genDigit(N);
    memo[0][0][0] = 1;
    for(int i = 1; i < 101; i++){
        if(dig[101 - i - 1] == 0){
            for (int j = 0; j < 4; ++j) {
                memo[i][0][j] = memo[i-1][0][j];
                if(memo[i][0][0] != 0){
                    //continue;
                }
                if(j == 0){
                    memo[i][1][j] = memo[i-1][1][j];
                }else{
                    memo[i][1][j] = memo[i-1][1][j] + memo[i-1][1][j - 1] * 9;
                }
            }
        }else{
            for (int j = 0; j < 4; ++j) {
                if(j == 0){
                    memo[i][0][0] = 0;
                }else{
                    memo[i][0][j] = memo[i-1][0][j - 1];
                }
                if(j == 0){
                    memo[i][1][j] = memo[i-1][1][j] + memo[i-1][0][j];
                }else{
                    memo[i][1][j] = memo[i-1][1][j] + memo[i-1][0][j] + memo[i-1][1][j - 1] * (9) + memo[i-1][0][j-1] * (dig[101 - i - 1] - 1);
                }
            }
        }
    }
    cout << memo[100][0][K] + memo[100][1][K] << endl;


}


Measured memory_bytes: 256
x = int(input())

def isPrime(n):
  if n%2 == 0 or n%3 == 0: return True
  if n<3: return False
  for i in range( 2, int(n**0.5) +1):
    if n%i == 0: return False
  return True

primes = [i for i in range(1, 32) if isPrime(i)]

def isExp(n):
  if n==1: return True
  for i in [p for p in primes if p<int(n**0.5)+1]:
    p = 0
    while i**p<=n:
      if i**p == n: return True
      p+=1
  return False

def solve():
  for i in range(x,0,-1):
    if isExp(i): return i

print(solve())

Measured memory_bytes: 3064
import sys
from collections import deque
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    SA = readline().decode('utf-8').strip()
    SB = readline().decode('utf-8').strip()
    SC = readline().decode('utf-8')
    A = deque(SA)
    B = deque(SB)
    C = deque(SC)
    next = A.popleft()
    while True:
        if next=='a':
            if not A:
                print('A')
                break
            next = A.popleft()
        elif next=='b':
            if not B:
                print('B')
                break
            next = B.popleft()
        else:
            if not C:
                print('C')
                break
            next = C.popleft()



if __name__ == '__main__':
    main()

Measured memory_bytes: 3316
import sys
input = sys.stdin.readline
import numpy as np
from heapq import heappush, heappop

N = int(input())
A = np.array(input().split(), dtype=np.int32)
a_to_i = {a:i for i,a in enumerate(A)}

# sparse table を使ってRMQ
# parityの同じところだけを見るようにしておく

U = len(A).bit_length()
sp = [None,A]
for i in range(2,U):
    L = 1 << (i-1)
    sp.append(np.minimum(sp[-1][:-L], sp[-1][L:]))

def RMQ(x,y):
    if (y-x)&1: 
        y -= 1
    # x番目から偶数番目だけ見て[x,y]での最小値を返す
    d = y - x
    if d <= 1:
        return A[x]
    n = d.bit_length()
    return min(sp[n-1][x], sp[n-1][y+2-(1<<(n-1))])

def F(x,y):
    # 辞書式で最小の2つ組をとる
    # そのあと、今後調べないといけない区間の一覧を返す
    x1 = RMQ(x,y)
    i1 = a_to_i[x1]
    x2 = RMQ(i1+1,y)
    i2 = a_to_i[x2]
    task = ((x,y) for x,y in ((x,i1-1), (i1+1,i2-1), (i2+1,y)) if y > x)
    return x1,x2,task

q = [(None,None,((0,N-1),))]
answer = []
while q:
    x,y,task = heappop(q)
    if x != None:
        answer.append(x)
        answer.append(y)
    for left,right in task:
        heappush(q,F(left,right))

print(' '.join(map(str,answer)))

Measured memory_bytes: 108464
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define pii pair<int, int>
#define ff first
#define ss second
#define PI acos(-1)
#define ld long double
const int mod = 1e9+7, N = 2e5+5;

int a[N], n;

void solve(int test_case){
	int i, j;
	cin >> n;
	map<string, int> m;
	for(i=0;i<n;i++){
		string s;
		cin >> s;
		m[s]++;
	}
	cout << "AC x " << m["AC"] << '\n';
	cout << "WA x " << m["WA"] << '\n';
	cout << "TLE x " << m["TLE"] << '\n';
	cout << "RE x " << m["RE"] << '\n';
	return;
}

signed main(){
	FASTIO;
#define MULTITEST 0
#if MULTITEST
	int ___T;
	cin >> ___T;
	for(int T_CASE = 1; T_CASE <= ___T; T_CASE++)
		solve(T_CASE);
#else
	solve(1);
#endif
	return 0;
}


Measured memory_bytes: 3664
import java.io.InputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.InputMismatchException;
import java.util.NoSuchElementException;
import java.math.BigInteger;

public class Main{

static PrintWriter out;
static InputReader ir;

static void solve(){
 for(int t=0;;t++){
  final int[] v=new int[]{10,50,100,500};
  int n=ir.nextInt();
  if(n==0) return;
  int[] a=ir.nextIntArray(4);
  int[] r=new int[4];
  int tot=0;
  for(int i=3;i>=0;i--){
   tot+=a[i]*v[i];
  }
  tot-=n;
  for(int i=3;i>=0;i--){
   r[i]=tot/v[i];
   tot-=v[i]*r[i];
  }
  if(t!=0) out.println();
  for(int i=0;i<4;i++){
   if(a[i]>r[i]) out.println(v[i]+" "+(a[i]-r[i]));
  }
 }
}

public static void main(String[] args) throws Exception{
 ir=new InputReader(System.in);
 out=new PrintWriter(System.out);
 solve();
 out.flush();
}

static class InputReader {
 private InputStream in;
 private byte[] buffer=new byte[1024];
 private int curbuf;
 private int lenbuf;

 public InputReader(InputStream in) {this.in=in; this.curbuf=this.lenbuf=0;}
 
 public boolean hasNextByte() {
  if(curbuf>=lenbuf){
   curbuf= 0;
   try{
    lenbuf=in.read(buffer);
   }catch(IOException e) {
    throw new InputMismatchException();
   }
   if(lenbuf<=0) return false;
  }
  return true;
 }

 private int readByte(){if(hasNextByte()) return buffer[curbuf++]; else return -1;}
 
 private boolean isSpaceChar(int c){return !(c>=33&&c<=126);}
 
 private void skip(){while(hasNextByte()&&isSpaceChar(buffer[curbuf])) curbuf++;}
 
 public boolean hasNext(){skip(); return hasNextByte();}
 
 public String next(){
  if(!hasNext()) throw new NoSuchElementException();
  StringBuilder sb=new StringBuilder();
  int b=readByte();
  while(!isSpaceChar(b)){
   sb.appendCodePoint(b);
   b=readByte();
  }
  return sb.toString();
 }
 
 public int nextInt() {
  if(!hasNext()) throw new NoSuchElementException();
  int c=readByte();
  while (isSpaceChar(c)) c=readByte();
  boolean minus=false;
  if (c=='-') {
   minus=true;
   c=readByte();
  }
  int res=0;
  do{
   if(c<'0'||c>'9') throw new InputMismatchException();
   res=res*10+c-'0';
   c=readByte();
  }while(!isSpaceChar(c));
  return (minus)?-res:res;
 }
 
 public long nextLong() {
  if(!hasNext()) throw new NoSuchElementException();
  int c=readByte();
  while (isSpaceChar(c)) c=readByte();
  boolean minus=false;
  if (c=='-') {
   minus=true;
   c=readByte();
  }
  long res = 0;
  do{
   if(c<'0'||c>'9') throw new InputMismatchException();
   res=res*10+c-'0';
   c=readByte();
  }while(!isSpaceChar(c));
  return (minus)?-res:res;
 }

 public double nextDouble(){return Double.parseDouble(next());}

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

 public long[] nextLongArray(int n){
  long[] a=new long[n];
  for(int i=0;i<n;i++) a[i]=nextLong();
  return a;
 }

 public char[][] nextCharMap(int n,int m){
  char[][] map=new char[n][m];
  for(int i=0;i<n;i++) map[i]=next().toCharArray();
  return map;
 }
}
}

Measured memory_bytes: 27260
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val m1 = sc.nextInt()
    val d1 = sc.nextInt()
    val m2 = sc.nextInt()
    val d2 = sc.nextInt()
    println(problemSumitomoMitsuiA(m1, d1, m2, d2))
}

fun problemSumitomoMitsuiA(m1: Int, d1: Int, m2: Int, d2: Int): Int {
    return if (m1 != m2) 1 else 0
}

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

int main(){
    int n; cin >> n;
    char s[n];cin >> s;
    int k;cin >> k;
    char c = s[k-1];
    for(int i=0;i<n;i++){
        if(s[i] == c){

        }
        else{
            s[i] = '*';
        }
    }
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.*
import java.util.*

fun solve(A: Int, B: Int, C: Int, D: Int, E: Int, F: Int) {
    data class SugarWater(val water: Int, val sugar: Int) {
        public val total = water + sugar
        public val isValid = sugar <= water * E / 100 && 0 < total && total <= F
        public val density = if (isValid) sugar.toFloat() * 100 / (water + sugar).toFloat() else 0f
    }
    val sugarMax = F * E / 100
    val ws = (0..F / (A * 100)).asSequence()
        .flatMap { a -> (0..F / (B*100)).asSequence().map { b -> a * 100*A + b * 100*B } }
    val sugars = (0..sugarMax / C).asSequence()
        .flatMap { c -> (0..sugarMax / D).asSequence().map { d -> c*C + d*D } }
    val waterCand = ws.distinct().filter { it <= F }
    val sugarCand = sugars.distinct().filter { it <= sugarMax }
    // println(waterCand.toList().sorted())
    // println(sugarCand.toList().sorted())
    waterCand
        .flatMap { w -> sugarCand.map { s -> SugarWater(w, s) } }
        .filter { it.isValid }
        .maxBy { it.density }?.let { println("${it.total} ${it.sugar}") }
    return
}

fun main(args: Array<String>) {
    fun StringArray(size: Int, init: (Int) -> String = { "\u0000" }): Array<String> {
        return Array<String>(size, init)
    }
    class Scanner(stream: InputStream) {
        private val reader = BufferedInputStream(stream).bufferedReader()
        private var st: StringTokenizer? = null
        fun next(): String {
            while (!(st?.hasMoreTokens() ?: false)) st = StringTokenizer(reader.readLine())
            return st!!.nextToken()
        }
    }
    val sc = Scanner(System.`in`)
    val A = sc.next().toInt()
    val B = sc.next().toInt()
    val C = sc.next().toInt()
    val D = sc.next().toInt()
    val E = sc.next().toInt()
    val F = sc.next().toInt()
    solve(A, B, C, D, E, F)
}


Measured memory_bytes: 64412
#include <iostream>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >
#define endl '\n'

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    int N, K, Q;
    cin >> N >> K >> Q;
    VEC(int) Answers(N + 1, 0);
    FOR(i, 1, Q + 1) {
        int a;
        cin >> a;
        Answers[a]++;
    }

    FOR(i, 1, N + 1) {
        if (K <= (Q - Answers[i]))
            cout << "No";
        else
            cout << "Yes";
        cout << endl;
    }
    return 0;
};

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=100005;
const ll INF=1LL<<60;

int main(){
    
    int N;cin>>N;
    vector<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 mini=INF;
    for(int i=0;i<N-1;i++){
        mini=min(mini,abs(A[i]-(A[N-1]-A[i])));
    }
    
    cout<<mini<<endl;
}



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

#define ALL(obj) (obj).begin(), (obj).end()
#define rep(i,n) for(int i=0; i<n; i++)
#define rep2(i,a,b) for(int i=a; i<=b; i++)
using ll = long long;
#define pb push_back
#define INF 100100100
//const int INF = 100100100;
const int MOD = (int) 1e9 + 7;
const double EPS = 1e-9;

int main()
{
  int N;
  ll  Y;
  cin >> N >> Y;
  rep2(i, 0, N) {
    ll rest_i = Y - 1000 * i;
    rep2(j, 0, N-i) {
      ll rest_j = rest_i - 5000 * j;
      if ( (rest_j % 10000 == 0 ) && (rest_j / 10000 == N-i-j)) {
        cout << N-i-j << " " << j << " " << i << endl;
        return 0;
      }
      
    }
  }
  cout << "-1 -1 -1" << endl;
}
	


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<bitset>
#define BS 4096
using namespace std;
bitset<4096>w[6], X, G, TP;
int n, GL, Mod = 998244353, po[4096];
char p[4096];
void Put(bitset<4096> &TP, char *key) {
	int i, L;
	for (i = 0; key[i]; i++);
	L = i;
	for (i = 0; i < L; i++) {
		TP[L - i - 1] = key[i]-'0';
	}
}
int Len(bitset<4096> &TP) {
	int j;
	for (j = BS - 1; j >= 0; j--) {
		if (G[j])break;
	}
	return j+1;
}
int main() {
	int i, j;
	po[0] = 1;
	for (i = 1; i <= 4000; i++)po[i] = po[i - 1] * 2 % Mod;
	scanf("%d", &n);
	scanf("%s", p);
	Put(X, p);
	for (i = 0; i < n; i++) {
		scanf("%s", p);
		Put(w[i], p);
	}
	G = w[0];
	while (1) {
		int ck = 0;
		for (i = 0; i < n; i++) {
			TP = w[i];
			GL = Len(G);
			for (j = BS - 1; j >= GL - 1; j--) {
				if (TP[j]) {
					TP ^= G << (j + 1 - GL);
				}
			}
			for (j = BS - 1; j >= 0; j--)if (TP[j])break;
			if (j != -1) {
				ck = 1;
				G = TP;
			}
		}
		if (!ck)break;
	}
	GL = Len(G);
	long long res = 0;
	TP.reset();
	for (i = BS - 1; i >= GL - 1; i--) {
		if (X[i]) {
			res = (res + po[i - (GL - 1)]) % Mod;
		}
		if (TP[i] != X[i]) {
			TP ^= G << (i + 1 - GL);
		}
	}
	int ck = 0;
	for (i = BS - 1; i >= 0; i--) {
		if (X[i] != TP[i]) {
			if (TP[i]) ck = 1;
			break;
		}
	}
	res = (res + 1 - ck) % Mod;
	printf("%d\n", res);
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
 
using namespace std;
 
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P > PP;
 
int tx[] = {0,1,0,-1};
int ty[] = {-1,0,1,0};
 
static const double EPS = 1e-8;
 
static const int MAX_N = 1000000;
bool isPrime[MAX_N];
 
class Ticket{
public:
  int mMoney;
  string mNumber;
  Ticket(int _m, string _num){
    mMoney = _m;
    mNumber = _num;
  }
};
 
int main(){
  int n,m;
 
  while(~scanf("%d %d",&n,&m)){
    if(n==0) break;
    vector<Ticket> tickets;
    for(int i=0;i<n;i++){
      string number;
      int money;
      cin >> number >> money;
      tickets.push_back(Ticket(money,number));
    }
 
    int sum = 0;
    for(int i=0;i<m;i++){
      string str;
      cin >> str;       
      int prize = 0;
      for(int j=0;j<tickets.size();j++){       
	bool isok = true;
	for(int k=tickets[j].mNumber.size()-1;k>=0;k--){                 
	  if(tickets[j].mNumber[k] != str[k]
	     && tickets[j].mNumber[k] != '*'){
	    isok = false;
	    break;
	  }
	}
 
	if(isok) prize = max(tickets[j].mMoney,prize);
      }
 
      sum += prize;
    }
 
    printf("%d\n",sum);
  }
}

Measured memory_bytes: 1264
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

class Program
{
    static void Solve()
    {
        var N = ReadLong();
        var caps = new List<long>();
        var takens = new List<long>();

        long ans = 0;

        for (var i = 0; i < 5; i++)
        {
            var cap = ReadLong();
            var taken = N / cap + (N % cap != 0 ? 1 : 0);

            if (i == 0)
            {
                ans += taken;
            }
            else
            {
                ans += (cap < caps.Min()) ? (taken - takens.Max() + 1) : 1;
            }
            caps.Add(cap);
            takens.Add(taken);
        }

        Console.WriteLine(ans);
    }

    static void Main(string[] args)
    {
        var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(sw);
        Solve();
        Console.Out.Flush();
    }

    public static string Read() { return Console.ReadLine(); }
    public static int ReadInt() { return int.Parse(Read()); }
    public static long ReadLong() { return long.Parse(Read()); }
    public static double ReadDouble() { return double.Parse(Read()); }

    public static string[] Reads() { return Console.ReadLine().Split(' '); }
    public static int[] ReadInts() { return Reads().Select(_ => int.Parse(_)).ToArray(); }
    public static long[] ReadLongs() { return Reads().Select(_ => long.Parse(_)).ToArray(); }
    public static double[] ReadDoubles() { return Reads().Select(_ => double.Parse(_)).ToArray(); }
}

Measured memory_bytes: 13268
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int maxN = 1e6 + 5;
const int mod = 1e9 + 7;
ll frac[maxN];
ll inv[maxN];
ll f[maxN];
ll pw(ll a, ll b) {
    ll ans = 1;
    while (b) {
        if (b&1) ans = ans * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return ans;
}
void init() {
    frac[0]= 1;
    inv[0] = 1;
    for (int i = 1; i <= maxN; i++) {
        frac[i] = frac[i-1] * i % mod;
        inv[i] = pw(frac[i], mod-2);
    }
}
ll c(ll m, ll n) {
    if (m < n) return 0;
    if (n == 0) return 1;
    return frac[m] * inv[n] % mod * inv[m-n] % mod;
}
int main() {
    int n;
    cin >> n;
    init();
    f[2] = 1;
    ll ans = 0;
    for (ll i = n/2; i < n; i++) {
        f[i] = c(i-1, n-1-i) * frac[i] % mod * frac[n-1-i] % mod;
        //cout << f[i] << "\n";
        ans = (ans + (f[i] - f[i-1] + mod) % mod * i) % mod;
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 21760
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-11;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int main(){
	while(1){
		string s;
		cin>>s;
		if(s=="#") break;
		int y,m,d;
		cin>>y>>m>>d;
		if(y>31) s="?";
		if(y==31&&m>=5) s="?";
		if(s=="?") y-=30;
		cout<<s<<' '<<y<<' '<<m<<' '<<d<<endl;
	}
}


Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <set>
#include <map>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define ll long long
const long long MOD = 1000000007LL;
int main(){
    int n;
    cin >> n;
    ll a[n];
    rep(i,n){
        cin >> a[i];
    }
    sort(a,a+n);
    ll ans = 0;
    ll tem = 0;
    if(n%2==0){
        rep(i,n/2-1){
            ans = ans + 2*a[n-1-i];
            ans = ans - 2*a[i];
        }
        ans = ans + a[n/2] - a[n/2 - 1];
        cout << ans << endl;
    }
    else{
        rep(i,(n-1)/2){
            ans = ans + 2*a[n-1-i];
            ans = ans - 2*a[i];
        }
        tem = ans + a[(n-1)/2] - a[(n+1)/2];
        ans = ans - a[(n-1)/2] + a[(n-3)/2];
        ans = max(tem,ans);
        cout << ans << endl;
    }
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define F first
#define S second

#define fo(i, n) for(int i = 1; i <= n; ++i)
#define rep(i, a, b) for(int (i) = (a); (i) < (b); ++(i))

typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const int N = 600200;
const int mod = 1e9 + 7;
const ll INF = 1e18;
ll n, a[N], ans;

int main()
{
	ios::sync_with_stdio(0); cin.tie(0);
	cin>>n;
	fo(i,3*n)
		cin>>a[i];
	sort(a+1,a+3*n+1);
	reverse(a+1,a+3*n+1);
	for(int i=2;i<=2*n;i+=2)
		ans+=a[i];
	cout<<ans;
	return 0;	
}

Measured memory_bytes: 4352
#include <iostream>
#include <iomanip>
#include <algorithm>
typedef long long ll;
using namespace std;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
#define repi(i, n, init) for (ll i = init; i < (n); i++)

bool isPrime(int num)
{
    for (int i = 2; i * i <= num; i++)
    {
        if (i * i <= (num + 1) / 2 && (num + 1) / 2 % i == 0)
            return false;
        if (num % i == 0)
            return false;
    }
    return true;
}
int main()
{
    int q;
    cin >> q;
    int sum[int(1e5 + 1)] = {0};
    int l[q], r[q];
    int Ma = 0;
    repi(i, q, 0)
    {
        cin >> l[i] >> r[i];
        Ma = max(Ma, r[i]);
    }
    for (int i = 3; i <= Ma; i += 2)
    {
        if (isPrime(i))
            sum[i]++;
        if (Ma != i)
            sum[i + 2] += sum[i];
    }
    repi(ri, q, 0)
    {
        cout << sum[r[ri]] - sum[max(l[ri] - 2, 1)] << endl;
    }

    return 0;
}

Measured memory_bytes: 1792
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement, groupby
from math import sqrt, factorial, log
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from heapq import heappop, heappush, heappushpop
import sys
stdin = sys.stdin
mod = 10**9 + 7

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

s = ns()

if "A" in s and "B" in s:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3444
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N=I()
    d = defaultdict(int)
    for i in range(1,N+1):
        s = str(i)
        h,t = s[0],s[-1]
        d[h,t]+=1
    ans  = 0  
    for i in range(1,N+1):
        s = str(i)
        h,t = s[0],s[-1]
        ans += d[t,h]
    print(ans)


if __name__ == '__main__':
    main()
    # S=ST()
    # ans = 0
    # for i in range(len(S)):
    #     for it in combinations([i for i in range(len(S))], i):
    #         before = 0
    #         for j in it:
    #             print(int(S[before:j+1]), before,j)
    #             ans += int(S[before:j+1])
    #             before = j+1
    #         try:
    #             ans += int(S[before:])
    #         except:
    #             pass
    #         print(ans)
    # print(ans)

Measured memory_bytes: 69096
#include<iostream>
#include<algorithm>

using namespace std;

int main(){
    int n, i, j, k;
    cin >> n;
    int a[3][n + 1], b[n];
    for (i = 0; i < 2; ++i){
        for (j = 0; j < n; ++j){
            cin >> a[i][j];
            b[j] = 0;
        }
    }
    for (i = 0; i < n; ++i){
        for (k = 0; k <= i; ++k){
            b[i] += a[0][k];
        }
        for (j = i; j < n; ++j){
            b[i] += a[1][j];
        }
    }
    sort(b, b + n);
    cout << b[n - 1] << endl;
    return 0;
}

Measured memory_bytes: 256
n,m,c=map(int,input().split())
b=list(map(int,input().split()))
def sol(x,y,z):
  l=len(y)
  par=0
  for i in range(l):
    par+=x[i]*y[i]
  if(par+z>0):
    return 1
  else:
    return 0

ans=0
for i in range(n):
  a=list(map(int,input().split()))
  ans += sol(a,b,c)
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
using namespace std;
typedef long long ll;

namespace mp = boost::multiprecision;
using Bint = mp::cpp_int;
using Real = mp::number<mp::cpp_dec_float<1024>>;

#define INCANT cin.tie(0), ios::sync_with_stdio(false), cout << fixed << setprecision(20)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
#define all(x) (x).begin(),(x).end()
#define out(a) cout << a << endl
#define PRINT(V) for (auto v : (V)) cout << v << " "

const int MOD = 1000000007;
const double PI = acos(-1.0);

void solve() {
    int K, N;
    cin >> N >> K;
    vector<int> p(N);
    rep(i, N) cin >> p.at(i);
    sort(all(p));
    ll ans=0;
    rep(i, K) ans += p.at(i);
    out(ans);
}
int main() {
    INCANT;
    solve();
    return 0;
}




Measured memory_bytes: 3600
s = input()
n = len(s)
stat = 0
a = 0
bc = 0
abc = 0
ans = 0
def count():
    global ans, a, bc, abc
    newa = a+abc
    cnt = abc
    while cnt>0:
        ans += cnt
        cnt -= 1
        if a>0:
            a -= 1
            cnt += 1
        if bc>0:
            bc -= 1
            cnt += 1
    a = newa
    bc = 0
    abc = 0
i = 0
while i<n:
    if stat==0:
        if s[i:i+3]=='ABC':
            a = 0
            abc = 1
            stat = 2
            i += 3
        elif s[i]=='A':
            a = 1
            stat = 1
            i += 1
        else:
            i += 1
    elif stat==1:
        if s[i:i+3]=='ABC':
            abc = 1
            stat = 2
            i += 3
        elif s[i]=='A':
            a += 1
            i += 1
        else:
            stat = 0
    elif stat==2:
        if s[i:i+3]=='ABC':
            abc += 1
            i += 3
        elif s[i:i+2]=='BC':
            bc = 1
            stat = 3
            i += 2
        else:
            count()
            stat = 1
    else:
        if s[i:i+2]=='BC':
            bc += 1
            i += 2
        else:
            count()
            stat = 1
if stat>=2:
    count()
print(ans)

Measured memory_bytes: 45388
n, m = map(int, input().split())
ls_ab = [[int(_) for _ in input().split()] for _ in range(n)]

ls_ab.sort()
ans = 0
kosu = 0

for i in range(n):
	if kosu + ls_ab[i][1] >= m:
		ans += (m - kosu) * ls_ab[i][0]
		break
	else:
		ans += ls_ab[i][1] * ls_ab[i][0]
		kosu += ls_ab[i][1]

print(ans)

Measured memory_bytes: 21604
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<queue>
#include<map>
#define all(x) (x).begin(),(x).end()
typedef long long ll;
const ll MOD = 1000000007;
 
using namespace std;

int main(){
    int N, tmp;  cin >> N;
    for(int i=1; i<10000; i++){
        if(N <= (i*i + i)/2){
            tmp = N;
            for(int j=i; j>0; j--){
                if(tmp == 0)    break;
                else if(tmp >= j){
                    cout << j << endl;
                    tmp -= j;
                }
            }
            return 0;
        }
    }
}

Measured memory_bytes: 3604
//Solution by Tima
#include <bits/stdc++.h>
 
#define f first
#define s second
#define ll long long
#define ull unsigned long long
#define mp make_pair
#define pb push_back
#define vi vector <int>
#define ld long double
#define pii pair<int, int>
#define y1 sda
 
using namespace std;    
const int N = int(3e5) + 12, mod = int(1e9)  + 7; 

int a,b,n;

int main () {
	cin >> a >> b >> n;
	if(a < b) swap(a,b);
	cout << (n + a - 1) / a;
 
return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

const int dm = 1 << 21;
char dn[dm], * di = dn, dt;
inline void putint(int X) {
	int keta = 0;
	char C[10];
	while (X) {
		*(C + keta) = '0' + X % 10;
		X /= 10;
		keta++;
	}
	for (int i = keta - 1; i >= 0; i--)* di++ = (*(C + i));
	*di++ = '\n';
}

void pakuri_sort(int N, int A[], int B[], int C[]) {
	const int b = 8;
	int tmp[200001], tmp2[200001], tmp3[200001];
	rep(k, 4) {
		int kazu[1 << b] = {}, kazu2[1 << b] = {};
		rep(i, N) kazu[A[i] >> k * b & ((1 << b) - 1)]++;
		rep(i, (1 << b) - 1) kazu[i + 1] += kazu[i];
		for (int i = N - 1; i >= 0; i--) {
			tmp[--kazu[A[i] >> k * b & ((1 << b) - 1)]] = A[i];
			tmp2[kazu[A[i] >> k * b & ((1 << b) - 1)]] = B[i];
			tmp3[kazu[A[i] >> k * b & ((1 << b) - 1)]] = C[i];
		}
		k++;
		rep(i, N) kazu2[tmp[i] >> k * b & ((1 << b) - 1)]++;
		rep(i, (1 << b) - 1) kazu2[i + 1] += kazu2[i];
		for (int i = N - 1; i >= 0; i--) {
			A[--kazu2[tmp[i] >> k * b & ((1 << b) - 1)]] = tmp[i];
			B[kazu2[tmp[i] >> k * b & ((1 << b) - 1)]] = tmp2[i];
			C[kazu2[tmp[i] >> k * b & ((1 << b) - 1)]] = tmp3[i];
		}
	}
}

int S[200002], T[200002], X[200002];
int D[200002];
int P[200002];
int kotae[200002] = {};
int ima;
int Find(int A) {
	if (D[A] >= T[ima] - X[ima]) return A - 1;
	if (P[A]) return P[A] = Find(P[A] + 1);
	else {
		kotae[A] = X[ima];
		return P[A] = Find(A + 1);
	}
}

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


	int N = getint(), Q = getint();
	rep1(i, N) {
		S[i] = getint();
		T[i] = getint();
		X[i] = getint();
	}
	pakuri_sort(N, X + 1, S + 1, T + 1);
	rep1(i, Q) D[i] = getint();
	D[Q + 1] = 2e9;

	for (ima = 1; ima <= N; ima++) {
		auto j = lower_bound(D + 1, D + Q + 1, S[ima] - X[ima]) - D;
		Find(j);
	}

	rep1(i, Q) {
		if (kotae[i] == 0) {
			*di++ = '-';
			*di++ = '1';
			*di++ = '\n';
		}
		else putint(kotae[i]);
	}

	fwrite(dn, 1, di - dn, stdout);

	Would you please return 0;
}

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

int main() {
    int n, k;
    ll sum = 0;
    cin >> n >> k;
    vector<int> p(n);
    for (int i = 0; i < n; i++)
    {
        cin >> p[i];
    }
    sort(p.begin(), p.end());
    for (int i = 0; i < k; i++)
    {
        sum += p[i];
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3596
import java.util.*;
 class  Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String a = in.next();
        String b = in.next();
        String c = in.next();
        if(b.equals("+")){
            System.out.println(Integer.parseInt(a)+Integer.parseInt(c));
        }
        else {
            System.out.println(Integer.parseInt(a)-Integer.parseInt(c));
        }
    }


 }

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

using namespace std;
int main(void){
    int h, n;
    cin >> h >> n;
    

    for (int i = 0; i < n; i++){
        int a;
        cin >> a;
        h -= a;
    }
    
    if (h <= 0){
        cout << "Yes" << endl;
        return 0;
    }
    else{
        cout << "No" << endl;
        return 0;
    }
    
    
    
}


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

#define all(v)   v.begin(), v.end()
#define endl "\n";
#define pb push_back
#define F first
#define S second
#define THINK_TWICE_CODE_ONCE fast()
#define to_str to_string
#define isOdd(n)    (n&1)
#define LLMAX LLONG_MAX
#define LLMIN LLONG_MIN
#define IMIN INT_MIN
#define IMAX INT_MAX
#define pow POW
#define INF 1e9

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef double dd;
typedef string str;
typedef vector<int> vecint;
typedef vector<ll> vecll;
typedef pair<int, int> pii;

void fast() {
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(0);
}

bool compare(pii &a, pii &b) {
	return a.F > b.F;
}

ll numOfDigits(ll n) {
	if (!n) return 1;
	return (ll) (log10(n)) + 1;
}

ll POW(ll a, ll b);

/*

*/

ll BN();

int main()
{
    THINK_TWICE_CODE_ONCE;
    //freopen("test cases\\.txt", "r", stdin) ;
    int n; cin>>n;
    int arr[n];
    map<int, ll> mp;
    map<int, int> freq;
    for(int i=0; i<n; i++) cin>>arr[i], freq[arr[i]]++;
    ll sum = 0;
    for(auto &it: freq){
        mp[it.F] = (ll)it.S * (it.S-1)/2;
        sum += mp[it.F];
    }
    ll tmpSum = sum;
    for(int i=0; i<n; i++){
        sum = tmpSum;
        freq[arr[i]]--;
        sum -= mp[arr[i]];
        sum += (ll)freq[arr[i]] * (freq[arr[i]]-1)/2;
        cout<<sum<<endl;
        freq[arr[i]]++;
    }
    return 0;
}

ll BN() {
	int low = 1, up = 0;
	int ans = -1;
	while (low <= up) {
		ll mid = (((ll)low + up) / 2);
		if (mid){
			ans = mid;
			low = mid + 1;
		} else
			up = mid - 1;
	}
	return ans;
}

ll POW(ll a, ll b) {
	ll res = 1;
	while (b > 0) {
		if (b & 1)
			res = res * a;
		a = a * a;
		b >>= 1;
	}
	return res;
}


Measured memory_bytes: 16256
// Copyright 2020 yaito3014
#include <bits/stdc++.h>

int main() {
  using namespace std;
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  bool ans = (abs(a - b) <= d && abs(b - c) <= d) || abs(a - c) <= d;
  cout << (ans ? "Yes" : "No") << '\n';
}


Measured memory_bytes: 256
import numpy as np
from fractions import gcd

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


L = np.zeros(N, dtype=int)
R = np.zeros(N, dtype=int)

L[0] = A[0]


# L[i] .. A[0], A[1], A[i] の最大公約数
R[N-1] = A[N-1]
# R[i] .. A[-1], A[-2], .. A[(-(i+1)] の最大公約数
# R[i] .. A[N-1], A[N-2], .. A[(N-i-1)] の最大公約数

for i in range(1, N):
    L[i] = gcd(A[i], L[i-1])

for i in range(N-2, -1, -1):
    R[i] = gcd(A[i], R[i+1])

def it(i):
    if i == 0:
        return R[1]
    if i == N-1:
        return L[N-2]
    return gcd(L[i-1], R[i+1])

# print(A)
# print(L)
# print(R)

print(max(it(i) for i in range(N)))





Measured memory_bytes: 24256
N = int(input())
cnt = {}
a = list(map(int,input().split()))

for i in range(N):
	if a[i] in cnt:
		cnt[a[i]] += 1
	else:
		cnt[a[i]] = 1

res = 0
for key, value in cnt.items():
	if key < value:
		res += value - key
	elif key > value:
		res += value

print(res)

Measured memory_bytes: 18172
#include "iostream"
#include <string>
#include <queue>
#include <algorithm>

using namespace std;

int main(){
  int n,q,t;
  string name;

  queue < pair<string,int> > Q;

  cin >> n >> q;

  for(int i = 0;i<n;i++){
    cin >> name >> t;
    Q.push(make_pair(name,t));
  }
  pair<string,int> u;
  int elaps = 0,a;

  while(!Q.empty()){
    u = Q.front(); Q.pop();
    a = min(u.second,q);
    u.second -= a;
    elaps += a;
    if(u.second > 0){
      Q.push(u);
      }else{
        cout << u.first << " " << elaps << endl;
      }
    }
  return 0;
}



Measured memory_bytes: 6324
N, M = map(int, input().split())
e = [0,2,5,5,4,5,6,3,7,6]
dp = [-1]*(N+8)
dp[0] = 0
A = list(map(int, input().split()))
for n in range(N):
    if dp[n] == -1: continue
    for a in A:
        dp[n+e[a]] = max(dp[n+e[a]], dp[n]*10+a)
print(dp[N])

Measured memory_bytes: 84012
#include <bits/stdc++.h>
using namespace std;
using ll=long long;

int main(){
  ll n;
  cin >> n;
  
  ll all=0;
  vector<ll> a(n);
  
  for(int i=0;i<n;i++){
    cin >> a.at(i);
    all=all^a.at(i);
  }
  
  for(int i=0;i<n;i++){
    ll x=all^a.at(i);
    cout << x << endl;
  }
}

Measured memory_bytes: 4828
import sys
import collections


def input():
    return sys.stdin.readline()[:-1]


def main():
    n = int(input())
    s = ["".join(sorted(list(input()))) for _ in range(n)]
    c = collections.Counter(s)
    ans = 0
    for k in c.values():
        ans += k*(k-1)//2

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 64220
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();
		char[] s1 = s.toCharArray();
		char[] t1 = t.toCharArray();
		Arrays.sort(s1);
		Arrays.sort(t1);
		t1[0]=t1[t1.length-1];
		String S = String.valueOf(s1);
		String T = String.valueOf(t1);
		if(S.compareTo(T)<0) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}

}


Measured memory_bytes: 21844
#pragma GCC optimize("Ofast")
#include <cstdio>
#include <cstdlib>
#include <string>
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
#include <bitset>
#include <cmath>
#include <limits>
#include <iostream>
#include <map>
#include <set>
#include <tuple>
using namespace std;
#define INF 1LL << 30
#define MAX 100000
#define MOD 1000000007
typedef long long ll;
typedef pair<int,int> P;
//typedef pair<pair<int,int>,int> p;
#define bit(n, k) ((n >> k) & 1) /*nのk bit目*/
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)
struct edge
{
    ll to, cost, val;
};
template <class T, class U>
bool chmin(T &a, const U &b)
{
    if (a <= b)
        return false;
    a = b;
    return true;
}
template <class T, class U>
bool chmax(T &a, const U &b)
{
    if (a >= b)
        return false;
    a = b;
    return true;
}
//__builtin_popcount(S);
//C.erase(unique(C.begin(),C.end()),C.end());
//#define int ll

signed main(void)
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    ll N,A,B;
    cin>>N>>A>>B;
    if(N>A*B || N<A+B-1){
        cout<<-1<<endl;
        return 0;
    } 
    vector<int> V;
    int now=0;
    for(int i=0;i<B;i++){
        int x=B-i-1;
        int t=min(A,N-now-x);
        for(int j=N-now-t+1;j<=N-now;j++){
            V.push_back(j);
        }
        now+=t;
    }
    for(int i=0;i<N;i++){
        if(i) cout<<" ";
        cout<<V[i];
    }
    cout<<endl;

}


Measured memory_bytes: 3440
#include <iostream>

using namespace std;

int main(void){
	int n;
	cin >> n;
	int times = 0;
	int hit = 0;
	int point = 0;
	int out= 0 ;
	for(;times<n;){
		string s;
		cin >> s;
		if(s=="OUT"){
			out++;
			if(out==3){
				times++;
				cout << point << "\n";
				hit = 0;
				point = 0;
				out = 0;
			}
		}else if(s=="HIT"){
			if(hit<3) hit++;
			else point++;
		}else if(s=="HOMERUN"){
			point += hit+1;
			hit = 0;
		}
	}
	return 0;
}

Measured memory_bytes: 0
n,m = map(int, input().split())
al = list(map(int, input().split())) 

res = 0

def c(x):
    y = x*(x-1)//2
    return y

import itertools
als= list(itertools.accumulate(al))

alm = list(map(lambda x:x %m,als))

from collections import Counter
count = Counter(alm)
for i in count:
    if count[i]>1:
        res += c(count[i])

res += count[0]
print(res)

Measured memory_bytes: 26020
import math
n,a,b=map(int,input().split())
h=[int(input())for i in range(n)]
def f(x):
    s=sum([math.ceil(max(0,i-x*b)/(a-b))for i in h])
    if s<=x:
        return True
    else:
        return False
l=10**9+7
r=0
while l-r>1:
    k=(l+r)//2
    if f(k):
        l=k
    else:
        r=k
print(l)

Measured memory_bytes: 11032
// ABC122-B
// N<=10なら余裕だけど…
// より効率的にも解けますが不要です、、か。

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

int main(void){
  string S;
  cin >> S;
  int ret = 0;
  for(int i=0; i<S.size(); i++){
    for(int j=i; j<S.size(); j++){
      bool tmp = false;
      if(i==j) {
        if(S[i] == 'A' || S[i] == 'G' || S[i] == 'T' || S[i] == 'C'){
          tmp = true;
        }
      }else {
        for(int k=i; k<=j; k++) {
          if(S[k] == 'A' || S[k] == 'G' || S[k] == 'T' || S[k] == 'C') {
            tmp = true; 
          }else {
            tmp = false;
            break;
          }
        }
      }
      if(tmp) {
//        cout << "in, i: " << i << ", j: " << j << endl;
        ret = max(ret, j-i+1);
      }
    }
  }
  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 256
N,M = map(int,input().split())
A = list(map(int,input().split()))
cards = []
for i in range(0,N):
    cards.append((A[i],1))

for i in range(0,M):
    b,c = map(int,input().split())
    cards.append((c,b))

cards.sort()
cards.reverse()

result = 0
total = N
for num, cnt in cards:
    total -= cnt
    result += num*cnt
    if total < 0:
        result += num * total
        break
print(result)


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

int main() {
    // 制約見て！！！デカかったらlong longにすること！
    int n;
    cin >> n;
    int x;
    for(int i = 1;i<=n;i++){
        x = (int)i*1.08;
        if(x == n){
            cout << i <<endl;
            return 0;
        }
    }
    cout<<":("<<endl;
}

Measured memory_bytes: 3512
/*
  #問題：
  


  #分析：
  #オブジェクト：
  
  #条件：
  

  #要求：
  

  #解法：
  
*/

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define uLL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;


const unsigned int BIT_FLAG_0 = (1<<0);
const unsigned int BIT_FLAG_1 = (1<<1);
const unsigned int BIT_FLAG_2 = (1<<2);
const unsigned int BIT_FLAG_3 = (1<<3);
const unsigned int BIT_FLAG_4 = (1<<4);
const unsigned int BIT_FLAG_5 = (1<<5);
const unsigned int BIT_FLAG_6 = (1<<6);
const unsigned int BIT_FLAG_7 = (1<<7);


#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
namespace mp = boost::multiprecision;

using Bint = mp::cpp_int;



int main(void){
  int N;  cin>>N;
  vector<uLL> a(N);
  FOR(i,0,N){
    cin>>a[i];
  }


  uLL cnt=0;
  FOR(i,0,N){
    while(a[i]%2==0){
      a[i]=a[i]/2;
      cnt++;
    }
    
  }
  cout<<cnt<<endl;
  return 0;
}



Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <random>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

string s;
int main() {
  cin >> s;
  int n = s.size();
  s.insert(begin(s), 'x');
  bool ok = s[1] == '1' && s[n] == '0';
  for (int i = 1; i < n; ++i) {
    ok = ok && s[i] == s[n - i];
  }
  if (!ok) {
    cout << -1 << endl;
    return 0;
  }

  vector<pair<int, int>> es;
  int u = 1;
  for (int i = 1; i <= n / 2; ++i) {
    int v = i + 1;
    es.emplace_back(u, v);
    if (s[i] == '1') u = v;
  }
  for (int v = n / 2 + 2; v <= n; ++v) {
    es.emplace_back(u, v);
  }
  for (auto e : es) {
    cout << e.first << ' ' << e.second << '\n';
  }

  return 0;
}


Measured memory_bytes: 2420