akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

int main (){
  char s [4];
  int existA = 0, existB = 0;

  scanf ("%s", s);

  for (int i = 0; i < 3; i++) {
    if(s[i] == 'A') {
      existA = 1;
    } else {
      existB = 1;
    }
  }

  if(existA && existB) {
    printf("%s\n", "Yes");
  } else {
    printf("%s\n", "No");
  }

  return 0;
}


Measured memory_bytes: 128
n = int(input())
ds = [int(i) for i in input().split()]
mx = max(ds)

tbl = [0] * (mx+1)
for i in ds:
    tbl[i] += 1

cnt = 0
res = 0
for i in range(max(ds)):
    cnt += tbl[i]
    if cnt == n//2:
        res += 1
    elif cnt > n//2:
        break

print(res)

Measured memory_bytes: 14120
#include<stdio.h>
#include<math.h>

int main()
{
  long long int N;
  long long int P;
  long int i;
  long long int c;
  const long int arsize=200000;
  long long int divisors[arsize];
  long long int divcount[arsize];
  long long int divind=0;
  long long int gcd=1;
  long long int pp;

  for(i=0;i<arsize;i++) divcount[i]=0;

  scanf("%lld %lld",&N,&P);
  if(N==1)
  {
   printf("%lld\n",P);
  }else{
    c=P;
    if((c%2)==0) divisors[divind++]=2;
    while ((c%2)==0)
    {
      c=c/2;
      divcount[divind-1]++;
    }  
    pp=3;
    while( pp<=(sqrt(c)+1))
    {
      if ((c%pp) == 0)
      {
        if(divisors[divind-1]!=pp) divisors[divind++]=pp;
        divcount[divind-1]++;
        c = c /pp;
      }else{
        pp = pp + 2;
      }

    }
    if(c >1)
    {
      if(divisors[divind-1]==c)
      {
        divcount[divind-1]++;
      }else{
        divisors[divind++]=c;
        divcount[divind-1]++;
      }
    }
    for(i=0;i<divind;i++) 
    { 
      if(divcount[i]>=N) gcd=gcd*pow(divisors[i],(divcount[i]/N));
    }
    printf("%lld\n",gcd);
  }
 return 0;
}


Measured memory_bytes: 3200
#include <bits/stdc++.h>
  
using namespace std;
  
template<class T> void ckmin(T &a, T b) { a = min(a, b); }
template<class T> void ckmax(T &a, T b) { a = max(a, b); }
  
#define pb push_back
#define mp make_pair
#define cotu cout
#define itn int
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repr(i,n) for(int i = n - 1; i >= 0; --i)
#define Rep(i, a, n) for(int i = (a); i <=(n); ++i)
#define repst(i, n) for(auto it = n.begin(); it != n.end(); ++it)
#define Repr(i, a, n) for(int i = (n); i >= (a); --i)
#define forit(it, st) for(auto it : st)
#define ordered_set tree<int , null_type,less<int >, rb_tree_tag,tree_order_statistics_node_update> 
  
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
  
const int inf = int(1e9);
const int mod = inf + 7;
const int N = 1e6 + 555; // TL MB
const double PI = acos(-1.0);
const int days[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
int cnt[N];
void solve(){
	int n;
	cin >> n;
	int a[n];
	cnt[0] = 3;
	rep(i, n) cin >> a[i];
	int res = 1;
	rep(i, n){
		res = 1ll * res * cnt[a[i]] % mod;
		cnt[a[i] + 1]++;
		cnt[a[i]]--;
	}
	cout << res;


}	

 
int main()
{
    Red;
  	// int T; cin >> T; while(T--)
    solve();
    return 0;
}


Measured memory_bytes: 1024
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res

def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    a,b = LI()
    print(max(a+b,a-b,a*b))
    return

#B
def B():
    k,x = LI()
    ans = []
    for i in range(x-k+1,x+k):
        ans.append(i)
    print(*ans)
    return

#C
def C():
    def f(s):
        res = [0]*m
        for i in s:
            res[alp.index(i)] += 1
        return res
    alp = list("abcdefghijklmnopqrstuvwxyz")
    m = len(alp)
    n = I()
    s = [input() for i in range(n)]
    d = defaultdict(lambda : 0)
    for i in s:
        d[tuple(f(i))] += 1
    ans = 0
    for i in d.values():
        ans += (i*(i-1))//2
    print(ans)
    return

#D
def D():

    return

#E
def E():

    return

#F
def F():

    return

#Solve
if __name__ == "__main__":
    C()


Measured memory_bytes: 122116
package main

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

const (
	initialBufSize = 10000
	maxBufSize     = 1000000
	mod            = 1e9 + 7
)

var (
	sc *bufio.Scanner = func() *bufio.Scanner {
		sc := bufio.NewScanner(os.Stdin)
		buf := make([]byte, initialBufSize)
		sc.Buffer(buf, maxBufSize)
		sc.Split(bufio.ScanWords)
		return sc
	}()
)

func main() {
	X := getInt()
	num := X
	for ; ; num++ {
		if isPrime(num) {
			break
		}
	}
	fmt.Println(num)
}

type Graph struct {
	n     int
	edges [][]int
}

func NewGraph(n int) *Graph {
	g := &Graph{
		n:     n,
		edges: make([][]int, n),
	}
	return g
}

func (g *Graph) AddEdge(u, v int) {
	g.edges[v] = append(g.edges[v], u)
	g.edges[u] = append(g.edges[u], v)
}

func dfs(c int, edges [][]int, visited map[int]struct{}) {
	visited[c] = struct{}{}

	for _, v := range edges[c] {
		_, flag := visited[v]
		if flag {
			continue
		}
		dfs(v, edges, visited)
	}
}

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

func abs(a int) int {
	return int(math.Abs(float64(a)))
}

func pow(p, q int) int {
	return int(math.Pow(float64(p), float64(q)))
}

func powMod(n, p int) int {
	if p == 0 {
		return 1
	} else if p%2 == 0 {
		t := powMod(n, p/2)
		return calcMod(t * t)
	} else {
		return n * powMod(n, p-1)
	}
}

func min(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton min() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Min(float64(res), float64(nums[i])))
	}
	return res
}

