akhauriyash/Code-Regression huggingface dataset:
n = int(input())
s = input()

def check(a:list):
    for i in range(1,n):
        if a[i] == "S":
            if s[i] == "o":
                a.append(a[i-1])
            else:
                if a[i-1] == "S":
                    a.append("W")
                else:
                    a.append("S")
        if a[i] == "W":
            if s[i] == "o":
                if a[i-1] == "S":
                    a.append("W")
                else:
                    a.append("S")
            else:
                a.append(a[i-1])
    if a[0] != a[-1]:
        return 0
    else:
        a.pop()
        if a[1] == a[-1]:
            return "".join(a) if (a[0] == "S" and s[0] == "o") or (a[0] == "W" and s[0] == "x") else 0
        else:
            return "".join(a) if (a[0] == "S" and s[0] == "x") or (a[0] == "W" and s[0] == "o") else 0 

if check(["S","S"]):
    print(check(["S","S"]))
    exit()

if check(["S","W"]):
    print(check(["S","W"]))
    exit()

if check(["W","S"]):
    print(check(["W","S"]))
    exit()

if check(["W","W"]):
    print(check(["W","W"]))
    exit()

print(-1)


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

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	int n, m;
	cin >> n >> m;
	vector<pair<int, int>> jobs;
	for(int i = 0; i < n; i++) {
		int a, b;
		cin >> a >> b;
		jobs.emplace_back(a, b);
	}
	
	sort(jobs.begin(), jobs.end());
	long long ans = 0;
	
	priority_queue<int> pq;
	for(int d = m-1, i = 0; d >= 0; d--) {
		while(i < n && d + jobs[i].first <= m) {
			pq.push(jobs[i++].second);
		}
		if(pq.size()) {
			ans += pq.top();
			pq.pop();
		}
	}
	
	cout << ans << endl;
}


Measured memory_bytes: 1908
#include<stdio.h>

int main()
{
    int n,y,a,b,c;

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

    for(a=0;a<=n;a++){
        for(b=0;b<=n-a;b++){
            c=n-a-b;
            if(a*10000+b*5000+c*1000==y){
                printf("%d %d %d\n",a,b,c);
                return 0;
            }
        }
    }

    printf("-1 -1 -1\n");

    return 0;
}


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

using namespace std;

typedef long long ll;

long long test_cases;
int mod = 1e9 + 7;
int k;
string s;
int strings_size;
int total_strings;
int strings_no_s = 0;
vector <int> fact;
int powers[2001111];
int z = 26;
int ans;


int modoMulti(int a, int b, int mod) 
{ 
    int res = 0; 
  
    a %= mod; 
  
    while (b) 
    { 
        if (b & 1) 
            res = (res + a) % mod; 
        a = (2 * a) % mod; 
        b >>= 1;  
    } 
  
    return res; 
} 


void factorial(int x)
{
    while(fact.size() <= x)
    {   
        fact.push_back(modoMulti(fact[fact.size() - 1], fact.size(), mod));
    }
}


int modInverse(int a, int m) 
{ 
    int m0 = m; 
    int y = 0, x = 1; 
  
    if (m == 1) 
      return 0; 
  
    while (a > 1) 
    { 
        
        int q = a / m; 
        int t = m; 
  
        m = a % m, a = t; 
        t = y; 
   
        y = x - q * y; 
        x = t; 
    } 
  
    if (x < 0) 
       x += m0; 
  
    return x; 
} 


int pow(int x, int e) 
{
    if (e < 0) 
    {
        x = modInverse(x, mod);
        e *= -1;
    }
    if (e == 0)
        return 1;
    if ((e & 1) > 0)
        return modoMulti(x, pow(x, e - 1), mod);

    return pow(modoMulti(x, x, mod), e / 2);
}


int bino(int n, int r) 
{
                
    if (r < 0 || n < r)
        return 0;
    
    int den1 = fact[r];
    int den2 = fact[n - r];
    int den3 = modoMulti(den1, den2, mod);
    int den = modInverse(den3, mod);
    return modoMulti(fact[n], den, mod);

}


int addition(int a, int b, int p)
{
    return ((a % p) + (b % p)) % p;
}


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

    /* cin >> test_cases; */
    test_cases = 1;

    while (test_cases > 0)
    {

        cin >> k;
        cin >> s;
        
        strings_size = k + s.size();
        
        /* Armazenar todos os fatorias até n já em mod pra depois pegá-los em O(1) */
        fact.push_back(1);
        factorial(strings_size);

        /* Armazenar as potências de 25 */
        powers[0] = 1;
        for (int i = 0; i + 1 <= strings_size; i++) 
        {
            powers[i + 1] = modoMulti(powers[i], z - 1, mod);
        } 
        
        total_strings = pow(z, strings_size);
    
        for(int i = 0; i < s.size(); i++)
            strings_no_s = addition(strings_no_s, modoMulti(bino(strings_size, i), powers[strings_size - i], mod), mod);
        
        cout << ((total_strings - strings_no_s) % mod + mod) % mod <<"\n";
        test_cases--;
    }

    return 0;
}

Measured memory_bytes: 20192
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def divisors(n):
    # 約数列挙

    divisors = []

    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n // i)

    return set(divisors)


def main():
    from collections import Counter

    n = int(readline())
    a = list(map(int, readline().split()))
    counter = Counter(a)
    a.sort()
    mx = max(a)

    ok = [True] * (mx + 1)

    for x in a:
        for y in range(2 * x, mx + 1, x):
            ok[y] = False

    ans = 0
    prev = -1
    for key, val in counter.items():
        if val > 1:
            pass
        else:
            if ok[key]:
                ans += 1

    print(ans)


if __name__ == '__main__':
    main()


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

int main() {
	string s; cin >> s;
	int q; cin >> q;
	rep(i, q) {
		string t; cin >> t;
		if (t == "print") {
			int a, b; cin >> a >> b;
			cout << s.substr(a, b - a + 1) << endl;
		}
		if (t == "reverse") {
			int a, b; cin >> a >> b;
			reverse(s.begin() + a, s.begin() + b + 1);
		}
		if (t == "replace") {
			int a, b; string p; cin >> a >> b >> p;
			s.replace(a, b - a + 1, p);
		}
	}
}

