akhauriyash/Code-Regression huggingface dataset:
Str = input()
q = int(input())
for i in range(q):
    order = list(input().split())
    o = order[0]
    a = int(order[1])
    b = int(order[2])
    
    if o=='print':
        print(Str[a:b+1])
    
    if o=='reverse':
        StrL = list(Str)
        t = list(Str[a:b+1])
        j = len(t)-1
        for i in range(a,b+1):
            StrL[i] = t[j]
            j -= 1
        Str = ''.join(StrL)
    
    if o=='replace':
        p = list(order[3])
        StrL = list(Str)
        j = 0
        for i in range(a,b+1):
            StrL[i] = p[j]
            j += 1
        Str = ''.join(StrL)


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

ll ans;
int D, G;
vector<int> p, c;
ll min_solve(int i, int sum, string flag, ll solved){
    if(i == D - 1){
        if(sum >= G){
            ans = min(ans, solved);
            return ans;
        }
        else{
            int memo;
            rep(j, D){
                int m = flag[j] - '0';
                if (m == 0) memo = j;
            }
            if(sum + 100 * (memo + 1) * p.at(memo) < G){
                return ans;
            }
            else{
                float memo2 =(G - sum);
                memo2 /= (100 * (memo + 1));
                ll memo1 = solved + ceil(memo2);
                ans = min(ans, memo1);
                return ans;
            }
            return ans;
        }
    }
    min_solve(i + 1, sum, flag + "0", solved);
    min_solve(i + 1, sum + 100 * (i + 2) *p[i+1] + c[i+1], flag + "1",solved + p.at(i + 1));
    return ans;
}
int main(){
    cin >> D >> G;
    rep(i, D){
        p.emplace_back(0);
        c.emplace_back(0);
        cin >> p[i] >> c[i];
    }
    ll a;
    ans = 99999999999;
    a = min_solve(0, 0, "0", 0);
    ans = 99999999999;
    a = min(a, min_solve(0, 100 * p[0] + c[0], "1", p[0]));
    cout << a << endl;
    return 0;
}

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

using namespace std;
typedef long long ll;
typedef vector<ll> vel;
typedef vector<string> ves;
typedef vector<int> vei;
typedef vector<vector<ll>> vvel;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REP(a, b, m) for (ll a = (ll)(b); a < (ll)(m); a++)

int main() {
    ll n;cin>>n;
    vel L(n);
    ll ans=0;
    rep(i,n) {
        cin>>L[i];
    }
    rep(i,n) {
        rep(j,n) {
            rep(k,n) {
                if(i==k||j==k||i==j||L[i]==L[j]||L[i]==L[k]||L[j]==L[k]) {
                    continue;
                }
                else {
                    if(L[i]+L[j] > L[k] && L[i]+L[k] > L[j] && L[k]+L[j] > L[i])
                    {
                        ans++;
                    }
                }
            }
        }
    }
    cout<<ans/6<<endl;
}

Measured memory_bytes: 3628
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;

int main() {
	string s;
	while (cin >> s) {
		if (s == "0000")break;
		int n[4] = { s[0] - '0',s[1] - '0',s[2] - '0',s[3] - '0' };
		int ans = 0;
		if (n[0] == n[1] && n[2] == n[3] && n[1] == n[2]) {
			ans = -1;
		}
		else {
			while (1) {
				if (n[0] == 6 && n[1] == 1 && n[2] == 7 && n[3] == 4)break;
				sort(n, n + 4);
				int na[4];
				na[0] = n[3] - n[0];
				na[1] = n[2] - n[1];
				na[2] = n[1] - n[2];
				na[3] = n[0] - n[3];
				for (int i = 0; i < 4; i++)n[i] = na[i];
				if (n[3] < 0) {
					n[3] += 10;
					n[2] --;
				}
				if (n[2] < 0) {
					n[2] += 10;
					n[1]--;
				}
				if (n[1] < 0){
					n[1] += 10;
					n[0]--;
				}
				ans++;
			}
		}
		if (ans == -1)cout << "NA" << endl;
		else cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3132
#include<bits/stdc++.h>
#define ios std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
typedef long long ll;
using namespace std;
int main(){
    ios;
	ll a,b,k;
	cin>>a>>b>>k;
	if( a>=k ) {  cout<<a-k<<' '<<b<<endl;      }
	else cout<<0<<' '<<max((ll)0,( b+a-k ))<<endl; 
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,m,k,i,count=0;
    cin>>n>>m>>k;
    vector<long long int>a,b;
    a.push_back(0);
    for(i=1;i<=n;i++)
    {
        long long int x;cin>>x;
        a.push_back(a[i-1]+x);
    }
    long long int x;cin>>x;
    b.push_back(x);
    for(i=1;i<m;i++)
    {
        cin>>x;
        b.push_back(b[i-1]+x);
    }
    long long int ans=0;
    for(i=0;i<=n;i++)
    {
        count=k-a[i];
        if(count<0)
        {
            break;
        }
        long long int idx=upper_bound(b.begin(),b.end(),count)-b.begin();
        ans=max(ans,i+idx);
    }
    cout<<ans;
}


Measured memory_bytes: 7988
import java.util.Scanner;


public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			int n = sc.nextInt();
			int m = sc.nextInt();
			if(n+m==0)break;
			int[] t = new int[n+1];
			int sumt = 0;
			for(int i=1;i<=n;i++) {
				t[i] = sc.nextInt();
				sumt += t[i];
			}
			
			int[] h = new int[m+1];
			int sumh = 0;
			for(int i=1;i<=m;i++) {
				h[i]  = sc.nextInt();
				sumh += h[i];
			}
			
			int Git=101;int Gih=101;
			for(int i=1;i<=n;i++){
				for(int j=1;j<=m;j++) {
					if(sumt-t[i]+h[j] == sumh-h[j]+t[i] && Git+Gih > t[i]+h[j]) {
						Git=t[i];
						Gih=h[j];
					}
				}
			}
			if(Git + Gih == 202)
				System.out.println("-1");
			else System.out.println(Git + " " + Gih);
			
		}
		
	}
}