func max(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton max() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Max(float64(res), float64(nums[i])))
	}
	return res
}

func strSearch(a []string, b string) bool {
	for i := 0; i < len(a); i++ {
		if a[i] == b {
			return true
		}
	}
	return false
}

func printIntArray(array []int) {
	strArray := fmt.Sprint(array)
	fmt.Println(strArray[1 : len(strArray)-1])
}

func calcMod(x int) int {
	return x % mod
}

func reverse(s string) string {
	runes := []rune(s)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return string(runes)
}

func isPrime(n int) bool {
	if n < 2 {
		return false
	} else if n == 2 {
		return true
	} else if n % 2 == 0 {
		return false
	}

	sqrtN := int(math.Sqrt(float64(n)))
	for i := 3; i <= sqrtN; i += 2 {
		if n % i == 0 {
			return false
		}
	}

	return true
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <queue>
#include <math.h>
using namespace std;
typedef long long int ll;

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	double r; cin >> r;
	printf("%.9f\n",2*r*acos(-1) );
}

Measured memory_bytes: 3808
object Main {
  def main(args: Array[String]): Unit = {
    val s = new Main()
    s.solve()
    s.out.flush()
  }
}

class Main {
  import java.io._
  import java.util.StringTokenizer

  import scala.collection.mutable
  import scala.util.Sorting
  import math.{abs, max, min}
  import mutable.{ArrayBuffer, ListBuffer}
  import scala.reflect.ClassTag

  val MOD = 1000000007
  val out = new PrintWriter(System.out)

  def solve(): Unit = {
    val N = ni()
    val A = Array.ofDim[Int](N, 3)
    REP(N) { i =>
      REP(3) { j =>
        A(i)(j) = ni()
      }
    }

    val dp = Array.ofDim[Int](2, 3)
    REP(N) { i =>
      val x = i % 2
      REP(3) { j =>
        REP(3) { k =>
          if (k != j) dp(x^1)(j) = max(dp(x^1)(j), dp(x)(k) + A(i)(j))
        }
      }
    }

    val ans = dp(N % 2).max
    out.println(ans)
  }

  class InputReader(val stream: InputStream) {
    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer: StringTokenizer = _

    def next(): String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = next().toInt
    def nextLong(): Long = next().toLong
    def nextChar(): Char = next().charAt(0)
  }
  val sc = new InputReader(System.in)
  def ni(): Int = sc.nextInt()
  def nl(): Long = sc.nextLong()
  def nc(): Char = sc.nextChar()
  def ns(): String = sc.next()
  def ns(n: Int): Array[Char] = ns().toCharArray
  def na(n: Int, offset: Int = 0): Array[Int] = map(n)(_ => ni() + offset)
  def na2(n: Int, offset: Int = 0): (Array[Int], Array[Int]) = {
    val A1, A2 = Array.ofDim[Int](n)
    REP(n) { i =>
      A1(i) = ni() + offset
      A2(i) = ni() + offset
    }
    (A1, A2)
  }
  def nm(n: Int, m: Int): Array[Array[Int]] = {
    val A = Array.ofDim[Int](n, m)
    REP(n) { i =>
      REP(m) { j =>
        A(i)(j) = ni()
      }
    }
    A
  }
  def nal(n: Int): Array[Long] = map(n)(_ => nl())
  def nm_c(n: Int, m: Int): Array[Array[Char]] = map(n) (_ => ns(m))
  def REP(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = offset
    val N = n + offset
    while(i < N) { f(i); i += 1 }
  }
  def REP_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = n - 1 + offset
    while(i >= offset) { f(i); i -= 1 }
  }

  def map[@specialized A: ClassTag](n: Int, offset: Int = 0)(f: Int => A): Array[A] = {
    val res = Array.ofDim[A](n)
    REP(n)(i => res(i) = f(i + offset))
    res
  }


  def sumL(as: Array[Int]): Long = {
    var s = 0L
    REP(as.length)(i => s += as(i))
    s
  }

  def cumSum(as: Array[Int]) = {
    val cum = Array.ofDim[Long](as.length + 1)
    REP(as.length) { i =>
      cum(i + 1) = cum(i) + as(i)
    }
    cum
  }
}

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



int main(){
int n, m, ans  = 0;
cin >> n >> m;
for(int i = 1; i * i <= m; i++){
   if(m % i == 0){
      int j = i;
      if(m / j >= n) ans = max(ans, j);
      if(m / (m / j) >= n) ans = max(ans, m / j);
   }
}
cout << ans;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i=(a); i<(int)(b); i++)
#define pb push_back
#define ALL(x) (x).begin(), (x).end()
#define st first
#define nd second
using namespace std;
 
const int maxN = 1 << 18;

char T[maxN];

void solve()
{
	int k;
	scanf ("%d", &k);
	scanf ("%s",T);
	int n = strlen(T);
	
	FOR(i, 0, n)
	{
		int j = T[i] - 'A';
		j = (j + k) % 26;
		printf("%c", 'A' + j);
	}
	printf("\n");
}
 
int main()
{
	int t;
	t=1;//scanf ("%d", &t);
	while (t--)
		solve();
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define int             long long
#define pb              push_back
#define mp              make_pair
#define scan(a, n) 		for(int i = 0; i < n;i++)cin >> a[i];
#define print(a, n) 	for(int i = 0; i < n;i++)cout << a[i] <<' ';cout<<endl;
#define w(x)            int x; cin>>x; while(x--)
#define ms(s, n) 		memset(s, n, sizeof(s))
#define sz(a) 			int((a).size())
#define endl 			'\n'
const int MOD = 		(int) 1e9 + 7;
#define all(v) 			v.begin(),v.end()
#define Sort(v) 		sort(v.begin(), v.end())
#define vi 				vector<int>
#define vs 				vector<string>
#define db(...) 		__f(#__VA_ARGS__, __VA_ARGS__)
#define rep(i, n) 		for (int (i) = 0; (i) < (int)(n); ++(i))
#define prefixsum(a,b)	partial_sum(all(a),b.begin())

 
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << '\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
	const char* comma = strchr(names + 1, ',');
	cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}
 