Measured memory_bytes: 3192
#include<bits/stdc++.h>
using namespace std;
int n,d[100005],m[100005];
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&d[i]);
		if(i%2==1) m[1]+=d[i];
		else m[1]-=d[i];
	}
	printf("%d ",m[1]);
	for(int i=2;i<=n;i++){
		m[i]=2*d[i-1]-m[i-1];
		printf("%d ",m[i]);
	}
	return 0;
}

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

int main() {
  double a, b;
  b == 0;
  double c;
  cin >>a;
  
  for(int i=0; i<a; i++){
    if((i+1)%2==1){
      b = b+1;
    }
    else{
    }
  }
  c = b/a;
  cout <<c <<endl;
    
}

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

#include <math.h>
#include <stdlib.h>


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

template<class T> inline bool chmin(T &a, T b) { if(a > b){ a = b; return true; } return false; }
template<class T> inline bool chmax(T &a, T b) { if(a < b){ a = b; return true; } return false; }

//INT_MAX	2,147,483,647 = 2*1.0e9

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int A, B;
    cin >> A >> B;

    if(A <= 8 && B <= 8) cout << "Yay!" << endl;
    else cout << ":(" << endl;


    return 0;
}


Measured memory_bytes: 256
a,b,c,k=map(int,input().split())

ans =0

if k < a:
    print(k)
    exit()
else:
    ans+=a
    k-=a
    
    k-=b
    
    if k<=0:
        print(ans)
        exit()
    else:
        ans-=min(k,c)
        print(ans)
        exit()

Measured memory_bytes: 9212
import java. io.*;

class Main
{
	public static void main(String[] args) throws IOException
	{
	
	  BufferedReader br =
	   new BufferedReader(new InputStreamReader(System. in));
	   
	  String str = br.readLine();
	  int x = Integer.parseInt(str);
	  
	  //System.out.println( x^3);  //^???java??§???????????§?????????XOR???????????????
	  System.out.println( x*x*x );            // <= ??£?§£
	  //System.out.println( Math.pow(x,3) );  // Math.pow ???double???????????????
	  //System.out.println( (int)Math.pow(x,3) ); // <= ??£?§£
	  
	  }
}

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

int main() {
  int n, x, y, a;
  cin >> n >> x >> y;
  vector<int> num(n, 0);
  for (int i = 1; i <= n; i++)
    for (int j = i + 1; j <= n; j++)
      num[min(abs(j - i), abs(y - j) + abs(x - i) + 1)]++;

  for (int i = 1; i < n; i++) cout << num[i] << endl;
}


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