Measured memory_bytes: 29528
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
	long long n, b, c = 0, e = 2;
	cin >> n >> b;
	c = min(n, b / 2);
	b = b - c * 2;
	if (b >= 1) {
		c += b / 4;
	}
	cout << c << endl;
	cin >> e;
}

Measured memory_bytes: 256
N = int(input())
Vn = list(map(int, input().split()))
Cn = list(map(int, input().split()))
 
X = 0
Y = 0
for i, d in enumerate([v - c for v, c in zip(Vn, Cn)]):
    
    if(d >= 0):
        X += Vn[i]
        Y += Cn[i]
print(X - Y)

Measured memory_bytes: 3064
import sys
input = sys.stdin.readline
N, M = map(int, input().split())

INF = 1<<30
dp = [INF]*(1<<N)
dp[0] = 0

K = []
for _ in [0]*M:
    a, b = map(int, input().split())
    *C, = map(int, input().split())
    h = 0
    for c in C:
        h ^= 1 << (c-1)
    
    for i in range(1<<N):
        nxt = i|h
        dp[nxt] = min(dp[nxt], dp[i]+a)

ans = dp[(1<<N)-1]
print(-1 if ans == INF else ans)


Measured memory_bytes: 74364
n, m = map(int, input().split())

students = [list(map(int, input().split())) for _ in range(n)]
checkpoints = [list(map(int, input().split())) for _ in range(m)]

for a, b in students:
    min_distance = float("inf")
    min_checkpoint = 0
    for i, cd in enumerate(checkpoints):
        c, d = cd
        if abs(c - a) + abs(d - b) < min_distance:
            min_checkpoint = i + 1
            min_distance = abs(c - a) + abs(d - b)
    print(min_checkpoint)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
typedef long long ll;
typedef pair<ll,ll> pint;
ll gcd(ll a,ll b){
    if(b==0){
        return a;
    }
    else{
        return gcd(b,a%b);
    }
}

int main(){
    ll n;cin>>n;
    string a;cin>>a;
    vector<vector<int> > res(4,vector<int>(n,0));
    int flag=-1;
    if(a[0]=='o'){
        res[0][0]=0;
        res[0][1]=0;
        res[0][n-1]=0;
        
        res[1][0]=0;
        res[1][1]=1;
        res[1][n-1]=1;
        
        res[2][0]=1;
        res[2][1]=1;
        res[2][n-1]=0;
        
        res[3][0]=1;
        res[3][1]=0;
        res[3][n-1]=1;
        
    }
    else{
        res[0][0]=0;
        res[0][1]=1;
        res[0][n-1]=0;
        
        res[1][0]=0;
        res[1][1]=0;
        res[1][n-1]=1;
        
        res[2][0]=1;
        res[2][1]=1;
        res[2][n-1]=1;
        
        res[3][0]=1;
        res[3][1]=0;
        res[3][n-1]=0;
    }
    rep(j,4)REP(i,1,n-1){
        if (-1<flag)continue;
        if(i!=n-2){
            if(a[i]=='o'&&res[j][i]==0){
                res[j][i+1]=res[j][i-1];
            }
            else if(a[i]=='o'&&res[j][i]==1){
                res[j][i+1]=(res[j][i-1]+1)%2;
            }
            else if(a[i]=='x'&&res[j][i]==0){
                res[j][i+1]=(res[j][i-1]+1)%2;
            }
            else if(a[i]=='x'&&res[j][i]==1){
                res[j][i+1]=res[j][i-1];
            }
        }
        else{
            if(a[i]=='o'&&res[j][i]==0){
                if(res[j][i+1]==res[j][i-1]){
                    flag=j;
                }
            }
            else if(a[i]=='o'&&res[j][i]==1){
                if(res[j][i+1]==(res[j][i-1]+1)%2){
                    flag=j;
                }
            }
            else if(a[i]=='x'&&res[j][i]==0){
                if(res[j][i+1]==(res[j][i-1]+1)%2){
                    flag=j;
                }
            }
            else if(a[i]=='x'&&res[j][i]==1){
                if(res[j][i+1]==res[j][i-1]){
                    flag=j;
                }
            }
        }
        if(-1<flag){
            if(res[j][n-1]==0){
                if(a[n-1]=='o'&&res[j][n-2]!=res[j][0]){
                    flag=-1;
                }
                else if(a[n-1]=='x'&&res[j][n-2]==res[j][0]){
                    flag=-1;
                }
            }
            else{
                if(a[n-1]=='o'&&res[j][n-2]==res[j][0]){
                    flag=-1;
                }
                else if(a[n-1]=='x'&&res[j][n-2]!=res[j][0]){
                    flag=-1;
                }
            }
        }
    }
    if(-1<flag){
    rep(k,n){
        if(res[flag][k]==0){
            cout<<'S';
        }
        else{
            cout<<'W';
        }
    }cout<<endl;
    }
    else{
        cout<<-1<<endl;
    }
}

Measured memory_bytes: 2432
import java.io.*;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.*;