template <typename T, typename U> 
inline void chkmax(T& x, U y) {
	if (x < y) x = y;
}
  
template <typename T, typename U>
inline void chkmin(T& x, U y) {
	if (y < x) x = y;
}

void code()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("/home/tushar/Desktop/input.txt", "r", stdin);
    freopen("/home/tushar/Desktop/output.txt", "w", stdout);
#endif
}
// template end here


void solve() 
{
	int i, j, k, q ,n, m, ans = 0, cnt = 0, sum = 0,input;
	int x;cin>>x;
	int a=100;

	while(a<x)
	{
		a = a + (0.01)*a;
		cnt++;
	}
	cout<<cnt<<endl;
}
 
int32_t main()
{
    code();
    solve();
    return 0;
}




Measured memory_bytes: 3604
N, M  = map(int, input().split())
A = [int(a) for a in input().split()]
thr = (sum(A) - 1) // (4 * M) + 1
cnt = 0
for a in A:
    if a >= thr:
        cnt += 1
if cnt >= M:
    print('Yes')
else:
    print('No')


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

int main(){
    int N;
    cin >> N;
    string s = to_string(N);
    if (s.at(0) == '9' || s.at(1) == '9'){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
S = input()
n = len(S)-1
total_num = 0
if n == 0:
    total_num = S[0]
else:
    for i in range(2**n):
        num = '' 
        for j in range(n):
            if i & 2**j:
                num += S[j]
                total_num += int(num)
                num = ''
            else:
                num += S[j]
        num += S[-1]
        total_num += int(num)
print(total_num)
        

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n) ; i++)
#define rrep(i,n) for(int i = n-1; i >= 0 ; i--)
typedef long long ll;
constexpr auto INFI = 2147483647;
const ll INFL = 9223372036854775807;

int main(){
    map<string, int> ans;
    int n;
    string tmp;
    cin >> n;

rep(i,n) {
    cin >> tmp;
    ans[tmp]++;
}

cout << "AC" << " x " << ans["AC"] << endl;
cout << "WA" << " x " << ans["WA"] << endl;
cout << "TLE" << " x " << ans["TLE"] << endl;
cout << "RE" << " x " << ans["RE"] << endl;

    return 0;
}

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

#define rep(i, a, b) for(int i = (a); i < int(b); ++i)
#define rrep(i, a, b) for(int i = (a) - 1; i >= int(b); --i)
#define trav(it, v) for(auto &it : (v))
#define all(v) (v).begin(), (v).end()
#define what_is(x) cerr << #x << " is " << x << endl;
#define sz(x) (int)(x).size()

typedef double fl;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;

vector<int> A[3];
set<pair<int, int> > convert[3][3];
vector<int> color;
ll ans;

void add(int ind, int color){
	rep(i,0,3){
		convert[color][i].insert(make_pair(A[i][ind]-A[color][ind], ind));
	}
	ans += A[color][ind];
}

void remove(int ind, int color){
	rep(i,0,3){
		convert[color][i].erase(make_pair(A[i][ind]-A[color][ind], ind));
	}
	ans -= A[color][ind];
}

int main(){
	ios::sync_with_stdio(0);
	int X[3];
	cin >> X[0] >> X[1] >> X[2];
	int N = X[0] + X[1] + X[2];
	A[0].resize(N);
	A[1].resize(N);
	A[2].resize(N);
	rep(i,0,N){
		cin >> A[0][i] >> A[1][i] >> A[2][i];
	}
	int curInd = 0;
	rep(i,0,3){
		rep(j,0,X[i]){
			add(curInd, i);
			curInd++;
		}
	}
	while(true){
		int c[3][3];
		bool any = false;
		rep(i,0,3)
			rep(j,0,3){
				c[i][j] = convert[i][j].rbegin()->first;
			}
		rep(i,0,3){
			if(any)
				break;
			rep(j,i+1,3){
				if(c[i][j]+c[j][i] > 0){
					int indi = convert[i][j].rbegin()->second;
					int indj = convert[j][i].rbegin()->second;
					remove(indi, i);
					add(indi, j);
					remove(indj, j);
					add(indj, i);
					any = true;
					break;
				}
			}
		}
		if(any)
			continue;
		int i = 0;
		rep(j,1,3){
			if(any)
				break;
			int k = 3-j;
			if(c[i][j]+c[j][k]+c[k][i] > 0){
				int indi = convert[i][j].rbegin()->second;
				int indj = convert[j][k].rbegin()->second;
				int indk = convert[k][i].rbegin()->second;
				remove(indi, i);
				add(indi, j);
				remove(indj, j);
				add(indj, k);
				remove(indk, k);
				add(indk, i);
				any = true;
			}
		}
		if(!any)
			break;
	}
	cout << ans << endl;
}

Measured memory_bytes: 15488
#include <algorithm>
#include <cmath>
#include <iostream>
#include <limits>
#include <numeric>
#include <string>
#include <vector>