int main()
{
  int N;
  cin >> N;
  vector<int> V(N), C(N);
  for (int i = 0; i < N; i++)
  {
    cin >> V[i];
  }
  for (int i = 0; i < N; i++)
  {
    cin >> C[i];
  }
  int ans = 0;
  for (int bit = 0; bit < (1 << N); bit++)
  {
    int Xsum = 0;
    int Ysum = 0;
    for (int i = 0; i < N; i++)
    {
      if (bit & (1 << i))
      {
        Xsum += V[i];
        Ysum += C[i];
      }
    }
    ans = max(ans, Xsum - Ysum);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define PA pair<ll,ll>
#define FOR(I,A,B) for(ll I = int(A); I < int(B); ++I)
#define FORR(I,A,B) for(ll I = int((B)-1); I >= int(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e16+7;
const ll MOD=1e9+7;


//無向グラフ
// http://kagamiz.hatenablog.com/entry/2013/10/05/005213
struct Articulation_point_and_Bridge{
int V,E=0;
vector< vector<int> > G;
vector<int> ord,low;
vector<bool> vis;
vector< pair<int, int> > bridge;
vector<int> articulation;
Articulation_point_and_Bridge(int V_){
	V=V_;
	G.resize(V);
	ord.resize(V,0);
	low.resize(V,0);
	vis.resize(V,false);
}
void dfs(int v, int p, int &k){
	vis[v] = true;
	ord[v] = k++;
	low[v] = ord[v];
	bool isArticulation = false;
	int ct = 0;
	for (int i = 0; i < G[v].size(); i++){
		if (!vis[G[v][i]]){
			ct++;
			dfs(G[v][i], v, k);
			low[v] = min(low[v], low[G[v][i]]);
			if (~p && ord[v] <= low[G[v][i]]) isArticulation = true;
			if (ord[v] < low[G[v][i]]) bridge.push_back(make_pair(min(v, G[v][i]), max(v, G[v][i])));
		}
		else if (G[v][i] != p){
			low[v] = min(low[v], ord[G[v][i]]);
		}
	}
	
	if (p == -1 && ct > 1) isArticulation = true;
	if (isArticulation) articulation.push_back(v);
}
void add_edge(int v1,int v2){
	G[v1].push_back(v2);
	G[v2].push_back(v1);
	E++;
}
void calc(){
	int k=0;
	for(int i=0;i<V;i++){
		if(!vis[i])dfs(i,-1,k);
	}
	sort(bridge.begin(), bridge.end());
	sort(articulation.begin(), articulation.end());
}

};

int main(){
	int n,m;
	cin >> n >> m;
	Articulation_point_and_Bridge apb(n);
	FOR(i,0,m){
		int a,b;
		cin >> a >> b;
		apb.add_edge(a,b);
	}
	apb.calc();
	for(auto x:apb.bridge){
		cout << x.first << " " << x.second << endl;
	}
}


Measured memory_bytes: 4664
from sys import stdout
from collections import deque
printn = lambda x: stdout.write(str(x))
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 999999999
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

n,d,a = inm()
xh = []
for i in range(n):
    xx,hh = inm()
    xh.append((xx,(hh+a-1)//a))
xh.sort()
cnt = 0
q = deque([])
ad = 0
for i in range(n):
    h = xh[i][1]
    x = xh[i][0]
    while len(q)>0 and q[0][0]<x:
        z = q.popleft()
        ad -= z[1]
    h -= ad
    if h<=0:
        continue
    cnt += h
    ad += h
    q.append((x+2*d,h))
print(cnt)


Measured memory_bytes: 73176
N=int(input())
A=list(map(int,input().split()))
tot=sum(A)
cur=1
total=0
for d in range(N+1):
    if tot>=cur:
        total+=cur
    cur-=A[d]
    tot-=A[d]
    if cur<0:
        total=-1
        break
    cur=min(cur*2,tot)
print(total)    

Measured memory_bytes: 20140
#include<iostream>
#include<math.h>
#include<algorithm>
using namespace std;
int main()
{
  int64_t n,ans=10000000000000;
  cin>>n;
  for(int64_t i=1;i*i<=n;++i){
    if(n%i==0)
      ans=min(ans,i+n/i-2);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3596
import scala.io.{StdIn => in}
import scala.collection.{mutable => mu}

object Main extends App {
  val Array(n, c) = in.readLine.split(" ").map(_.toInt)
  val dcf = Iterator.continually(in.readLine)
    .take(c).map(_.split(" ").map(_.toInt)).toArray
  val pallet = Iterator.continually(in.readLine)
    .take(n).map(_.split(" ").map(_.toInt)).toArray

  val group = Array.fill(3)(mu.ArrayBuffer.empty[Int])
  for {
    i <- 0 until n
    j <- 0 until n
  } {
    val rem = (i + j) % 3
    group(rem) += pallet(i)(j)
  }
  // group.foreach(s => debug(s.mkString(" ")))
  val table = for(g <- group.indices) yield {
    for(i <- 0 until c) yield {
      group(g)./:(0)((acc, j) => acc + dcf(j-1)(i))
    }
  }

  // debug(table.mkString(" "))

  def dfsEnum(d:Int, n:Int):Int = {
    // d進 n個列挙
    val enum = Array.ofDim[Int](n)
    var ret = Int.MaxValue
  
    def evalute():Unit = {
      if(enum.toSet.size == 3) {
        val res = 
          enum.indices.map(i => table(i)(enum(i))).sum
        ret = math.min(ret, res)
        // debug(enum.mkString(" "), " ", res)
      }
    }
  
    def dfs(cnt:Int):Unit = {
      if(cnt == n) evalute
      else {
        for(i <- 0 until c) {
          enum(cnt) = i
          dfs(cnt+1)
        }
      }
    }
  
    dfs(0)
    ret
  }

  val ans = dfsEnum(c,3)
  println(ans)

  def debug(any:Any*):Unit = {
    if(this.getClass.toString != "class Main$")
      println(any.mkString(" "))
  }
}

Measured memory_bytes: 77336
n = int(input())
pn = list(map(int, input().split()))
cnt = 0
for i in range(n-2):
  p1, p2, p3 = pn[i:i+3]
  if p1 < p2 and p2 < p3:
    cnt += 1
  elif p3 < p2 and p2 < p1:
    cnt += 1
print(cnt)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define see(x) cerr<<#x<<"="<<x<<endl;
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
ll fast(ll x,ll n) {ll ans=1;for(;n;n>>=1,x=x*x%mod) if(n&1) ans=ans*x%mod; return ans;}
const int N=1e6+100;

int main() {
    ll x;
    cin>>x;
    int ok=0;
    while(x) {
        if(x%10==7) ok=1;
        x/=10;
    }
    printf("%s\n",ok?"Yes":"No");
}


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

using static Input;
using static Util;
class Program
{
    static int[] A, B;
    static int N, M, K;
    
    static void INPUT()
    {
        N = NextInt();
        M = NextInt();
        K = NextInt();
        A = LineInt();
        B = LineInt();
    }

    static void OUT()
    {
        var sa = new Stack<int>();
        var sb = new Queue<int>();
        foreach (var b in B)
            sb.Enqueue(b);

        long a = 0;
        var i = 0;
        var max = 0;
        while (i < N)
        {
            if (a + A[i] <= K)
            {
                a += A[i];
                sa.Push(A[i++]);
            }
            else break;
        }
        long k = K - a;
        while (sb.Any() && k >= sb.Peek())
        {
          k -= sb.Dequeue();
          i++;
        }
        max = i;
        while(sa.Any())
        {
            k += sa.Pop();
            i--;
            while (sb.Any() && k >= sb.Peek())
            {
                k -= sb.Dequeue();
                i++;
                max = Math.Max(max, i);
            }
        }

        Console.WriteLine(max);
    }

    static void Main(string[] args)
    {
#if DEBUG  
        //TESTINPUT();
        INPUT();

#else
        INPUT();
#endif
        OUT();
    }

    static void TESTINPUT()
    {
    }

}

public class Input
{
    public const long MOD = 1000000007;
    public const int INF = 1000000007;
    private static Queue<string> q = new Queue<string>();
    private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); }
    public static string NextString() { Confirm(); return q.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
}

class Util
{
}


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

#define rep(i, e) for (int i = 0; i < e; i++)
#define repp(i, s, e) for (int i = s; i < e; i++)
#define N_Max 100
#define Card_Max 36
#define p(a) printf("%d\n", a);
#define ll long long

template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}

const long long INF = 1LL << 60;

int main()
{
    string s;
    cin >> s;
    if (s == "Sunny")
    {
        cout << "Cloudy" << endl;
    }
    else if (s == "Cloudy")
    {
        cout << "Rainy" << endl;
    }
    else
    {
        cout << "Sunny" << endl;
    }
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<typename T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<typename T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef tuple<ll,ll,ll> tlll;
typedef tuple<int,int,int> tiii;
const ll mod=1e9+7;
const int inf=1<<30;

int main(){
  int k; cin >> k;
  queue<ll> q;
  for(int i=1;i<10;i++) q.push(i);
  int cnt=0;
  while(1){
    int x=q.front()%10;
    if(x!=0) q.push(10*q.front()+x-1);
    q.push(10*q.front()+x);
    if(x!=9) q.push(10*q.front()+x+1);
    cnt++;
    if(cnt==k){
      cout << q.front() << endl;
      return 0;
    }
    q.pop();
  }
  
}

Measured memory_bytes: 1792
import java.util.Scanner;

public class Main{
    private static final int MOD = 1000000007;

    public static void main(String[] args){
        long[] fac = new long[8001];
        long[] inv = new long[8001];
        long[] fiv = new long[8001];
        fac[0]=fac[1]=fiv[0]=fiv[1]=inv[1]=1;
        for(int i=2;i<=8000;i++){
            fac[i] = fac[i - 1] * i % MOD;
            inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
            fiv[i] = fiv[i - 1] * inv[i] % MOD;
        }

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        int[] b = new int[n];
        int[][] p = new int[4002][4002];
        for(int i=0;i<n;i++){
            a[i] = sc.nextInt();
            b[i] = sc.nextInt();
            p[2001-a[i]][2001-b[i]]++;
        }
        for(int i=1;i<4002;i++)for(int j=1;j<4002;j++){
            p[i][j]+=p[i-1][j]+p[i][j-1];
            p[i][j]%=MOD;
        }
        long ans = 0L;
        for(int i=0;i<n;i++){
            ans+=(long)p[2001+a[i]][2001+b[i]];
            ans%=MOD;
        }
        long dbl = 0L;
        for(int i=0;i<n;i++){
            dbl+=(fac[2*a[i]+2*b[i]])*(fiv[2*a[i]]*fiv[2*b[i]]%MOD)%MOD;
            dbl%=MOD;
        }
        System.out.println(((ans-dbl+MOD)%MOD)*inv[2]%MOD);
    }
}

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

using namespace std;
using ll = long long;
using P = pair<int, int>;
#define all(c) (c).begin(), (c).end()
const int INF = 1e9 + 1;
const ll LINF = 1e18 + 1;
const ll MOD = 1e9 + 7;

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

  int n, t;
  cin >> n >> t;
  vector<P> dishes(n);

  for (int i = 0; i < n; ++i) {
    cin >> dishes[i].first >> dishes[i].second;
  }
  vector<int> dp1(t + 1, 0), dp2(t + 1, 0);  // dp1/2:ラストオーダー未指定/指定済み

  for (int i = 0; i < n; ++i) {
    int a, b;
    tie(a, b) = dishes[i];
    vector<int> dpt(t + 1, 0);
    for (int j = 0; j < t + 1; ++j) {
      dpt[j] = dp1[j] + b;
    }
    for (int j = t; j >= 0; --j) {
      if (j >= a) dp1[j] = max(dp1[j], dp1[j - a] + b);
      if (j >= a) dp2[j] = max(dp2[j], dp2[j - a] + b);
      dp2[j] = max(dp2[j], dpt[j]);
    }
  }
  // dump(dp1);
  // dump(dp2);
  cout << dp2[t - 1] << endl;
  return 0;
}


Measured memory_bytes: 384
import math
N = int(input())
S = input()
mod = 10**9+7
if(not (S[0]==S[-1]=='B')):
    print(0)
else:
    d = []
    cumu = [[0]*2 for _ in range(N*2)]
    cnt = 1
    for ind,s in enumerate(S):
        if(ind==0):
            d.append(0)
            cumu[0][0]+=1
        else:
            if(S[ind-1]==s):
                d.append(1-d[-1])
            else:
                d.append(d[-1])
            cumu[ind][0] = cumu[ind-1][0]
            cumu[ind][1] = cumu[ind-1][1]
            cumu[ind][d[-1]]+=1
            if(d[-1]==1):
                cnt *= (cumu[ind-1][0]-cumu[ind-1][1])
                cnt %= mod
    if(cumu[-1][0]!=cumu[-1][1]):
        cnt=0
    print((math.factorial(N)*cnt)%mod)


Measured memory_bytes: 34128
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
using pii = pair<ll, ll>;
using vi = vector<ll>;
using vvi = vector<vi>;
using vb = vector<bool>;
using vs = vector<string>;
using vp = vector<pii>;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(x) (ll)((x).size())
#define all(x) (x).begin(), (x).end()
#define each(a, x) for (auto&& a : (x))
#define _overload3(_1, _2, _3, name, ...) name
#define rep1(n) rep2(_, n)
#define rep2(i, n) rep3(i, 0, n)
#define rep3(i, a, n) for (ll i = (a); i < (n); ++i)
#define rep(...) _overload3(__VA_ARGS__, rep3, rep2, rep1)(__VA_ARGS__)
const int INF = 1e9;
const int MOD = 1e9 + 7;
const double EPS = 1e-9;
const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
template<typename T> inline void print(const T& x) {cout << x << "\n";}
template<typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;}
template<typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;}
struct Init {Init() {cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10);}} init;

int main() {
    ll n, q;
    cin >> n >> q;
    fenwick_tree<ll> fw(n);
    rep(i, n) {
        ll a;
        cin >> a;
        fw.add(i, a);
    }
    rep(q) {
        ll t;
        cin >> t;
        if (t == 0) {
            ll p, x;
            cin >> p >> x;
            fw.add(p, x);
        }
        else {
            ll l, r;
            cin >> l >> r;
            print(fw.sum(l, r));
        }
    }
}

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

int main()
{
  valarray<int> a(5), b(5);
  for (auto&& e : a) cin >> e;
  b = (a + 9) / 10 * 10;
  cout << b.sum() - (b - a).max() << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll INF =ll(1e18)+5;

int main() {
    ll N;
    cin >> N;
    vector<ll> A(N);
    for(int i=0;i<N;i++){
        cin >> A[i];
    }
    ll ans = INF;
    {
        //正負と続いていくもの
        ll sum =0;
        ll temp =0;
        for(int i=0;i<N;i++){
            sum += A[i];
            if(i%2==0){
                if(sum<=0){
                    temp += (1-sum);
                    sum =1;
                }
            }else{
                if(sum>=0){
                    temp += (sum+1);
                    sum =-1;
                }
            }
        }
        ans = min(ans,temp);


    }
    {
        //逆
        ll sum =0;
        ll temp =0;
        for(int i=0;i<N;i++){
            sum += A[i];
            if(i%2==1){
                if(sum<=0){
                    temp += (1-sum);
                    sum = 1;
                }
            }else{
                if(sum>=0){
                    temp += (sum+1);
                    sum = -1;
                }
            }
        }
        ans = min(ans,temp);
    }
    cout << ans << endl;

    return 0;
}

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

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int[] input = Arrays.stream(scanner.next().split("")).mapToInt(Integer::parseInt).toArray();
		int[] mask = new int[input.length - 1];
		for(int i = 0 ; i < mask.length; i++) mask[i] = (int)Math.pow(2, i);
		long subT = 0;
		long total = 0;
		for(int i = 0; i < (int)Math.pow(2, input.length -1); i++) {
			subT = input[0];
			for(int j = 0; j < mask.length; j++) {
				if((mask[j] & i) > 0) {
					total += subT;
					subT = input[j + 1];
				} else {
					subT *= 10;
					subT += input[j + 1];
				}
			}
			total += subT;
		}
		System.out.println(total);
	}
}