public class Main {
    static Input in = new Input(System.in);
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) {
        int H = in.nextInt();
        int W = in.nextInt();
        int K = in.nextInt();
        boolean[][] black = new boolean[H][W];
        for (int h = 0; h < H; h++) {
            String str = in.next();
            for (int w = 0; w < W; w++)
                black[h][w] = (str.charAt(w) == '#');
        }

        int ans = 0;
        boolean[] bh = new boolean[H + 1];
        while (!bh[H]) {
            boolean[] bw = new boolean[W + 1];
            while(!bw[W]) {
                int blacks = 0;
                for (int h = 0; h < H; h++) if (bh[h])
                    for (int w = 0; w < W; w++) if (bw[w])
                        if (black[h][w]) blacks++;
                if (blacks == K)
                    ans++;
                int i = -1;
                do {
                    i++;
                    bw[i] = !bw[i];
                } while (!bw[i]);
            }
            int i = -1;
            do {
                i++;
                bh[i] = !bh[i];
            } while (!bh[i]);
        }
        out.println(ans);

        out.flush();
    }

    static class Input {
        private BufferedReader br;
        private String[] buff;
        private int index = 0;

        Input(InputStream is) {
            br = new BufferedReader(new InputStreamReader(is));
        }
        String nextLine() {
            try {
                return br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return null;
        }
        String next() {
            while (buff == null || index >= buff.length) {
                buff = nextLine().split(" ");
                index = 0;
            }
            return buff[index++];
        }
        byte nextByte() {
            return Byte.parseByte(next());
        }
        short nextShort() {
            return Short.parseShort(next());
        }
        int nextInt() {
            return Integer.parseInt(next());
        }
        long nextLong() {
            return Long.parseLong(next());
        }
        float nextFloat() {
            return Float.parseFloat(next());
        }
        double nextDouble() {
            return Double.parseDouble(next());
        }
        BigInteger nextBigInteger() {
            return new BigInteger(next());
        }
        BigDecimal nextBigDecimal() {
            return new BigDecimal(next());
        }
    }
}



Measured memory_bytes: 34152
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main(N):
    ans = N * (N + 1) // 2

    for n in range(1,N+1):
        for i in range(2*n, N+1, n):
            ans += i

    print(ans)


if __name__ == "__main__":
    N = int(readline())
    main(N)


Measured memory_bytes: 73096
#include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 1000000000
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);

  int N, a, am = INF, ap = -INF;

  std::cin >> N;

  for (int i = 0; i < N; i ++) {
    std::cin >> a;

    am = std::min(a, am);
    ap = std::max(a, ap);
  }

  std::cout << ap - am << std::endl;

  return 0;
}


Measured memory_bytes: 256
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
//問題文および制約はちゃんと確認しよう！
//サイズは10^5じゃなくて2×10^5とかかもしれないし、重要な制約・条件を見落としているかも
//とりあえずサンプルを読んでから解法を考えよう？
int main()
{
	int a;cin>>a;cout<<(a+1)/2<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>

int main(){
  int i,j,k;
  
  char S[100];
  
  scanf("%s",S);
  
  for(i=0;i<strlen(S);i++){
    for(j=0;j<i;j++){
      if(S[j] == S[i]){
        puts("no");
        return 0;
      }
    }
  }
  
  puts("yes");
  return 0;
}

Measured memory_bytes: 128
n,m = map(int, input().split())
A = [list(map(int, input().split())) for i in range(n)]
b = list(int(input()) for i in range(m))
for i in range(n) :
    c = 0
    for j in range(m) :
        c += A[i][j] * b[j]
    print(c)



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

int main() {
    int N;
    cin >> N;
    int d[N];
    int ans;
    rep(i,N){
        cin >> d[i];
    }
    vector<int> v;
    rep(i,N){
        v.push_back(d[i]);
    }
    sort(v.begin(), v.end());
    
    
    ans = v[(N/2)] - v[(N/2)-1];
    
    if(ans > 0){
        cout << ans << endl;
    }else{
        cout << 0 << endl;
    }
    
    return 0;
}


Measured memory_bytes: 1276
s = input()
N = s.count('N')
S = s.count('S')
E = s.count('E')
W = s.count('W')
if ((N >= 1 and S == 0) or (N == 0 and S >= 1) or 
    (E >= 1 and W == 0) or (E == 0 and W >= 1)):
  print('No')
else:
  print('Yes')


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}
#ifdef __LOCAL
#define debug(x) cerr << __LINE__ << ": " << #x << " = " << x << endl
#define debugArray(x, n)                             \
  cerr << __LINE__ << ": " << #x << " = {";          \
  for (long long hoge = 0; (hoge) < (n); ++(hoge)) { \
    cerr << ((hoge) ? "," : "") << x[hoge];          \
  }                                                  \
  cerr << "}" << endl
#else
#define debug(x) (void(0))
#define debugArray(x, n) (void(0))
#endif

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long X;
  cin >> X;
  long long ans = X / 500 * 1000 + (X % 500) / 5 * 5;
  cout << ans << endl;
  return 0;
}


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

#define FOR(i, j, n) for (int i(j); i < n; ++i)
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define dbg(x) std::cerr<<#x<<" = " << (x) << std::endl
#define pnl(x) std::cout << x << "\n"

typedef	std::vector<int>	vi;
typedef std::pair<int,int>	ii;
typedef std::vector<std::string>	vs;
typedef std::vector<ii>	vii;
typedef std::vector<long long>	vl;
typedef	long long ll;


int		main(void)
{
	std::ios_base::sync_with_stdio(false);
	int	X, A, B;
	std::cin >> X >> A >> B;

	pnl((X - A) % B);
}



Measured memory_bytes: 256
using System;