using namespace std;
int main() {
    int a[] = {1, 1, 1, 2, 1, 2, 1, 5,  2, 2, 1, 5, 1, 2, 1, 14,
               1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int k;
    cin >> k;
    cout << a[k - 1] << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int a,b;
	cin>>a>>b;
	string s[a];
	for(int i=0;i<a;i++) cin>>s[i];
		sort(s,s+a);
	for(int i=0;i<a;i++) cout<<s[i];
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize ("Ofast")
#define int long long 
#define ld long double
#define pb push_back
#define vi vector<int>
#define pii pair<int,int>
#define ff first
#define ss second
#define endl '\n'
#define all(v) v.begin(),v.end()
#define sz(v) (int)v.size()
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n;i>=0;i--)
#define loop(i,l,r) for(int i=l;i<r;i++)
#define rloop(i,r,l) for(int i=r;i>=l;i--)
#define watch(x) cerr<<(#x)<<"= "<<(x)<<endl;
#define watcharr(a) cerr<<(#a)<<"("<<sz(a)<<")= ";rep(i,sz(a))cerr<<a[i]<<",";cerr<<'\n';
#define inf 2000000000000000000LL
#define mod 1000000007
#define mod1 998244353
#define FASTIO std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
using namespace std;

signed main() {
    FASTIO;
    // #ifndef ONLINE_JUDGE
    //     freopen("input.txt", "r", stdin);
    //     freopen("output.txt", "w", stdout);
    //     freopen("stderr.txt", "w", stderr);
    // #endif

    // int tt=1;
    // cin>>tt;
    // while(tt--){
        string s,t;
        cin>>s>>t;
        int n=s.size(), m=t.size();
        vector<vector<int>> dp(n+1,vector<int>(m+1));
        rep(i,n+1){
            rep(j,m+1){
                if(i==0 or j==0) dp[i][j]=0;
                else{
                    if(s[i-1]==t[j-1]) dp[i][j]=dp[i-1][j-1]+1;
                    else dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
                }
            }
        }
        // rep(i,n+1){rep(j,m+1) cerr<<dp[i][j]<<' '; cerr<<endl;}
        // watch(dp[n][m]);
        int i=n, j=m;
        string ans="";
        while(i>0 and j>0){
            if(s[i-1]==t[j-1]){
                ans=s[i-1]+ans;
                i--, j--;
            }
            else (dp[i-1][j]>dp[i][j-1])? i--:j--;
        }
        cout<<ans<<endl;
        
    // }
    // cerr<<"Time Elapsed: "<<1.0*clock()/CLOCKS_PER_SEC<<" sec";
    return 0;
}

Measured memory_bytes: 70784
def main():
    from bisect import bisect_left
    import sys
    sys.setrecursionlimit(10 ** 7)
    input = sys.stdin.readline

    inf = 1 << 30

    N = int(input())
    *a, = map(int, input().split())

    g = tuple(set() for _ in range(N))
    for _ in range(N - 1):
        u, v = (int(x) - 1 for x in input().split())
        g[u].add(v)
        g[v].add(u)

    ans = [0] * N
    lis = [inf] * N
    lis[0] = a[0]

    def dfs(v, p=-1):
        ans[v] = bisect_left(lis, inf)
        for u in g[v]:
            if p == u: continue
            i = bisect_left(lis, a[u])
            prev_at_i = lis[i]
            lis[i] = a[u]
            dfs(u, v)
            lis[i] = prev_at_i

    dfs(0)

    print(*ans, sep='\n')


if __name__ == '__main__':
    main()

# dp[i]=長さiの増加部分列の末尾としてありえる最小値
# というテーブルを持っておいて、数列を列を前から見ながら二分探索で更新箇所を探す


Measured memory_bytes: 301084
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

int main() {
    int n;
    cin >> n;
    vec t(n), x(n), y(n);
    rep(i, n) cin >> t[i] >> x[i] >> y[i];

    bool f = true;

    rep(i, n) {
        if (i == 0) {
            if (abs(x[0]) + abs(y[0]) > t[0]) f = false;
            if ((abs(x[0]) + abs(y[0])) % 2 != t[0] % 2) f = false;
        }
        if (i == n-1) continue;
        int diff = t[i+1] - t[i];
        int d = abs(x[i+1] - x[i]) + abs(y[i+1] - y[i]);
        if (d > diff) f = false;
        if (d % 2 != diff % 2) f = false;
    }

    if (f) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 1408
from collections import deque
import sys
readline = sys.stdin.readline
write = sys.stdout.write
def solve():
    N = int(readline())
    A = [0]*N
    B = [0]*N
    for i in range(N-1):
        a, b = map(int, readline().split())
        if not a <= b:
            a, b = b, a
        A[i] = a-1
        B[i] = b-1
    que = deque([0])
    vs = []
    dist = [0]*N
    while que:
        v = que.popleft()
        vs.append(v)
        d = dist[v]
        if A[v] != N-1:
            w = A[v]
            que.append(w)
            dist[w] = d+1
        if B[v] != N-1:
            w = B[v]
            que.append(w)
            dist[w] = d+1
    sz = [0]*N
    dp = [[0, 0] for i in range(N)]
    vs.reverse()
    for v in vs:
        a = A[v]; b = B[v]
        if a == N-1:
            dp[v][0] = 2
            dp[v][1] = dist[v] + 2
            sz[v] = 2
        elif b == N-1:
            dp[v][0] = dp[a][0] + sz[a] + 1
            dp[v][1] = dp[a][1] + 1
            sz[v] = sz[a] + 1
        else:
            dp[v][0] = dp[a][0] + dp[b][0] + sz[a] + sz[b]
            dp[v][1] = min(dp[a][0] + dp[b][1] + sz[a], dp[a][1] + dp[b][0] + sz[b], dp[a][1] + dp[b][1])
            sz[v] = sz[a] + sz[b]
    write("%d\n" % dp[0][1])
solve()


Measured memory_bytes: 167876
//16
#include<iostream>
#include<algorithm>

using namespace std;

int main(){
  for(int n;cin>>n,n;){
    int a[100];
    for(int i=0;i<n;i++){
      cin>>a[i];
    }
    int ans=0;
    bool up;
    do{
      up=false;
      for(int i=0;i<n-1;i++){
	if(a[i]>a[i+1]){
	  ans++;
	  up=true;
	  swap(a[i],a[i+1]);
	}
      }
    }while(up);
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
// Problem : D - Sum of Large Numbers
// Contest : AtCoder - AtCoder Beginner Contest 163
// URL : https://atcoder.jp/contests/abc163/tasks/abc163_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/coder3101/cp-editor)

// Mere bas ka nahi hai
// still i'm trying
// apna time aayega
//
//        .--------------.  
//        | Try First One|
//        '--------------'
//                |     .--------------.
//                |     |              |
//                V     V              |
//              .--------------.       |
//              |      AC.     |<---.  |  
//              '--------------'    |  |
//              (True)|  |(False)   |  |
//           .--------'  |          |  |
//           |           V          |  |
//           |  .--------------.    |  |
//           |  |   Try Again  |----'  |
//           |  '--------------'       |
//           |                         |
//           |  .--------------.       |
//           '->| Try Next One |-------'
//              '--------------'                          		  
//
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll power(ll x,ll y,ll m){if(y==0)return 1;ll p=power(x,y/2,m)%m;p=(p*p)%m;return (y%2==0)?p:(x*p)%m;}
ll nCr(ll n,ll r,ll m){if(r>n)return 0;ll a=1,b=1,i;for(i=0;i<r;i++){a=(a*n)%m;--n;}while(r){b=(b*r)%m;--r;}return (a*power(b,m-2,m))%m;}
#define Test int t;cin>>t;while(t--)
#define endl '\n'
void solve()
{
	int n,k;
	cin >> n >> k;
	long long int ans=0;
	for(int i=k-1;i<=n;++i)
	{
		if(i==0)
		ans+=n+1;
		//long long int temp=(i*(i+1)) >> 1;
		//long long int temp2=temp +
		else
		ans+=((long long int)(n-i))*((ll)(i+1))+1;
		ans%=1000000007;
	}
	cout << ans << endl;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	//Test
	solve();
	return 0;
}


Measured memory_bytes: 3652
import java.util.Scanner;

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

		long cntR = 0;
		long cntG = 0;
		long cntB = 0;
		int i,j,k;
		for(i = 0; i < n; i++) {
			switch(d[i]){
			case 'R':
				cntR++;
				break;
			case 'G':
				cntG++;
				break;
			case 'B':
				cntB++;
				break;

			}
		}

		long ans = cntR * cntG * cntB;
		for(i = 0; i < n - 2; i++) {
			for(j = i + 1; j < n - 1; j++) {
				k = i + (j - i) * 2;
				if(k >= n)
					break;

				if(d[i] != d[j] && d[j] != d[k] && d[i] != d[k])
					ans--;
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 36312
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <sstream>
#include <functional>
#include <numeric>
#include <cmath>
#include <cstring>
#include <queue>

using namespace std;

const int INF = 1 << 29;
typedef pair<int, int> P;

int m, n;

vector<int> ans;
vector<bool> visited;

vector<vector<int> > graph;

void visit(int node)
{
	if(visited[node]) return;
	visited[node] = true;
	int size = graph[node].size();
	for (int i = 0; i < size; i++)
	{
		visit(graph[node][i]);
	}
	ans.push_back(node);
}

int main(void)
{
	while(cin >> m >> n && m)
	{
		ans.clear();
		visited.resize(m);
		fill(visited.begin(), visited.end(), false);
		graph = vector<vector<int> >(m);

		for (int i = 0; i < n; i++)
		{
			int x, y;
			cin >> x >> y, x--, y--;
			graph[y].push_back(x);
		}

		visit(1);
		for (int i = 0; i < m; i++)
		{
			cout << ++ans[i] << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1228
function shcdHash( key )
{
  var res = 0;
  if( 'S' == key ) {
    res = 0;
  } else if( 'H' == key ) {
    res = 1;
  } else if( 'C' == key ) {
    res = 2;
  } else if( 'D' == key ) {
    res = 3;
  }
  return res;
} 
var input = '';
var readable = process.stdin;
readable.resume();
readable.setEncoding( 'utf-8' );
readable.on( 'data', function( chunk ) {
  input += chunk;
});

readable.on( 'end', function() {
  var cards = { 'S':[] , 'H':[], 'C':[], 'D':[] };
  var shcd = [ 'S', 'H', 'C', 'D' ];
  for( var key in cards ) {
    for( var i=1; i<=13; i++ ) {
      cards[key].push( i );
    }
  }
  var data = input.split( '\n' );
 
  for( var i=1; i<data.length; i++ ) {
    var p = data[i].split( ' ' );
    var k = shcdHash( p[0] );
    var res = cards[ shcd[k] ].indexOf( Number( p[1] ) );
    if( -1 != res ) {
        cards[ shcd[k] ].splice( res, 1 );
    }
  }
  for( var i=0; i<4; i++ ) {
    for( var j = 0; j<cards[ shcd[i] ].length; j++ ) {
      console.log( shcd[i]+" "+cards[ shcd[i] ][j] );
    }
  }
});

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

int N,length[100001];
long long ans1,ans2;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
    cin>>N;
    for(int i = 1;i <= N;i++){
        cin>>length[i];
    }
    sort(length + 1,length + N + 1);
    for(int i = N;i >= 1;i--){
        if(length[i] == length[i - 1] && ans1 == 0) {
            ans1 = length[i];
            i--;
        }
        else if(length[i] == length[i - 1] && ans2 == 0) {
            ans2 = length[i];
            break;
        }
    }
    cout<<ans1 * ans2<<endl;
}


Measured memory_bytes: 4032
a = input()

if a[0] == "R" and a[1] == "R" and a[2] == "R":
  print(3)
elif (a[0] == "R" and a[1] == "R") or (a[1] == "R" and a[2] == "R"):
  print(2)
elif a[0] == "R" or a[1] == "R" or a[2] == "R":
  print(1)
else:
  print(0)

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

int main() {
    int n;
    cin >> n;
    vector<long long> a(n);
    for(int i = 0; i < n; i++) cin >> a.at(i);
    long long cash = 1000;
    long long stock = 0;
    for(int i = 0; i < n - 1; i++) {
        if(a.at(i) < a.at(i + 1)) {
            stock += cash / a.at(i);
            cash -= stock * a.at(i);
            cash += stock * a.at(i + 1);
            stock -= stock;
        }
    }
    cout << cash << endl;
}

Measured memory_bytes: 3556
#include <stdio.h>
#include <math.h>

int main(void)
{
  int a, b, i, j, k, result;
  
  scanf("%d", &k);
  
  scanf("%d %d", &a, &b);
  
  for( i = a; i <= b; i++ ){
      if( i % k == 0 ){
          printf("OK\n");
          return 0;
      }
  }

  
  printf("NG\n");
  return 0;
}

Measured memory_bytes: 1664
// Contest: AtCoder Beginner Contest 178 (https://atcoder.jp/contests/abc178)
// Problem: B: Product Max (https://atcoder.jp/contests/abc178/tasks/abc178_b)


// region boilerplate
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <chrono>
#include <cstdint>
#include <deque>
#include <exception>
#include <forward_list>
#include <functional>
#include <initializer_list>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#if __cplusplus >= 201703L
#   include <optional>
#   include <string_view>
#   include <variant>
#endif

using namespace std;

#if __cplusplus >= 201703L
#   define all(a)      begin(a),end(a)
#   define sz(x)       ((int)size(x))
#else
#   define all(a)      (a).begin(),(a).end()
#   define sz(x)       ((int)(x).size())
#endif

#define rep(a, b)      for(int a = 0; a < (b); ++a)
#define reps(a, b, c)  for(int a = (b); a < (c); ++a)
#define trav(a, b)     for(auto& a : b)

using ll = long long;
using ld = long double;
using u64 = uint64_t;
using u32 = uint32_t;

using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vpi = vector<pi>;

#if __cplusplus >= 201703L
#   define MAYBE_UNUSED [[maybe_unused]]
#else
#   define MAYBE_UNUSED
#endif

MAYBE_UNUSED static constexpr int INF = (int)1e9 + 5;
MAYBE_UNUSED static constexpr ll INFL = (ll)1e18 + 5;
MAYBE_UNUSED static mt19937 rng((u32)chrono::duration_cast<chrono::nanoseconds>(chrono::high_resolution_clock::now().time_since_epoch()).count());
//endregion

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

    ll a, b, c, d; cin >> a >> b >> c >> d;
    cout << max({a * c, a * d, b * c, b * d}) << '\n';

    return 0;
}


Measured memory_bytes: 3624
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する
class Solve {
public:
    int N;
    vector<vector<pair<int, int>>> G;
    vector<int> label;

    void input() {
        cin >> N;
        G.resize(N);
        label.resize(N, -1);
        rep(i, 0, N - 1) {
            int a, b, w;
            cin >> a >> b >> w;
            a--, b--;
            w %= 2;
            G[a].push_back(make_pair(b, w));
            G[b].push_back(make_pair(a, w));
        }
    }

    void dfs(int v, int c = 0, int p = -1) {
        if (label[v] == -1) label[v] = c;
        for (auto e : G[v]) {
            int nv = e.first;
            int w = e.second;
            if (nv != p) {
                dfs(nv, (c + w) % 2, v);
            }
        }
    }

    void solve() {
        input();
        dfs(0);
        for (auto e : label) {
            cout << e << endl;
        }

    }
};


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

    Solve().solve();


    return 0;
}


Measured memory_bytes: 8960
import java.io.*;
import java.util.*;

public class Main {

	final static long MOD = 1000000007L;
	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static ArrayList<int[]> list = new ArrayList<>();
	public static void main(String[] args) throws Exception {

		long N = nextLong();
		long M = nextLong();
		if(Math.abs(N-M)>1){
			System.out.println(0);
			return;
		}
		long ans = 1;
		if(N==M){
			ans=2;
		}
		for(int i=1;i<=N;i++){
			ans=ans*i%MOD;
		}
		for(int i=1;i<=M;i++){
			ans=ans*i%MOD;
		}
		System.out.println(ans);
	}


	public static String[] toStringArray(String s) {
		String[] tmp = new String[s.length()];
		char[] c = s.toCharArray();
		for (int i = 0; i < tmp.length; i++) {
			tmp[i] = String.valueOf(c[i]);
		}
		return tmp;
	}

	public static String concatStringArray(String[] s){
		StringBuffer sb = new StringBuffer();
		for(String x:s){
			sb.append(x);
		}
		return sb.toString();
	}

	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}


}

Measured memory_bytes: 23252
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>

#define FOR(i, a) for(int i=0;i<(int)a;++i)
typedef long long ll;
using namespace std;

void solver() {
    int N;
    while (cin >> N) {
        int ans = 0;
        FOR(a, 10)FOR(b, 10)FOR(c, 10) {
                    int d = N - (a + b + c);
                    if (d >= 0 && d < 10) {
                        ans++;
                    }
                }
        cout << ans << endl;
    }
}

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

Measured memory_bytes: 3076
#include<iostream>
#include<string>
#include<vector>

using namespace std;

int main() {
	int N, C0 = 0, C1 = 0, C2 = 0, C3 = 0;
	string S;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> S;
		if (S == "AC")C0++;
		if (S == "WA")C1++;
		if (S == "TLE")C2++;
		if (S == "RE")C3++;
	}
	cout << "AC x " << C0 << endl;
	cout << "WA x " << C1 << endl;
	cout << "TLE x " << C2 << endl;
	cout << "RE x " << C3 << endl;
}

Measured memory_bytes: 3524
#include<iostream>
#include<string>
#include<algorithm>

using namespace std;

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

int main(void){
    string ro;
    int m[256]={};
    m['I']=1,
        m['V']=5,
        m['X']=10,
        m['L']=50,
        m['C']=100,
        m['D']=500,
        m['M']=1000;
    while(cin>>ro){
        int n=0;
        for(auto c:ro)n+=m[c];
        rep(i,ro.size()) if(m[ro[i]]<m[ro[i+1]])n-=2*m[ro[i]];
        cout<<n<<endl;
    }
}

Measured memory_bytes: 1184
from fractions import gcd

N,K = map(int,input().split())
A = [int(i) for i in input().split()]

if K > max(A):
    print('IMPOSSIBLE')
    exit()


a = 0
for i in range(N):
    a = gcd(a,A[i])

if K % a == 0:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')


Measured memory_bytes: 16240
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline

##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)

##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力

# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと

##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順

# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順

##### 無限 #####
# f_inf = float('inf')

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))

def main():
	N,K = inputMap()
	P = inputList()

	kikan1 = 0
	maaxx = 0
	base = 0
	for i in range(N):
		if i == 0:
			tmp = 0
			for j in range(K):
				tmp += P[i+j]
			base = tmp
			continue

		#print(i)
		if i+K > N:
			break
		#print(i)
		tmp = base - P[i-1] + P[i+K-1]
		base = tmp
		if tmp > maaxx:
			maaxx = tmp
			kikan1 = i

	#print(kikan1)
	ans = 0
	for j in range(K):
		#print(P[kikan1+j])
		tmp = P[kikan1+j]
		total = 0
		for jj in range(1,tmp+1):
			total += jj
		ans += total/tmp

	print(ans)

if __name__ == "__main__":
	main()


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

ll INF = 1LL << 60;

int 
main() {

  int N, M; cin >> N >> M;
  vector<int> arr(N, -1);

  rep(i, 0, M){
    int digit; cin >> digit, --digit;
    int value; cin >> value;
    if(arr[digit] != -1){
      if(value != arr[digit]){
        cout << -1 << endl;
        return 0;
      }
    }
    if(N > 1 && digit == 0 && value == 0){
      cout << -1 << endl;
      return 0;
    }
    arr[digit] = value;
  }

  if(N == 1){
    if(arr[0] != -1) cout << arr[0];
    else cout << 0 << endl;
    return 0;
  } else if(arr[0] != -1) {
    cout << arr[0];
  } else {
    cout << 1;
  }

  rep(i, 1, N){
    if(arr[i] != -1){
      cout << arr[i];
    } else {
      cout << 0;
    }
  }
  cout << endl;
}


Measured memory_bytes: 3588
#!/usr/bin/env python3
import math
import collections

N = int(input().split()[0])

def factorize(n: int) -> list:
    # 試し割り法
    f_list = []
    while n % 2 == 0:
        f_list.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            f_list.append(f)
            n //= f
        else:
            # 偶数はすでにチェックしているので+2ずつカウントアップ
            f += 2

    if n != 1:
        f_list.append(n)
    return f_list

mod = 10**9 + 7
c = 1
d_list = []
counter = collections.Counter()

for i in range(1, N+1):
    f_list = factorize(i)
    c = collections.Counter(f_list)
    counter += c

x = 1

for k, v in counter.items():
    x *= (v + 1) % mod

ans = x % mod
print(ans)


Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}

int main() {
    int n;
    cin >> n;
    map<int, int>cnts;
    set<int>nums;
    for(int i=0; i<n; i++){
        int ai;
        cin >> ai;
        nums.insert(ai);
        cnts[ai]++;
    }
    int ans = 0;

    auto itr = nums.begin();
    while(itr != nums.end()){
        int k = *itr;
        int ck = cnts[k];
        if (ck >= k){
            ans += min(ck, ck-k);
        }
        else{
            ans += ck;
        }
        itr++;
    }
    cout << ans << endl;

}

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

using namespace std;

#define ll long long

const int N = 1005;

int a[N];

void go(vector<int> ind,int n){

    assert(ind.size()>0);
    int cur = n;
    int C = (ind[0]-1);
    vector<int> ret;

    while(C--){
        --cur;
        ret.push_back(1);
    }
    C = n- ind.back();

    while(C--){
        ret.push_back(cur);
        --cur;
    }
    for(int i=0;i<(int)ind.size()-1;++i){
        C = (ind[i+1]-ind[i])/2;
        while(C>0){
            ret.push_back(C+1);
            --C;
        }
    }

    cout<<ret.size()<<endl;
    for(int i=0;i<ret.size();++i)printf("%d\n",ret[i]);
}
int main(){

    //freopen("input.txt","r",stdin);
    int n;
    cin>>n;
    bool is=0;
    int maxi = -2e9;
    for(int i=1;i<=n;++i){
        scanf("%d",&a[i]);

        if(a[i]>=0){
            is = 1;
        }
        maxi = max(maxi,a[i]);
    }
    if(!is){
        vector<int> ind;
        cout<<maxi<<endl;
        for(int i=1;i<=n;++i)if(a[i]==maxi){
            ind.push_back(i);
            break;
        }
        go(ind,n);
        return 0;
    }

    ll odd = 0,even=0;

    vector<int> oind,eind;
    for(int i=1;i<=n;i+=2){
        if(a[i]>0)odd+=a[i],oind.push_back(i);
    }
    for(int i=2;i<=n;i+=2){
        if(a[i]>0)even+=a[i],eind.push_back(i);
    }
    vector<int> ind;
    ll sum = 0;
    if(odd>even && oind.size()>0)
        ind = oind,sum = odd;
    else
        ind = eind,sum = even;

    cout<<sum<<endl;

    go(ind,n);
}

Measured memory_bytes: 384
#写経
#https://atcoder.jp/contests/abc168/submissions/13414936
from math import gcd
from collections import Counter
mod = 10**9 + 7
N,*AB = map(int,open(0).read().split())

def std(a,b):
    """
    a,bを既約にする
    """
    if a == 0:
        return(0,int(b!=0))
    g = gcd(a,b)
    a,b = a// g, b//g
    return(a,b) if a > 0 else (-a,-b)

C = Counter(std(a, b) for a, b in zip(*[iter(AB)] * 2))
def resolve():
    ans = 1
    cnt = 0
    for (a,b), v in C.items():
        if b > 0:
            if (b,-a) in C:
                ans *= -1 + pow(2,v,mod) + pow(2,C[(b,-a)], mod) #仲の悪い組み合わせが一緒に入らないように，別々に入れるか入れないかを判定 空集合は共通しているので引く
                ans %= mod
            else:
                cnt += v
        elif (-b,a) not in C:
            cnt += v
    ans *= pow(2,cnt,mod)
    ans += C[(0,0)] - 1
    print(ans%mod)
resolve()

Measured memory_bytes: 72816
#include <iostream>

using namespace std;

const int MAXN = 100005;

int dp[MAXN][4], day[MAXN][4];

int main()
{
    int n;
    cin >> n;
    for(int i = 1; i <= n; ++i){
        for(int j = 1; j <= 3; ++j)
            cin >> day[i][j];
    }
    for(int i = 1; i <= n; ++i){
        for(int j = 1; j <= 3; ++j){
            for(int k = 1; k <= 3; ++k){
                if(j == k) continue;
                dp[i][j] = max(dp[i][j], dp[i - 1][k] + day[i][j]);
            }
        }
    }
    cout << max(dp[n][1], max(dp[n][2], dp[n][3]));
    return 0;
}


Measured memory_bytes: 3328
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")
 
#include <iostream>
#include <stdlib.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <assert.h>
#include <memory.h>
#include <time.h>
#include <bitset>
 
#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define ld long double
#define rep(i, l, r) for (int i = (l); i < (r); i++)
#define repb(i, r, l) for (int i = (r); i > (l); i--)
#define sz(a) (int)a.size()
#define fi first
#define se second
#define mp(a, b) make_pair(a, b)
#define rank qwertyuio
#define next dfghjk
#define plus fsghsf
#define minus ytryr
 
using namespace std;
 
inline bool setmin(int &x, int y) { return (y < x) ? x = y, 1 : 0; }
inline bool setmax(int &x, int y) { return (y > x) ? x = y, 1 : 0; }
inline bool setmin(ll &x, ll y) { return (y < x) ? x = y, 1 : 0; }
inline bool setmax(ll &x, ll y) { return (y > x) ? x = y, 1 : 0; }
 
const int N = 100000;
const int inf = (int)1e9 + 1;
const ll big = (ll)1e18 + 1;
const int P = 239;
const int P1 = 31;
const int P2 = 57;
const int MOD = (int)1e9 + 7;
const int MOD1 = (int)1e9 + 9;
const int MOD2 = 998244353;
const ld eps = 1e-12;
const double pi = atan2(0, -1);
const int ABC = 26;
 
void reverse_sub(string &s, int l, int r) {
    rep(i, 0, (r - l + 1) / 2) {
        swap(s[l + i], s[r - i]);
    }
}
 
int main()
{
    //freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);
    int shi;
    string s;
    cin>>shi>>s;
    int i;
    for(i=0;i<s.length();i++){
        s[i]=(s[i]+shi-'A')%('Z'-'A'+1)+'A';
    }
    cout<<s;

    return 0;
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
//#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>
#include<cctype>
#include<fstream>
 
 
#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LINF 1000000000000000000 //9000000000000000000
#define PI 3.14159265358979
#define MAXI 7500000
 
using namespace std;
typedef long long int ll;
typedef pair< long long int, long long  int> P;
 
int dy[5] = { 0,0,1,-1,0 };
int dx[5] = { 1,-1,0,0,0 };
 
int main(void){

	//ofstream ofs("./output");

	while(1){
		int n,m,t,p;
		int d[21],c[21];
		int x[21],y[21];
		int paper[70][70]={};//x,y
		int  count=0;

		FOR(i,0,69){
			FOR(j,0,69){
				paper[i][j]=0;
			}
		}

		cin>>n>>m>>t>>p;
		if(n==0&&m==0&&t==0&&p==0){
			break;
		}
		FOR(i,1,t){
			cin>>d[i]>>c[i];
		}
		FOR(i,1,p){
			cin>>x[i]>>y[i];
		}
		FOR(i,0,n-1){
			FOR(j,0,m-1){
				paper[i][j]=1;
			}
		}

		FOR(i,1,t){
			if(d[i]==1){
				FOR(j,1,c[i]){
					FOR(k,0,69){//y
						paper[c[i]+(c[i]-j)][k]+=paper[j-1][k];
					}
				}

				FOR(j,c[i],c[i]+69){//x
					FOR(k,0,69){//y
					if(j>69){
						paper[j-c[i]][k]=0;
					}else{
						paper[j-c[i]][k]=paper[j][k];
					}
						
					}
				}
				
				

			}else{
				FOR(j,1,c[i]){
					FOR(k,0,69){//x
						paper[k][c[i]+(c[i]-j)]+=paper[k][j-1];
					}
				}

				FOR(j,c[i],c[i]+69){//y
					FOR(k,0,69){//x
						if(j>69){
							paper[k][j-c[i]]=0;
						}else{
							paper[k][j-c[i]]=paper[k][j];
						}
						
					}
				}
			}

			/*if(i<=5){
				RFOR(r,69,0){
					FOR(s,0,69){
						cout<<paper[s][r]<<"";
					}
					cout<<endl;
				}
			cout<<endl;
			}*/
			

		}

		FOR(i,1,p){
			cout<<paper[x[i]][y[i]]<<endl;
			//ofs<<paper[x[i]][y[i]]<<endl;
		}

		/*RFOR(r,69,0){
			FOR(s,0,69){
				cout<<paper[s][r]<<"";
			}
			cout<<endl;
		}*/


		
	}

}


Measured memory_bytes: 3064