Measured memory_bytes: 26836
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll N=3001;
ll dp[N][N];string a,b;
int main(){
    //Normal lazy string dp would'nt work in this
    //have to use back-pointer compulsorily for this
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    cin>>a>>b;
    for(ll i=1;i<=a.length();i++){
        for(ll j=1;j<=b.length();j++){
            if(a[i-1]==b[j-1]){
                dp[i][j]=1+dp[i-1][j-1];
            }
            else{
                dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
            }       
        }
    }
    string ans;
    ll i=a.length(),j=b.length();
    //cout<<dp[i][j]<<"\n";
    while(i>0 && j>0){
        //cout<<i<<" "<<j<<" "<<dp[i][j]<<"\n";
        if(dp[i][j]==dp[i][j-1]){
            j--;
        }
        else if(dp[i][j]==dp[i-1][j]){
            i--;
        }
        else{
            ans.push_back(a[i-1]);
            i--;
        }
    }

    reverse(ans.begin(),ans.end());
    cout<<ans<<"\n";
    return 0; 
}

Measured memory_bytes: 70656
using System;

class Program
{
    static void Main(string[] args)
    {
        int N = int.Parse(Console.ReadLine());
        long psum = 0,r;
        int[] A = new int[N];
        int[] B = new int[N];

        for(int i = 0; i < N; i++)
        {
            string[] input = Console.ReadLine().Split(' ');
            A[i] = int.Parse(input[0]);
            B[i] = int.Parse(input[1]);
        }

        for(int i = N - 1; i >= 0; i--)
        {
            r = (A[i]+psum)%B[i];
            if(r!=0)psum += B[i] - r;
        }

        Console.WriteLine(psum);

    }
}

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