public class Program
{
  public static void Main(string[] args)
  {
    int[,,] univ;
    univ = new int[4,3,10];
    for(int b = 0;b < 4;b++)
    {
      for(int f = 0;f < 3;f++)
      {
        for(int r = 0;r < 10;r++)
        {
          univ[b,f,r] = 0;
        }
      }
    }
    int num_of_info = int.Parse(Console.ReadLine());
    for(int i = 0;i < num_of_info;i++)
    {
      string[] info = Console.ReadLine().Split(' ');
      int tmp_b = int.Parse(info[0]) - 1;
      int tmp_f = int.Parse(info[1]) - 1;
      int tmp_r = int.Parse(info[2]) - 1;
      int visitor = int.Parse(info[3]);
      univ[tmp_b,tmp_f,tmp_r] += visitor;
    }
    for(int b = 0;b < 4;b++)
    {
      for(int f = 0;f < 3;f++)
      {
        for(int r = 0;r < 10;r++)
        {
          Console.Write(" " + univ[b,f,r]);
        }
        Console.WriteLine();
      }
      if(b != 4 - 1){
        Console.WriteLine("####################");
      }
    }
  }
}

Measured memory_bytes: 9136
#include<bits/stdc++.h>
using namespace std;
#define SORT(c) sort((c).begin(),(c).end());
#define pb push_back
#define MP make_pair
#define pii pair<int,int>
#define pcc pair<char,char>
#define pic pair<int,char>
#define pci pair<char,int>
#define VS vector<string>
#define VI vector<int>
#define pi 3.141592653589793
#define ll long long
#define ull unsigned long long
#define w(x) int x;cin>>x;while(x--)
#define fast ios_base::sync_with_stdio(0)
#define sz size()
typedef unsigned long long UL;
template<typename T>inline T  S(T a)
{
    return a*a;
}
template<class T>inline string tostring(T a)
{
    ostringstream os("");
    os << a;
    return os.str();
}
template<typename T>inline ll tolong(T a)
{
    ll res;
    istringstream os(a);
    os>>res;
    return res;
}
template<typename T>inline T gcd(T a, T b)
{
    if (b == 0)return a;
    else return gcd(b, a % b);
}
template<typename T>inline T bigmod(T a, T b, T m)
{
    if (b == 0)return 1;
    else if (b % 2 == 0)return S(bigmod(a, b / 2, m)) % m;
    else return (a % m*bigmod(a, b - 1, m)) % m;
}
const int inf = (int)1e9 + 5;
const ll linf = (ll)1e16 + 5;
const ll modd = (ll)1e9 + 7;
const int mod = 10000007;
/*#define N 20000009
bool prime[N];
vector<ll> prm;
void seive ()
{

    memset(prime, true, sizeof(prime));

    for( ll i=2; i*i<=N; i++)
    {
        if (prime[i] == true)
        {
            prm.pb(i);
            for (ll j=i*i; j<=N; j += i)
                prime[j] = false;
        }
    }
}*/
void pr (int f)
{
    if(f==1)
        cout<<"YES\n";
    else
        cout<<"NO\n";
}
map<string,string>ma;
set<int > s;
multiset<string> :: iterator it;

deque <char> q ;
ll ar [55100];
int main()
{
    fast;
     int n,k,x,y;
     cin>>n>>k>>x>>y;
     int ans= 0;
     for(int i=0;i<n;i++)
     {
         if(k)
         {
             ans+=(x);
             k--;
         }
         else
            ans+=y;
     }
     cout<<ans<<endl;

}




Measured memory_bytes: 3672
import sys
input = sys.stdin.readline
n, k = map(int,input().split())
A = list(map(int,input().split()))

D = [0] * (k+1)
for i in range(k+1):
    safe = 0
    for j in range(n):
        if i-A[j] >= 0 and D[i-A[j]] == 0:
            safe = 1
    D[i] = safe

print("First" if D[-1]==1 else "Second")

Measured memory_bytes: 74148
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
#define INF (1 << 30)
struct SegmentTree{
private:
  ll dat[1 << 18];
  int n;
public:
  SegmentTree(){}
  SegmentTree(int size){
    n = 1;
    while(n < size) n *= 2;
  }
  ll getSize(){
    return n;
  }
  ll getSeg(int s){
    return dat[s];
  }
  void update(int i,ll x){
    i += n - 1;
    dat[i] = x;
    while(i > 0){
      i = ( i - 1 ) / 2;
      dat[i] = max( dat[i * 2 + 1] , dat[i * 2 + 2]);
    }
  }
  ll query(int a,int b,int k,int l,int r){
    if(r <= a || b <= l) return 0;
    if(a <= l && r <= b) return dat[k];
    ll vl = query(a,b,k*2+1,l,(l+r)/2);
    ll vr = query(a,b,k*2+2,(l+r)/2,r);
    return max(vl,vr);
  }
};
int main(){
  int n;
  ll ans = 0;
  cin >> n;
  SegmentTree BIT(n);
  for(int i = 0 , x ; i < n ; i++ ){
    cin >> x;
    BIT.update( x , BIT.query(1,x+1,0,0,BIT.getSize()) + x );
    ans = max( ans , BIT.getSeg( x + BIT.getSize() - 1));
  }
  cout << ((ll)n * (ll)(n + 1) / 2 - ans) << endl;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;

bool is_triangle(int a, int b, int c) {
    if (a == b || b == c || c == a) return false;

    return (a + b > c) && (b + c > a) && (c + a > b); 
}

void solve() {
    int n;
    cin >> n;
    vi v;
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        v.push_back(x);
    }

    int cnt = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            for (int k = j + 1; k < n; k++) {
                // cout << i << " " << j << " " << k << endl;

                if (is_triangle(v[i], v[j], v[k])) 
                    cnt++;
            }
        }
    }
    cout << cnt << endl;
}

int main() {
    // For fast I/O
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int T;
    T = 1;
    // cin >> T;
    while (T--) {
        solve();
    }

    return 0;
}