using namespace std;

// Repetitions
#define FOR(i,a,n) for(ll i = ((ll) a); i < ((ll) n); ++i)
#define FORR(i, s, g) for(ll i = ((ll)s - 1); i >= ((ll) g); --i)
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) FORR(i, n, 0)

// Container Utils
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define SORTALL(v) sort(ALL(v))
#define SZ(a) int((a).size())
#define CLR(a) memset((a), 0 ,sizeof(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())

// For Debug
#define DMP(x)  cerr << #x << " = " << (x) << endl
#define DBG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

// Aliases
#define PB push_back
#define MP make_pair
using ll = long long;
using ld = long double;
using str = string;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vs = vector<str>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vpii = vector<pii>;
using vpll = vector<pll>;

// Constant variables
const ld PI = (acos(-1));
const ll MOD = 1000000007;

// I/O Asynchronizing
struct __io_async{
    __io_async(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);
    };
};

int main() {
    int a, b;
    cin >> a >> b;
    int ans = -1;
    FOR(i, min(a / 0.08, b / 0.1), max((a + 1) / 0.08, (b + 1) / 0.1)) {
        if((int)(i * 0.08) == a && (int)(i * 0.1) == b) {
            ans = i;
            break;
        }
    }
    cout << ans << "\n";
    return 0;
}


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

// @author : sam000013

#define int long long
#define PI 3.14159265
#define fi(i,start,end) for(int i=0; i<n; i++)
#define pb(x) push_back(x)
#define int long long
#define PI 3.14159265
#define all(v) v.begin(), v.end()
#define endl cout<<"\n" 
#define ll long long
#define dbg(x) cout<<#x<<" "<<x;endl;
#define bye endl;return
#define uni 1.000000
using namespace std;

int mod = 1000000007;
template<typename T>

void debug(vector<T> x){
    for(auto e:x){
        cout<<e<<" ";
    }
    cout<<"\n";
}
/*
1
8 6
1 2 4 1 2 4 1 2

*/
bool isValid(int i, int j, int n, int m){
    return (i>=0 && i<n && j>=0 && j<m);
}
vector<int> dx = {0,0,1,-1};
vector<int> dy = {1,-1,0,0};

void solve(){

    int h,w;
    cin>>h>>w;
    int ch, cw;
    cin>>ch>>cw;
    int dh, dw;
    cin>>dh>>dw;
    ch--,cw--,dh--,dw--;
    vector<vector<char>> maze(h, vector<char>(w));
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++)
            cin>>maze[i][j];
    }
    deque<tuple<int, int , int>> q;
    q.push_front(make_tuple(ch, cw, 0));
    vector<vector<bool>> vis(h, vector<bool>(w));
    int m,c,r;
    while(!q.empty()){
        tie(c,r,m) = q.front();
        // cout<<c<<" "<<r<<" "<<m;endl;
        q.pop_front();
        if(vis[c][r])   continue;
        vis[c][r] = 1;
        if(c==dh && r==dw){
            cout<<m;bye;
        }
        for(int i=0; i<4; i++){
            int nc = c+dx[i], nr = r +dy[i];
            if(isValid(nc, nr, h, w) && !vis[nc][nr] && maze[nc][nr]=='.'){
                // cout<<"No magic nc: "<<nc<<" nr: "<<nr;endl;
                q.push_front(make_tuple(nc, nr, m));
            }
        }
        for(int i=-2; i<=2; i++){
            for(int j=-2; j<=2; j++){
                int nc = c+i, nr = r+j;
                if(isValid(nc, nr, h, w) && !vis[nc][nr] && maze[nc][nr]=='.'){
                    q.push_back(make_tuple(nc, nr, m+1));
                    // cout<<"nc: "<<nc<<" nr: "<<nr;endl;
                }
            }
        }
    }
    cout<<-1;bye;



}

signed main(){
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int t = 1;
    // cin>>t;
    for(int i=1; i<=t; i++){
        solve();
    }
    return 0;
}


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

enum Color {
	WHITE,
	GRAY,
	BLACK,
};

class dfs {
public:
	dfs(bool matrixT[][100], Color colorT[], int ts_F[], int ts_L[], int verNum) {
		for (int i = 0; i < verNum; i++) {
			for (int j = 0; j < verNum; j++)
				matrixTable[i][j] = matrixT[i][j];
		}
		verNumber = verNum;
	}

	void DFS(int nowVerVal) {
		colorTable[nowVerVal] = GRAY;
		++ttl;
		ts_first[nowVerVal] = ttl;

		for (int nextVer = 0; nextVer < verNumber; nextVer++) {
			if (matrixTable[nowVerVal][nextVer] == false) continue;
			if (colorTable[nextVer] != WHITE) continue;
			DFS(nextVer);
		}
		colorTable[nowVerVal] = BLACK;
		++ttl;
		ts_last[nowVerVal] = ttl;
	}

	void DFS_Init() {
		ttl = 0;
		for (int i = 0; i < verNumber; i++)
			colorTable[i] = WHITE;

		for (int i = 0; i < verNumber; i++)
			if (colorTable[i] == WHITE) DFS(i);
	}

	void print() {
		for (int i = 0; i < verNumber; i++) {
			cout << i + 1 << " " << ts_first[i] << " " << ts_last[i] << endl;
		}
	}
private:
	bool matrixTable[100][100];
	Color colorTable[100];
	int ts_first[100];
	int ts_last[100];
	int verNumber;
	int ttl;
};

int main() {
	int verNum; //num??????????????°???value????????????????????????????????¨???
	bool matrixTable[100][100]; //???????????¨??????????????????
	Color colorTable[100];
	int timeStamp_first[100];
	int timeStamp_last[100];
	cin >> verNum;

	for (int i = 0; i < verNum; i++)
		for (int j = 0; j < verNum; j++) {
			matrixTable[i][j] = false;
		}

	for (int i = 0; i < verNum; i++) {
		int verVal, nextVerNum;
		cin >> verVal >> nextVerNum;
		for (int j = 0; j < nextVerNum; j++) {
			int nextVerVal;
			cin >> nextVerVal;
			//0?????????????????´???
			matrixTable[verVal - 1][nextVerVal - 1] = true;
		}
	}

	dfs* d = new dfs(matrixTable, colorTable, timeStamp_first, timeStamp_last, verNum);
	d->DFS_Init();
	d->print();

	return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF 1e16
#define mod 1000000007

int H,N,Q;
int a[200010],b[200010];
int crt[200010];

int getplace(int i,int j,bool f){
  int rev=(i/N)%2;
  int rest=i%N;
  int res=-1;
  if(j==0){
    res=2*(rest/2) + 1;
  }else if(j==N-1){
    res=2*((N-1-rest)/2);
  }else{
    if((j-1)%2==rest%2){ // left
      if(j>=rest+1)res=j-rest-1;
      else res=getplace(i-j,0,false);
    }else{ // right
      if(j+rest+1<N)res=j+rest+1;
      else res=getplace(i-(N-1-j),N-1,false);
    }
  }
  return f&&rev?N-1-res:res;
}

vector<int> qs[200010];
int res[200010];

int main(){
  cin>>H>>N>>Q;
  rep(i,Q){
    cin>>a[i]>>b[i];
    a[i]--; b[i]--;
    qs[a[i]].push_back(b[i]);
  }
  rep(i,N)crt[i]=i;

  rep(i,H){
    for(int q : qs[i]){
      swap(crt[getplace(i,q,true)],crt[getplace(i,q+1,true)]);
    }
  }

  rep(i,N)res[crt[getplace(H-1,i,true)]]=i;
  rep(i,N)cout<<res[i]+1<<endl;

  return 0;
}



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

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef pair<LL, LL> PLL;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())

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

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

class UnionFind{
private:
  vector<int> par, rank;
public:
  UnionFind(int n){
	par.assign(n, 0);
	rank.assign(n, 0);
	for(int i=0;i<n;++i)
	  par[i] = i;
  }

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

  void unite(int x, int y){
	x = find(x);
	y = find(y);
	if(x == y) return;

	if(rank[x] < rank[y])
	  par[x] = y;
	else{
	  par[y] = x;
	  if(rank[x] == rank[y])
		++rank[x];
	}
  }

  bool same(int x, int y){
	return find(x) == find(y);
  }
};

struct Edge{
  int to;
  LL cost;

  Edge(int t, LL c): to(t), cost(c)
  {}
  bool operator>(const Edge& rhs) const{
	return cost > rhs.cost;
  }
  bool operator<(const Edge& rhs) const{
	return cost < rhs.cost;
  }

};
typedef vector< vector<Edge> > Graph;

// 無向グラフのとき
void add_edge(Graph& graph, int u, int v, LL cost){
  graph[u].push_back(Edge(v,cost));
  graph[v].push_back(Edge(u,cost));
}