Measured memory_bytes: 3652
using System;
using System.Collections.Generic;//list用
using System.Text;//StringBuilder用
using System.Collections;//ハッシュテーブル用
using System.Linq;

class Program
{
    //Hashtable ht = new Hashtable();
    static List<int> s = new List<int>();
    static List<int>[] sl;
    static decimal result;
    static decimal N,K;
    //StringBuilder strresult= new StringBuilder("");//Append(str ○○)関数で文字を追加していく
    static List<decimal> res =new List<decimal>();

    static void Main()
    {
        //Modular mo = new Modular(0);//素数で割った余りを出せで使う。()内が初期値。★使い方：Modular型で宣言すると、その時点でのその素数で割った余りを保持する変数になる（powべき乗、Fac累乗、nCr組み合わせも関数として存在）
        //Node<> no = new Node<>();//UnionFind★Find関数で根っこの値を返す（根っこの値が一緒なら同グループ）、Unite関数で二つの木をくっつける
        //Permutation<> pe = new Permutation<>();//配列＆リストを並べ替えた場合の全ケースを出力★All関数でリスト形式で返す。
        //Treap<> tr = new Treap<>();//平衡二分木★Insert()関数で挿入、FindIndex()関数で該当する大きさの物が入るべき配列番号を返す。
        //PriorityQueue<int,int> pr = new PriorityQueue<int,int>();//優先度付キュー★Add(key,value)で格納、Dequeue()で取りだし。keyが小さいものから取り出す。
Read4();
//最大公約数出して、それの素な約数の数を……
      decimal tmp=Gcd((long)N,(long)K);
PF(tmp);
      result++;
        Console.WriteLine(result.ToString());

    }
public static void PF(decimal n)
    {
        decimal i = 2;
        decimal tmp = n;

        while (i * i <= n) //※1
        {
          a1:
            if(tmp % i == 0){
                tmp /= i;
              for(int j=0;j<res.Count;j++){if(res[j]==i){goto a1;}}
              res.Add(i);
                result++;
            }else{
                i++;
            }
        }
        if(tmp != 1) result++;//最後の素数も返す
    }
  
static long Gcd(long a, long b)
{
    var v = new[] { a, b };
    while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
    return v[0];
}
  
    static void Read1()//1項
    {
        string tmp = Console.ReadLine();
        N = int.Parse(tmp);
    }

    static void Read2()//複数項（項目数Ｎ）
    {
        string[] tmp = Console.ReadLine().Split(' ');
        for (int i = 0; i < N; i++) { s.Add(int.Parse(tmp[i])); }
    }
    static void Read3()//1行複数項
    {
        string[] tmp = Console.ReadLine().Split(' ');
        for (int i = 0; i < tmp.Length; i++) { s.Add(int.Parse(tmp[i])); }
    }
    static void Read4()//NK１行
    {
        string[] tmp = Console.ReadLine().Split(' ');
        N = decimal.Parse(tmp[0]);
        K = decimal.Parse(tmp[1]);
    }
    static void Read5()//N行K項
    {


    }
}



Measured memory_bytes: 13396
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <utility>
#include <bitset>
using namespace std;
using ll = long long;

constexpr int lim = 18;

int main(){
  int n; cin >> n;
  string s; cin >> s;

  map<pair<string, string>, ll> mp;

  for(int i=0; i< (1 << n); i++){
    bitset<lim> bit(i);
    string red = "", blue = "";
    for(int b=0; b < n; b++){
      if(bit[b]){
        red += s[b];
      }
      else{
        blue += s[b];
      }
    }
    mp[{red, blue}]++;
  }

  ll ans = 0;

  for(int i=0; i< (1 << n); i++){
    bitset<lim> bit(i);
    string red = "", blue = "";
    for(int b=0; b < n; b++){
      if(bit[b]){
        red += s[2 * n - b - 1];
      }
      else{
        blue += s[2 * n - b - 1];
      }
    }
    ans += mp[{red, blue}];
  }
 
  cout << ans << endl;

  return 0;
}

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

enum inf = 10L^^15;
enum mod = 10L ^^ 9 + 7;

void main() {
    int n;
    scan(n);
    auto a = readln.split.to!(int[]);

    auto dp = new long[][][](n + 1, n + 1, 2);
    fillAll(dp, -1);

    long dfs(int l, int r, int p) {
        if (dp[l][r][p] != -1) {
            return dp[l][r][p];
        }
        if (r - l == 1) {
            return dp[l][r][p] = (-1)^^p * a[l];
        }
        dp[l][r][p] = (p ? min(dfs(l, r-1, p^1) - a[r-1], dfs(l+1, r, p^1) - a[l]) : 
                           max(a[r-1] + dfs(l, r-1, p^1), a[l] + dfs(l+1, r, p^1)));
        return dp[l][r][p];
    }

    auto ans = dfs(0, n, 0);

    debug {
        foreach (l ; 0 .. n) {
            foreach (r ; 0 .. n) {
                foreach (p ; 0 .. 2) {
                    if (dp[l][r][p] != -1) {
                        stderr.writefln("%d, %d, %d = %d", l, r, p, dp[l][r][p]);
                    }
                }
            }
        }
    }

    writeln(ans);
}







void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}


void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

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

void main() {
    int n, w;
    scan(n, w);

    auto dp = new int[](w + 1);

    foreach (i ; 1 .. n + 1) {
        int val, wei, m;
        scan(val, wei, m);

        for (int k; m > 0; k++) {
            int take = min(m, 1<<k);
            m -= take;

            foreach_reverse (j ; take * wei .. w + 1) {
                dp[j] = max(dp[j], dp[j - take * wei] + val * take);
            }
        }
    }

    writeln(dp[w]);
}


void scan(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

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

typedef long long ll;

#define        optimize           ios::sync_with_stdio(0); cin.tie(0);
#define PI    acos(-1.0)
#define pb push_back
#define YES cout<<"YES"<<endl;
#define NO cout<<"NO"<<endl;
#define RESET(a, b) memset(a, b, sizeof(a))
#define pii pair <int, int>
#define pll pair <ll, ll>
#define setbiti(x) __builtin_popcount(x)
#define setbitll(x) __builtin_popcountll(x)
#define gcd(a, b) __gcd(a, b)

#define        MX        200005
int ara[105];
int main()
{
    optimize
    int n;
    cin>>n;
    int sum = 0;
    int l = 105, r = -105;
    for(int i = 0; i < n; i++){
        cin>>ara[i];
        l = min(ara[i], l);
        r = max(ara[i], r);
    }
    int ans;
    for(int i = l; i <= r; i++){
        int cur = 0;
        for(int j = 0; j < n; j++){
            cur += ((ara[j]-i)*(ara[j]-i));
        }
        if(i == l) ans = cur;
        ans = min(ans, cur);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3636
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.NoSuchElementException;

public class Main {

	void run() {
		FastScanner sc = new FastScanner();
		int M = sc.nextInt();
		long[] d = new long[M];
		long[] c = new long[M];
		long sum = 0;
		long len = 0;
		for (int i = 0; i < M; ++i) {
			d[i] = sc.nextLong();
			c[i] = sc.nextLong();
			sum += c[i] * d[i];
			len += c[i];
		}
		System.out.println((sum - 1) / 9 + (len - 1));
		// sum-9a>0
		// len-b>0
		// max(a+b)?
	}

	public static void main(String[] args) throws FileNotFoundException {
		new Main().run();
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
	}

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

Measured memory_bytes: 25528
#include <iostream>
#include <utility>
#include <stdio.h>
#include <math.h>
#include <algorithm>
#include <vector>
#define llint long long
#define mod 998244353
#define eps 1e-8

using namespace std;

const int FACT_MAX = 200005;
llint fact[FACT_MAX], fact_inv[FACT_MAX];

llint modpow(llint a, llint n)
{
	if(n == 0) return 1;
	if(n % 2){
		return ((a%mod) * (modpow(a, n-1)%mod)) % mod;
	}
	else{
		return modpow((a*a)%mod, n/2) % mod;
	}
}

void make_fact()
{
	llint val = 1;
	fact[0] = 1;
	for(int i = 1; i < FACT_MAX; i++){
		val *= i;
		val %= mod;
		fact[i] = val;
	}
	fact_inv[FACT_MAX-1] = modpow(fact[FACT_MAX-1], mod-2);
	for(int i = FACT_MAX-2; i >= 0; i--){
		fact_inv[i] = fact_inv[i+1] * (i+1) % mod;
	}
}

llint comb(llint n, llint k)
{
	llint ret = 1;
	ret *= fact[n];
	ret *= fact_inv[k], ret %= mod;
	ret *= fact_inv[n-k], ret %= mod;
	return ret;
}

llint comb2(llint n, llint k)
{
	llint ret = 1;
	for(int i = 0; i < k; i++) ret *= (n-i)%mod, ret %= mod;
	for(int i = 1; i <= k; i++) ret *= modpow(i, mod-2), ret %= mod;
	return ret;
}

llint m, n, k;

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> m >> n >> k;
	make_fact();
	
	llint ans = 0;
	for(int i = 1; i <= min(m, k-1); i++){
		llint sum = 0;
		for(int j = 0; j <= i-1; j++){
			llint tmp = comb(i, j) * modpow(i-j, n) % mod;
			if(j % 2 == 0) sum += tmp, sum %= mod;
			else sum += mod - tmp, sum %= mod;
		}
		sum *= comb2(m, i), sum %= mod;
		ans += sum, ans %= mod;
	}
	ans = modpow(m%mod, n) - ans + mod, ans %= mod;
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 6340
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
template<typename T>vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
/*
 <url:https://atcoder.jp/contests/abc172/tasks/abc172_d>
 問題文============================================================
 D - Sum of Divisors
 =================================================================
 解説=============================================================
 ================================================================
 */

template<class Type>
Type solve(Type res = Type()){
    ll N; cin >> N;
    
    vector<ll> f(N+1);
    for(ll x = 1; x <= N; x++){
        
        // ここの処理はO(1)でも求めれる
        for(int m = 1; x*m <= N; m++){
            f[x*m] += x*m;
        }
        
        
        res += f[x];
    }
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    // solve(0);
    cout << fixed << setprecision(15) << solve<ll>() << endl;
    return 0;
}


Measured memory_bytes: 81352
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define Sort(Array) sort(Array.begin(), Array.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define out(ans) cout << ans << endl;
const int MOD = 1000000007;
const int INF = 2147483647;
const ld PI = 3.14159265358979323846;

//------------↓------------- M -------------- E ---------------- M --------------- O ---------------↓--------------//
// コンパイル 
// g++ -std=c++1z
//
// -------型変換--------
// int を string に変換
// string s = to_string(n);
// string を int に変換
// int n = stoi(s);
//
// -------二分探索---------
// k以上の値が最初に現れる時のイテレータ
// lower_bound(data.begin(), data.end(), k)
// kより大きい値が最初の現れる時のイテレータ O(logN)
// upper_bound(data.begin(), data.end(), k)
// kがdataに存在するかをtrue or falseで返す O(logN)
// binary_search(data.begin(), data.end(), k)
// 
//
//
//
//
//
// 
//------------↑------------- M -------------- E ---------------- M --------------- O ---------------↑--------------//

ll modadd(long long a, long long b){return (a%MOD+b%MOD+MOD)%MOD;}
ll modmul(long long a, long long b){return a%MOD*b%MOD%MOD;}
ll modexp(long long a, long long n){if (a==0) return 0; if(n==0)return 1; if(n%2==0){ll e=modexp(a,n/2); return modmul(e,e);} return modexp(a,n-1)*a%MOD;}
ll modinv(long long n){return modexp(n%MOD,MOD-2);}
ll modfact(long long n){long long res=1; for (int i=1; i <= n; ++i){res *= i; res %= MOD;} return res;}
ll modncr(long long n, long long r){long long numer=1;long long denom=1;for(int i=1;i<=r;++i){numer=modmul(numer,n-r+i);denom=modmul(denom,i);}return modmul(numer, modinv(denom));}



int main(void) {

    ll N, K; cin >> N >> K;
    ll ans = 0;
    for (ll i = K; i <= N+1; ++i) {
        ans = modadd(ans, i * (2*N - i + 1) / 2 - i * (i - 1) / 2 + 1);
    }    
    out(ans);
    
    return 0;
}









Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //ai>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //ai>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define REV(x) (reverse(x.begin(),x.end())) //reverse
#define TO(x,t,f) ((x)?(t):(f))
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define FILV(x,a) fill(x.begin(),x.end(),a)
#define FILA(ar,N,a) fill(ar,ar+N,a)
#define NEXTP(x) next_permutation(x.begin(),x.end())
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;else 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 pb push_back
#define pri(aa) cout<<(aa)<<endl
#define mp(x,y) make_pair(x,y)
#define fi first
#define se second
const ll INF=1e18+7;
const ll MOD=1e9+7;
const ll N = 1007;
class UnionFind{
public:
	vector<int> par;
	//0-indexed
	void init(int n = 1) {
		par.resize(n);
		for (int i = 0; i < n; ++i) par[i] = i;
	}
	int root(int x = 1){
		if(par[x]==x)return x;
		else{
			return par[x] = root(par[x]);
		}
	}
	void unite(int x = 1,int y = 1){
		x = root(x);
		y = root(y);
		if(x==y)return;
		else par[x] = y;
	}
};
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n,m;
	cin>>n>>m;
	UnionFind uf;
	uf.init(n);
	FOR(i,0,m){
		ll x,y;
		cin>>x>>y;
		uf.unite(x,y);
	}
	ll q;
	cin>>q;
	FOR(i,0,q){
		ll x,y;
		cin>>x>>y;
		if(uf.root(x)==uf.root(y)){
			pri("yes");
		}else{
			pri("no");
		}
	}
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n, cnt = 0;
    cin >> n;
    vector<int> l(n);
    for (int i = 0; i < n; i++)
    {
        cin >> l[i];
    }
    sort(l.begin(), l.end());
    for (int i = 0; i < n - 2; i++)
    {
        for (int j = i + 1; j < n - 1; j++)
        {
            for (int k = j + 1; k < n; k++)
            {
                if (l[i] != l[j] && l[j] != l[k] && l[k] != l[i] && l[i] + l[j] > l[k])
                {
                    cnt++;
                }
            }
        }
    }
    cout << cnt << endl;
}

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

using namespace std;

const int  N = 200;

int n;
int a[2][N];

int main(){

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

	for(int i = 1; i <= n; ++i){
		a[1][i] += a[1][i - 1];
	}

	int ans = 0;

	for(int i = n; i >= 1; --i){
		a[2][i] += a[2][i + 1];
		ans = max(ans, a[1][i] + a[2][i]);
	}

	cout << ans;

	return 0;
}

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


vector<int>a;

int N;
bool prime[2000];


void mul(int x){
    int up=0;
    for(int i=0;i<a.size()-1;i++){
        a[i]=a[i]*x+up;
        up=a[i]/10;
        a[i]%=10;
    }
}

void add(int x){
    int up=x;
    for(int i=0;i<a.size();i++){
        a[i]+=up;
        up=a[i]/10;
        a[i]%=10;
    }
}

void print(){
    int pos=0;
    for(int i=0;i<a.size();i++)if(a[i])pos=i;
    for(int i=pos;i>=0;i--)cout<<a[i];cout<<endl;
}

int main(){
    scanf("%d",&N);
    a.resize(5000,0);
    a[0]=1;

    fill_n(prime,2000,true);
    prime[0]=prime[1]=false;
    for(int i=2;i<2000;i++){
        if(!prime[i])continue;
        for(int j=i*2;j<2000;j+=i)prime[j]=false;
    }

    for(int i=2;i<2000;i++)if(prime[i])mul(i);

    add(2);
    print();

    for(int i=2;i<N+2;i++){
        for(int j=2;j<=i;j++)if(i%j==0){
            cout<<j<<endl;
            break;
        }
    }
    return 0;
}

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

using namespace std;

#define int long long

#ifndef bhupixb
    #define var(...)
    #define stl(...)
#endif

#define single_test

void solve() {
    int d, t, s;
    cin >> d >> t >> s;
    double taken = d / (double)s;
    if (taken <= t) {
        cout << "Yes" << '\n';
    }
    else {
        cout << "No" << '\n';
    }
}

signed main() {
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t = 1;
    #ifndef single_test
        cin >> t;
    #endif
    for (int i = 1; i <= t; ++i) {
        // cout << "Case #" << i << ": ";
        solve();
    }

    return 0;
}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
#define REP(i,n) for(int i=1;i<=n;i++)
using namespace std;
int main(){
    int D=0,N,X,ans=0;
    cin>>N>>X;
    vector<int> ma(N+1,0);
    for(int i=1;i<=N;i++)cin>>ma[i];
    REP(i,N+1){
        int tD=0;
        if(i!=0) tD = D + ma[i-1];
        if(tD <= X)ans++;
        D=tD;
    }
    cout<<ans<<endl;
}

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

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

const int MAX = 1e5 + 10;
const int INF = 1e9;
const int MOD = 1e9 + 7;

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

ll b[MAX];

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

  sort(a, a + N);
  for (int i = 0; i < N; i++) b[i] = a[i];
  for (int i = 1; i < N; i++) b[i] += b[i-1];

  int ans = 1;
  for (int i = N - 2; i >= 0; i--) {
    if (2 * b[i] < a[i+1]) break;
    ans++;
  }

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

  return 0;
}


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

using namespace std;

#define ll long long
#define fix cout << fixed; cout << setprecision(0)





void solve() {

	int n;
	cin >> n;
	bool ok = 1;
	while(n--) {
		int x;
		cin >> x;
		if(x % 2 == 0) {
			if(x % 3 != 0 && x % 5 != 0) {
				ok = 0;
			}
		}
	}
	if(ok) {
		cout << "APPROVED\n";

	}
	else {
		cout << "DENIED\n";
	}



	
}

int main() {

	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	fix;
	solve();

	return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

int median(int a, int b, int c)
{
	vi v;
	v.pb(a); v.pb(b); v.pb(c);
	sort(v.begin(),v.end());
	return v[1];
}

int test(deque<int> vec)
{
	if(vec.size()==1) return vec[0];
	deque<int> nw;
	for(int i = 1; i < vec.size() - 1; i++)
	{
		nw.pb(median(vec[i-1],vec[i],vec[i+1]));
	}
	return test(nw);
}

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n, x; cin>>n>>x;
	if(x == n) //handles n = 1
	{
		cout << "Yes\n";
		for(int i = 1; i <= 2*n - 1; i++)
		{
			cout << i << '\n';
		}
		return 0;
	}
	else if(x == 1 || x == 2*n - 1)
	{
		cout << "No\n";
		return 0;
	}
	else
	{
		deque<int> ans;
		ans.pb(x);
		int l = x - 1; int r = x + 1;
		bool cur = true;
		while(l > 0 && r < 2*n)
		{
			if(cur)
			{
				ans.push_front(l);
				ans.push_back(r);
			}
			else
			{
				ans.push_back(l);
				ans.push_front(r);
			}
			l--; r++; cur^=1;
		}
		while(l > 0)
		{
			ans.push_back(l);
			l--;
			ans.push_front(l);
			l--;
		}
		while(r < 2*n)
		{
			ans.push_back(r);
			r++;
			ans.push_front(r);
			r++;
		}
		cout << "Yes\n";
		for(int i = 1; i <= 2*n - 1; i++)
		{
			cout << ans[i-1] << '\n';
		}
		/*
		if(n <= 100)
		{
			assert(test(ans) == x);
		}
		*/
	}
}


Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
const int INF = 1001001001;

int main() {
int N;
cin >> N;
bool ans = false;
for (int i = 0;i < 100;i++) {
  for (int j = 0;j < 100;j++) {
    if (N == 4*i + 7*j) {
      ans = true;
      break;
  }
}
}
if (ans == true) cout << "Yes" << endl;
else cout << "No" << endl;

return 0;
}


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

int main()
{
    string S, T;
    cin >> S >> T;

    ll ans = 0;
    rep(i, S.size())
    {
        if (S[i] != T[i])
            ans++;
    }
    cout << ans << endl;
    return 0;
}


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

void solve(){
  string s; cin >> s;
  int n = s.size();
  stack<int> s1;
  int ans1 = 0;
  for(int i = 0; i < n; i++){
    if(s[i] == '\\') s1.push(i);
    else if(s[i] == '/' && s1.empty() == 0){
      ans1 += i - s1.top();
      s1.pop();
    }
  }
  cout << ans1 << endl;
  stack<int> s2;
  stack<pair<int, int> > s3;
  for(int i = 0; i < n; i++){
    if(s[i] == '\\') s2.push(i);
    else if(s[i] == '/' && s2.empty() == 0){
      int x = s2.top();
      s2.pop();
      int y = i - x;
      while(s3.empty() == 0 && s3.top().first > x){
        y += s3.top().second;
        s3.pop();
      }
      s3.push(make_pair(x, y));
    }
  }
  vector<int> ans;
  while(s3.empty() == 0){
    ans.push_back(s3.top().second);
    s3.pop();
  }
  cout << ans.size();
  for(int i = ans.size() - 1; i >= 0; i--){
    cout << " " << ans[i];
  }
  cout << endl;
  return;
}

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



Measured memory_bytes: 3300
#include <iostream>
#include <math.h>
#include <limits.h>
using namespace std;
typedef long long LL;
const double eps = 1e-6;


LL a, b, c;

bool check(int n) {
    if (c <= 0) return false;
    if (c > INT_MAX) return false;
    LL ret1 = a*b + b*c + c*a;
    LL ret2 = a*b*c;
    if (ret1*n != ret2*4) return false;

    return true;
}
void solve(int n) {
    double target = 4.0 / n;
    for (a = 1; a <= 5000; a++) {
        double a1 = 1.0 / a;
        if (a1 > target) continue;
        for (b = a; b <= 5000; b++) {
            double a2 = 1.0 / b;
            if (a1+a2 > target || fabs(a1+a2-target) < eps) continue;
            double tmp = target - a1 - a2;
            double tmp2 = 1 / tmp;
            c = (LL) tmp2;
            if (check(n)) return;
        }
    }
}


int main() {
//    freopen("test.txt", "r", stdin);
    int n;
    cin >> n;
    solve(n);
    cout << a << ' ' << b << ' ' << c << endl;
    return 0;
}

Measured memory_bytes: 256