vector<pair<Edge,int>> edges;
LL kruskal(const Graph& G, Graph& G_){
  int N = SZ(G);
  UnionFind uf(N);

  LL res = 0, i, n = 0;
  for(i=0;i<SZ(edges);++i){
	auto& e = edges[i].first;
	int v = edges[i].second;
	if(!uf.same(e.to,v)){
	  uf.unite(e.to, v);
	  res += e.cost;
	  add_edge(G_, e.to, v, e.cost);
	}
  }
  return res;
}

LL dist[4010][4010];
void dfs(int s, int p, int u, LL mx, Graph& G){
  dist[s][u] = dist[u][s] = max(dist[s][u], mx);
  for(auto& e: G[u]){
	if(e.to == p) continue;
	dfs(s, u, e.to, max(mx,e.cost), G);
  }
}

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

  int N, M; cin >> N >> M;
  Graph G(N), G_(N);
  REP(i,M){
	int a, b, c; cin >> a >> b >> c;
	--a; --b;
	add_edge(G, a, b, c);
	edges.push_back(MP(G[a].back(), a));
	edges.push_back(MP(G[b].back(), b));
  }
  sort(ALL(edges));

  LL mx = kruskal(G,G_);
  REP(i,N) dfs(i,-1,i,0,G_);
  int Q; cin >> Q;
  while(Q--){
	LL s,t; cin >> s >> t;
	--s, --t;

	cout << mx - dist[s][t] << endl;
  }

  return 0;
}


Measured memory_bytes: 165284
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;

#define repr(i, n) for(int i = n; i >= 0; i--)
#define reprl(i, n) for(ll i = n; i >= 0; i--)
#define all(v) v.begin(), v.end()

const ll mod=1000000007;

int countBits(int in){
  int res=0;
  for(int i=0;i<10;i++){
    int msk=1<<i;
    if((in&msk)!=0){
      res++;
    }
  }
  return res;
}

template<typename T>
void show2dVector(vector<vector<T>>& v){
  for(int i=0;i<v.size();i++){
    int m=v[i].size();
    cout<<i<<" : ";
    for(int j=0;i<m;i++){
      cout<<v[i][j]<<" ";
    }
    cout<<endl;
  }
}

void bfs(const vector<vector<int>>&g, int v, vector<bool>& seen){
  seen[v]=true;
  cout<<v<<" ";
  for(auto next: g[v]){
    if(seen[next]){
      continue;
    }
    bfs(g,next,seen);
  }
}

bool dfs(vector<vector<int>> &g,int start,int goal,vector<bool>&seen){
  bool res=false;
  seen[start]=true;
  if(start==goal){
    return true;
  }
  for(auto next: g[start]){
    if(seen[next]){
      continue;
    }
    res=dfs(g,next,goal,seen);
    if(res){
      break;
    }
  }
  return res;
}

ll gcd(ll a,ll b) {
  return b? gcd(b,a%b): a;  
}
ll lcm(ll a,ll b) {
  return a*b/gcd(a,b);
}
bool isLowerCase(char c){
  return (c>='a'&&c<='z');
}
const string outputYesNo(bool ans){
  return (ans?"Yes":"No");
}
int main() {
  ll x;cin>>x;
  ll val=100;
  int ans=0;
  while(val<x){
    ans++;
    val+=val/100;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3640
n, k = map(int, input().split())

ans = 0
lis = [0] *(10**5 +1)

for i in range(n):
    a, b = map(int, input().split())
    lis[a] += b

tmp = 0
for j in range(len(lis)):
    tmp += lis[j]
    if tmp >= k:
        print(j)
        break

Measured memory_bytes: 11700
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
int A[2000010];
int C[100010];

int main (){
	int n;
	cin>>n;
	for(int i=0;i<100000;i++) C[i]=0;
	for(int i=0;i<n;i++) {
		cin>>A[i];
		C[A[i]]++;
	}
	int flag=0;
	for(int i=0;i<100000;i++){
		for(int j=C[i];j>0;j--) if(flag) {
			cout<<" "<<i;
			flag++;
		}
		else {cout<<i;flag++;}
	}
	cout<<endl;
	return 0;
}


Measured memory_bytes: 11200
N = int(input())
A = list(map(int, input().split()))



dps = [False for _ in range(N + 1)]

ans =[]
#半分までは確定
fs = N // 2
for i in reversed(range(1, N + 1)):
    d_index = i * 2
    current_sum = 0
    while d_index <= N:
        if dps[d_index]:
            current_sum += 1
        d_index += i

    if current_sum % 2 == A[i-1]:
        dps[i] = False
    else:
        dps[i] = True


ans=[]
for i in range(1, N+1):
    if dps[i]:
        ans.append(i)


print(len(ans))
if len(ans) != 0:
    print(" ".join(map(str, ans)))




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


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

    ll n, q, index, l, r, count = 0;
    char c;
    string s;
    cin>>n>>s>>q;
    set <ll> se[26];

    loop(n) se[s[i]-'a'].insert(i);

    int x;
    while(q--){
        cin>>x;
        if(x==1){
            cin>>index>>c;
            index--;
            if(s[index]==c) continue;
            se[s[index]-'a'].erase(index);
            se[c-'a'].insert(index);
            s[index] = c;
        }
        else{
            count = 0;
            cin>>l>>r;
            l--; r--;
            loop(26){
                if(se[i].lower_bound(l) != se[i].end() && *se[i].lower_bound(l)<=r){
                    count++;
                }
            }
            cout<<count<<"\n";
        }
    }
    
    return 0;
}

Measured memory_bytes: 24220
import java.util.*;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(sc.hasNext()){
			int n = sc.nextInt();
			String[] s = new String[n];
			int[] m = new int[n];
			
			for(int i=0;i<n;i++){
				s[i] = sc.next();
				m[i] = sc.nextInt();
			}
			
			int a = 0;
			for(int i=0;i<n;i++){
				if(s[i].codePointAt(0)==40){
					a += m[i];
				}else{
					a -= m[i];
				}
				if(a<0){
					break;
				}
			}
			if(a==0){
				System.out.println("YES");
			}else{
				System.out.println("NO");
			}
			
		}
	
	}	
}

Measured memory_bytes: 24956
function Main(input) {
    var ab = input.split('\n')[0].split(' ');
    var a = parseInt(ab[0], 10);
    var b = parseInt(ab[1], 10);

    var towers = [];
    
    for (var i = 1, n = 0 ; i <= 999 ; ++i) {
        n += i;
        towers.push(n);
    }

    var t1 = towers[b-a-2];

    console.log(t1 - a);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

#define mp make_pair
#define pb push_back
#define ll long long

const int maxN = 6011;

int n, i, last, act;
char s[maxN];
vector<string> data;
vector<int> a, b;
int id[maxN];
string ans, aux;

string solve(int bg, int en) {
    string ans = "";
    string aux;
    int i, j, last;

    a.clear();
    b.clear();
    for (i = bg; i <= en; i++) {
        if (s[i] == 'a')
            a.pb(i), id[i] = a.size() - 1;
        else
            b.pb(i), id[i] = b.size() - 1;
    }

    if (s[bg] == 'a') {
        last = 0;
        for (i = 0; i < a.size(); i++) {
            if (a[i] <= last) continue;
            ans += "ab";
            last = b[i];
        }
    } else {
        for (i = 0; i < a.size(); i++) {
            aux.clear();
            for (j = bg; j <= en; j++)
                if (id[j] >= i)
                    aux.pb(s[j]);


            if (aux > ans) ans = aux;
        }
    }

    return ans;
}

int main()
{
    //freopen("test.in","r",stdin);

    scanf("%d\n%s", &n, s + 1);
    for (i = 1; i <= 2 * n; i++) {
        if (s[i] == 'a')
            act++;
        else
            act--;

        if (act == 0) {
            data.pb(solve(last + 1, i));
            last = i;
        }
    }

    ans = "";
    for (i = data.size() - 1; i >= 0; i--) {
        aux = data[i] + ans;
        if (aux > ans) ans = aux;
    }

    cout << ans;

    return 0;
}


Measured memory_bytes: 512
import std.algorithm, std.array, std.container, std.range, std.bitmanip;
import std.numeric, std.math, std.bigint, std.random, core.bitop;
import std.string, std.conv, std.stdio, std.typecons;

void main()
{
  while (true) {
    auto rd = readln.split.map!(to!int);
    auto x = rd[0], y = rd[1];
    if (x == 0 && y == 0) break;
    if (x > y) swap(x, y);
    writeln(x, " ", y);
  }
}

Measured memory_bytes: 2396
#include<bits/stdc++.h>
#define INF 1000000000LL
using namespace std;
typedef long long ll;
ll S;
int main()
{
    scanf("%lld",&S);
    ll need=(S+INF-1)/INF*INF-S;
    printf("0 0 %lld %lld %lld %lld\n",1LL,INF,(S+need)/INF,need);
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
//using System.Text;
//using System.Text.RegularExpressions;
//using System.Globalization;
//using System.Diagnostics;
using static System.Console;
//using System.Numerics;
//using static System.Math;
//using pair = Pair<int, int>;

class Program
{
    static void Main()
    {
        //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().solve();
        Out.Flush();
    }
    Scanner cin = new Scanner();
    readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑
    readonly int mod = 1000000007;
    void chmax<T>(ref T a, T b) where T : IComparable<T> { a = a.CompareTo(b) < 0 ? b : a; }
    void chmin<T>(ref T a, T b) where T : IComparable<T> { a = a.CompareTo(b) < 0 ? a : b; }

    void solve()
    {
        int N = cin.nextint;
        int X = cin.nextint;
        var A = cin.scanint;
        Array.Sort(A);
        int cnt = 0;
        for (int i = 0; i < N; i++)
        {
            X -= A[i];
            if(X < 0)
            {
                WriteLine(cnt);
                return;
            }
            cnt++;
        }
        if (X == 0)
        {
            WriteLine(cnt);
        }
        else
        {
            WriteLine(cnt - 1);
        }
    }

}

class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan { get { return ReadLine().Split(); } }
    public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } }
    public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } }
    public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } }
    public string next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next;
        }
    }
    public int nextint { get { return int.Parse(next); } }
    public long nextlong { get { return long.Parse(next); } }
    public double nextdouble { get { return double.Parse(next); } }
} 

Measured memory_bytes: 11220
n = int(input())
a_ls = list(map(int, input().split()))
if n > 2:
    a_ls.sort()
    num_total = a_ls[-1]
    a_ls.pop()
    def isOK(index, key, l):
        if l[index] >= key:
            return True
        else:
            return False
    def meguru_search(l, key):
        '''
        key以上の値を持つ最小のインデックスを返す
        '''
        left = -1
        right = len(l)

        while (right - left) > 1:
            mid = left + (right - left) // 2
            # 直感的に記憶　
                # 「含まれている」んだったら「含むを許容（等号付き）する右側」はmidまで動かして問題ない
                    # 新しいrightの位置がkeyの位置だとしても、「含む」は許容されてる
                # 「含まれていない」んだったら「含まない(<)左の壁」をそこまで動かしてもkeyを通り過ぎることはない
            if isOK(mid, key, l):
                right = mid
            else:
                left = mid
        
        # whileを抜ける時、rightとleftは一個差で、かつkeyがrightの位置にある
        return right

    if num_total % 2 == 0:
        Max = num_total // 2
    else:
        Max = num_total // 2 + 1
    Maxind1 = meguru_search(a_ls, Max)
    Maxind2 = Maxind1 - 1
    abs_1 = abs(Max - a_ls[Maxind1])
    abs_2 = abs(Max - a_ls[Maxind2])
    if abs_1 > abs_2:
        r = a_ls[Maxind2]
    else:
        r = a_ls[Maxind1]
    print(num_total, r)
else:
    print(max(a_ls), min(a_ls))
        


Measured memory_bytes: 14428