akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;
int n,k;
ll a[100001],ans=1e9-1;
int main()
{
	cin>>n>>k;
	for (int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	sort(a,a+n);
	for (int i=0;i<n-(k-1);i++)
	{
		ans=min(ans,a[i+k-1]-a[i]);
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 1024
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;
import java.util.Set;

//True Liars
public class Main{

	int m, p1, p2, n, c1, c2, idx;
	Set<Integer>[] yes, no;
	boolean[] u;
	int[] id, mark;
	
	void f(int k, int x){
		if(u[k])return;
		if(x==0)c1++;
		else c2++;
		u[k] = true;
		id[k] = idx;
		mark[k] = x;
		for(int v:yes[k])f(v, x);
		for(int v:no[k])f(v, 1-x);
	}
	
	class R{
		int s, t;
		public R(int s, int t) {
			this.s = s;
			this.t = t;
		}
	}
	
	@SuppressWarnings("unchecked")
	void run(){
		Scanner sc = new Scanner(System.in);
		yes = new Set[600];
		no = new Set[600];
		u = new boolean[600];
		id = new int[600];
		mark = new int[600];
		for(;;){
			m = sc.nextInt(); p1 = sc.nextInt(); p2 = sc.nextInt();
			if((m|p1|p2)==0)break;
			n = p1+p2;
			for(int i=0;i<n;i++){
				yes[i] = new HashSet<Integer>();
				no[i] = new HashSet<Integer>();
			}
			while(m--!=0){
				int s = sc.nextInt()-1, t = sc.nextInt()-1;
				String r = sc.next();
				if("yes".equals(r)){
					yes[s].add(t); yes[t].add(s);
				}
				else{
					no[s].add(t); no[t].add(s);
				}
			}
			Arrays.fill(u, false);
			Arrays.fill(id, 0);
			Arrays.fill(mark, 0);
			List<R> list = new ArrayList<R>();
			idx = 0;
			for(int i=0;i<n;i++){
				c1 = c2 = 0;
				f(i, 0);
				if(0<c1+c2){
					idx++;
					list.add(new R(c1, c2));
				}
			}
			int N = list.size();
			int[][] dp = new int[N+1][p1+1];
			dp[0][0] = 1;
			for(int i=1;i<=N;i++){
				R r = list.get(i-1);
				for(int j=0;j<=p1;j++){
					if(r.s<=j)dp[i][j]+=dp[i-1][j-r.s];
					if(r.t<=j)dp[i][j]+=dp[i-1][j-r.t];
				}
			}
			if(dp[N][p1]!=1){
				System.out.println("no"); continue;
			}
			List<Integer> res = new ArrayList<Integer>();
			for(int i=N-1;i>=0;i--){
				R r = list.get(i);
				if(r.s<=p1 && dp[i][p1-r.s]==1){
					p1-=r.s;
					for(int j=0;j<n;j++)if(id[j]==i&&mark[j]==0)res.add(j);
				}
				else{
					p1-=r.t;
					for(int j=0;j<n;j++)if(id[j]==i&&mark[j]==1)res.add(j);
				}
			}
			Collections.sort(res);
			for(int x:res)System.out.println(x+1);
			System.out.println("end");
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

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

using namespace std;

using ll = long long;

int main(){
    ll n; cin >> n;
    ll arr[n + 2] = {0};
    ll cnt = 0;
    for(ll i = 1; i < n + 1; ++i){
        cin >> arr[i];
    }
    for(ll i = 1; i < n + 1; ++i){
        cnt += abs(arr[i] - arr[i - 1]);
    }
    cnt += abs(arr[n] - arr[0]);
    for(ll i = 1; i < n + 1; ++i){
        cout << cnt - abs(arr[i + 1] - arr[i]) - abs(arr[i] - arr[i - 1]) + abs(arr[i + 1] - arr[i - 1])<< endl;
    }
    return 0;
}


Measured memory_bytes: 2048
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }

        static readonly long Mod = 1000000000 + 7;

        static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            var A = ReadLine();
            var B = ReadLine();
            if (A == B)
            {
                WriteLine("EQUAL");
                return;
            }
            if (A.Length < B.Length)
            {
                WriteLine("LESS");
                return;
            }
            if (B.Length < A.Length)
            {
                WriteLine("GREATER");
                return;
            }
            for (var i = 0; i < A.Length; ++i)
            {
                var a = A[i] - '0';
                var b = B[i] - '0';
                if (a < b)
                {
                    WriteLine("LESS");
                    return;
                }
                if (b < a)
                {
                    Write("GREATER");
                    return;
                }
            }
            //Out.Flush();
        }
    }
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
#define MD 1000000007
typedef long long int ll;
typedef pair<ll, ll> P;
template <typename T>
std::string tostr(const T &t){std::ostringstream os;os << t;return os.str();}
int dx[4]={1, 0, -1, 0}, dy[4]={0, 1, 0, -1};

int main()
{
    int N,M,R;
    cin>>N>>M>>R;
    vector<int> r(R);
    for(int i=0;i<R;i++) {
        cin>>r[i];
        r[i]--;
    }
    vector<P> pa(M);
    vector<int> cost(M);
    for(ll i=0;i<M;i++){
        int a,b,c;
        cin>>a>>b>>c;
        a--;b--;
        pa[i]={a,b};
        cost[i]=c;
    }
    //ワーシャルフロイド準備
    ll INF=1e12;
    vector<vector<ll>> dist(N, vector<ll>(N,INF));
    for(int i=0;i<N;i++){
        dist[i][i]=0;
    }
    for(int i=0;i<M;i++){
        dist[pa[i].first][pa[i].second]=cost[i];
        dist[pa[i].second][pa[i].first]=cost[i];
    }
    //ワーシャルフロイド
    for(int k=0;k<N;k++){
        for(int i=0;i<N;i++){
            for(int j=0;j<N;j++){
                dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);
            }
        }
    }
    //訪れる街の順列
    ll ans=1e12;
    sort(r.begin(),r.end());
    do{
        ll tmp=0;
        for(int i=0;i<R-1;i++){
            tmp+=dist[r[i]][r[i+1]];
        }
        ans=min(ans,tmp);
    }while(next_permutation(r.begin(),r.end()));
    
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 896
import java.io.*;

class Main {
    public static void main (String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
         
        int n = Integer.parseInt(br.readLine());
        String[] input = br.readLine().split(" ");
        int[] A = new int[n];
        for (int i = 0; i < n; i++) {
            A[i] = Integer.parseInt(input[i]);
        }

        long count = mergeSort(A, 0, n);
        System.out.println(count);
    }

    public static long mergeSort(int[] A, int left, int right) {
        long count = 0;
        if (left + 1 < right) {
            int mid = (left + right) / 2;
            count += mergeSort(A, left, mid);
            count += mergeSort(A, mid, right);
            count += merge(A, left, mid, right);
        }
        return count;
    }

    public static long merge(int[] A, int left, int mid, int right) {
        int n1 = mid - left;
        int n2 = right - mid;
        int[] L = new int[n1 + 1];
        int[] R = new int[n2 + 1];

        for (int i = 0; i < n1; i++) {
            L[i] = A[left + i];
        }
        for (int i = 0; i < n2; i++) {
            R[i] = A[mid + i];
        }

        L[n1] = Integer.MAX_VALUE;
        R[n2] = Integer.MAX_VALUE;

        int i = 0, j = 0;
        long count = 0;
        for (int k = left; k < right; k++) {
            if (L[i] < R[j]) {
                A[k] = L[i];
                i++;
            } else {
                A[k] = R[j];
                j++;
                count += n1 - i;
            }
        }

        return count;
    }
}

Measured memory_bytes: 61680
import math

dishes = []

for i in range(5):
    dishes.append([int(input()),None])

for el in dishes:
    el[1] = el[0] % 10 if el[0] % 10 > 0 else 10

dishes.sort(key=lambda x:x[1])

last_dish = dishes[0][0]

minute = 0

for j in range(1, len(dishes)):
    minute += math.ceil(dishes[j][0] / 10) * 10

minute += dishes[0][0]

print(minute)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(void)
{
	int toppingNumber;
	int toppingPrice;
	int pizzaPrise;
	double pizzaCal;
	vector<int> toppingCal;

	cin >> toppingNumber;
	cin >> pizzaPrise >> toppingPrice;
	cin >> pizzaCal;

	toppingCal.resize(toppingNumber);
	for (int i = 0; i < toppingNumber; i++)
	{
		cin >> toppingCal[i];
	}

	sort(toppingCal.begin() , toppingCal.end() , greater<int>());
	
	for (int i = 0; i < toppingNumber; i++)
	{
		if (pizzaCal / pizzaPrise < (double)(pizzaCal + toppingCal[i]) / (pizzaPrise + toppingPrice))
		{
			pizzaCal += toppingCal[i];
			pizzaPrise += toppingPrice;
		}
	}


	cout << (int)(pizzaCal / pizzaPrise) << endl;

	return 0;
}

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

int f[46]={0};

int fib(int n){
    f[0] = 1;
    f[1] = 1;
    for(int i=2; i<46; i++)    f[i] = f[i-1]+f[i-2];

    return f[n];
}

int main(void){
    int x;
    cin >> x;
    cout << fib(x) << endl;
    return 0;
}


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

int main() {
	int h, w;
	while (cin >> h >> w, h) {
		rep(i, h) {
			rep(j, w)cout << "#";
			cout << endl;
		}
		cout << endl;
	}
}

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

int main(){

    int a,b,c,k;
    cin>>a>>b>>c>>k;
    int tk=1;
    while(k>0){
        tk*=2;
        k--;
    }
    cout<<a+b+c+(tk-1)*max({a,b,c})<<endl;

    return 0;
}

Measured memory_bytes: 256
let n = Scanf.sscanf (read_line ()) "%d" @@ fun n -> n
let a = Array.init n @@ fun _ -> Scanf.sscanf (read_line ()) "%d" @@ fun a -> a

module IntMap = Map.Make(struct type t = int let compare = compare end)

let add i map =
  let v = try IntMap.find i map with Not_found -> 0 in
  IntMap.add i (v + 1) map

let remove i map =
  let v = IntMap.find i map in
  if v = 1 then IntMap.remove i map
  else IntMap.add i (v - 1) map

let solve map i =
  let mi, _, _ = IntMap.split i map in
  add i (
    if IntMap.is_empty mi then map
    else remove (fst @@ IntMap.max_binding mi) map
  )

let () = 
  Array.fold_left solve IntMap.empty a
  |> IntMap.bindings
  |> List.map snd
  |> List.fold_left (+) 0
  |> Printf.printf "%d\n"

Measured memory_bytes: 21660
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <math.h>
#define MOD 1000000007
typedef long long ll;
using namespace std;

int main(){
  int a,b;
  cin>>a;
  cin>>b;
  cout<<a*b-a-b+1<<endl;
  return 0;
}


Measured memory_bytes: 256
h, w = map(int, input().split())

temp = "0" * (w+2)

s = [temp]

for i in range(h):
    s.append("0" + input() + "0")

s.append(temp)

for i in range(h+2):
    for j in range(w+2):
        flag = False
        if s[i][j] == "#":
            if s[i-1][j] == "#" or s[i+1][j] == "#" or s[i][j+1] == "#" or s[i][j-1] == "#":
                flag = True
            if not flag:
                print("No")
                exit()

print("Yes")

Measured memory_bytes: 39280
# -*- coding: utf-8 -*-

# input
S = input()

# solve
ans = False
if S[0] == 'A' and S[1] != 'C' and S[2:len(S) - 1].count('C') == 1 and S.replace('A', '').replace('C', '').islower():
    ans = True

# output
print('AC' if ans else 'WA')


Measured memory_bytes: 2940
#include<iostream>
using namespace std;
int inv[3]={2,1,0};
int sum[3][3]={
	{0,1,2},
	{1,1,2},
	{2,2,2}
};
int prod[3][3]={
	{0,0,0},
	{0,1,1},
	{0,1,2}
};
string s;
int i;
int f(int p,int q,int r)
{
	if(s[i]=='-')
	{
		i++;
		return inv[f(p,q,r)];
	}
	else if(s[i]!='(')
	{
		if(s[i]=='P'){i++;return p;}
		else if(s[i]=='Q'){i++;return q;}
		else if(s[i]=='R'){i++;return r;}
		else{i++;return s[i-1]-'0';}
	}
	else
	{
		i++;
		int a=f(p,q,r);
		char c=s[i++];
		int b=f(p,q,r);
		i++;
		if(c=='*')return prod[a][b];
		else return sum[a][b];
	}
}
main()
{
	while(cin>>s,s!=".")
	{
		int cnt=0;
		for(int p=0;p<3;p++)for(int q=0;q<3;q++)for(int r=0;r<3;r++)
		{
			i=0;
			cnt+=f(p,q,r)==2;
		}
		cout<<cnt<<endl;
	}
}



Measured memory_bytes: 3128
#include <iostream>
#include <stdlib.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <assert.h>
#include <memory.h>
#include <time.h>
#include <bitset>
#include<iomanip>
 
#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define ld long double
#define rep(i, l, r) for (int i = (l); i < (r); i++)
#define repb(i, r, l) for (int i = (r); i > (l); i--)
#define sz(a) (int)a.size()
#define fi first
#define se second
#define pii pair<int,int>
#define pli pair<ll,int>
#define pll pair<ll,ll>
#define mp(a, b) make_pair(a, b)
#define mt(a,b,c) make_tuple(a,b,c)
#define rank qwertyuio
#define next dfghjk
#define plus fsghsf
#define minus ytryr
#define pb push_back
#define debug(x) cerr<<#x<<": "<<(x)<<endl
using namespace std;
 
inline bool setmin(int &x, int y) { return (y < x) ? x = y, 1 : 0; }
inline bool setmax(int &x, int y) { return (y > x) ? x = y, 1 : 0; }
inline bool setmin(ll &x, ll y) { return (y < x) ? x = y, 1 : 0; }
inline bool setmax(ll &x, ll y) { return (y > x) ? x = y, 1 : 0; }
 
const int N = 100000;
const int inf = (int)1e9 + 1;
const ll big = (ll)1e18 + 1;
const int P = 239;
const int P1 = 31;
const int P2 = 57;
const int mod = (int)1e9 + 7;
const int mod1 = (int)1e9 + 9;
const int mod2 = 998244353;
const int mod3 = (int)1e6+3;
const ld eps = 1e-12;
const double pi = atan2(0, -1);
const int ABC = 26;
 
 
ll binary_search(vector<ll> arr,ll val,ll l,ll r){
    ll m=l+(r-l)/2;
    if(l>=r){
        return l;
    }
    if(val<arr[m]){
        return binary_search(arr,val,l,m);
    }
    else{
        return binary_search(arr,val,m+1,r);
    }
}//return position less than
ll binary_search2(vector<ll> arr,ll val,ll l,ll r){
    ll m=l+(r-l)/2;
    if(l>=r){
        return l;
    }
    if(val<=arr[m]){//changed here
        return binary_search2(arr,val,l,m);
    }
    else{
        return binary_search2(arr,val,m+1,r);
    }
}//return position less than or equal
ll power(ll x, ll y) 
{ 
    ll res = 1;      // Initialize result 
  
    x = x % mod;  // Update x if it is more than or 
                // equal to p 
  
    while (y > 0) 
    { 
        // If y is odd, multiply x with result 
        if (y & 1) 
            res = (res*x) % mod; 
  
        // y must be even now 
        y = y>>1; // y = y/2 
        x = (x*x) % mod; 
    } 
    return res; 
} 
ll modInverse(ll n) 
{ 
    return power(n, mod-2); 
}
ll gcdl(ll a ,ll b){ 
    if (a == 0) 
        return b;  
    return gcdl(b % a, a);  
 }

int main()
{   ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int n,m;
    cin>>n>>m;
    if(m==n){
        cout<<"Yes";
    }
    else{
        cout<<"No";
    }

    return 0;
             
    
}

Measured memory_bytes: 256
N,M,X = map(int, input().split())
A = list(map(int, input().split()))

cnt_1=0
cnt_2=0
for i in range(M):
    if A[i]<X:
        cnt_1+=1
    elif A[i]>X:
        cnt_2+=1
    else:
        pass
print(min(cnt_1,cnt_2))

Measured memory_bytes: 38256
N=int(input().strip())
a=list(map(int, input().split()))
nlis={}

for i in range(N):
    if (a[i] in nlis)==False:
        nlis[a[i]]=1
    else:
        nlis[a[i]]+=1
ans=0
for i in nlis:
    if nlis[i]<i:
        ans+=nlis[i]
    else:
        ans+=abs(nlis[i]-i)
    #print(ans)
print(ans)

Measured memory_bytes: 18172
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0;i < n;i++)
#define rev(i, n) for(int i = n;i >= 0;i--)
#define repeat(i, m, n) for(int i = m;i < n;i++)
#define repeatrev(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define itn int

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
typedef priority_queue<int> Pr;

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N, K;
    cin >> N >> K;
    ll int t = K * pow((K - 1), N - 1);
    cout << t << endl;

}

Measured memory_bytes: 384
#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 ll long long 
#define FI first 
#define SE second
#define pb push_back 
#define eb emplace_back
#define mod 1000000007
#define all(c) (c).begin(),(c).end()
#define LB  lower_bound
#define UB  upper_bound
#define max3(a,b,c) max(c,max(a,b))
#define min3(a,b,c) min(c,min(a,b))
#define mems(s, n) memset(s, n, sizeof(s))
#define NINF -1e18
#define INF 1e18
#define int ll int
#define OOK order_of_key  //no of elements less than
#define FBO find_by_order //iterator pointing kth element;indexing starts from 0
#define CK3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define CK4(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl

typedef pair<int,int> PII;
typedef pair<pair<int,int>,int> PPII;
typedef pair<int,pair<int,int>> PIPI;
typedef map<int,int>MII;
typedef vector<int> VI;
template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

/*int power(int a, int b)
{int x=1,y=a;while(b>0){if(b%2){x =(x*y)%mod;}y =(y*y)%mod;b/=2;}return x%mod;}
*/
//int modInverse(int a, int m) {return power(a, m-2);} //gcd(a,m)=1 


signed main()
{
ios::sync_with_stdio(false); cin.tie(0);
int T=1,T1=0;//cin>>T;
while(T1++<T)
{
    int x,y,z;
    cin>>x>>y>>z;
    cout<<z<<" "<<x<<" "<<y<<endl;
}


return 0;
}





Measured memory_bytes: 256
n, k = map(int, input().split())
L = [0]*n
for i in range(k):
    d = int(input())
    A = list(map(int, input().split()))
    A = [a-1 for a in A]
    for a in A:
        L[a] = 1
ans = 0
for i in range(n):
    if L[i] == 0:
        ans += 1
print(ans)


Measured memory_bytes: 67832
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        // 数値の入力
        int a = sc.nextInt();
        int b = sc.nextInt();

        int answer  = 0;
        
        if(a > 10) {
        	answer = b;
        }else {
        	answer =b + ( 100 * (10 -a));
        }

            System.out.println(answer);
    }
}


Measured memory_bytes: 20820
nm=list(map(int,input().split()))
a=[[0 for x in range(nm[1])]for x in range(nm[0])]
b=[0 for x in range(nm[1])]
for x in range(nm[0]):
    code=list(map(int,input().split()))
    for y in range(nm[1]):
        a[x][y]=code[y]
for x in range(nm[1]):
    b[x] = int(input())

for x in range(nm[0]):
    result=0
    for y in range(nm[1]):
        result+=a[x][y]*b[y]
    print(result)

Measured memory_bytes: 8004
(* O(b log b) *)
Scanf.scanf "%d %d" @@ fun a b ->
  let string_rev s = let n = String.length s in String.init n @@ fun i -> s.[n - i - 1] in
  let ans = ref 0 in
  for n = a to b do
    let s = string_of_int n in
    if string_rev s = s then incr ans
  done;
  Printf.printf "%d\n" !ans

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b) - 1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)

#define PB push_back
#define INF (1<<29)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define CLR(a) memset(a,0,sizeof(a))
const int dx[] = {-1,0,0,1},dy[] = {0,1,-1,0};

typedef long long int ll;

using namespace std;

int main(){
    int n;
    stack<int> st;
    cin >> n;
    vector<int> a(n);
    REP(i,n){
	cin >> a[i];
    }
    int ans = 0;
    st.push(a[0]);
    ans++;
    FOR(i,1,n){
	/*
	printf("a[%d] = %d\n",i,a[i]);
	printf("Before: st.top = %d\n",st.top());
	*/
	if(st.top() < a[i]){
	    ans++;
	    st.push(a[i]);
	}else if(st.top() == a[i]){
	}else{
	    while(!st.empty()){
		st.pop();
		if(st.empty()){
		    ans++;
		    break;
		}
		if(a[i] == st.top()){
		    st.pop();
		    break;
		}else if(a[i] < st.top()){
		}else if(a[i] > st.top()){
		    ans++;
		    break;
		}
	    }
	    st.push(a[i]);
	}
	/*
	printf("After: st.top = %d\n",st.top());
	printf("ans = %d\n",ans);
	*/
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2592
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define INF 999999999
#define rep(i, n) for(int i = 0;i < n;i++)
#define pb(n) push_back(n)
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define Vecpr vector<pair<lli,lli>>
int main() {
  lli A,B,C,D;
  cin >>A;
  Out(A/3);
}


Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <vector>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <climits>
#include <stack>
#include <queue>
#include <set>
#include <cctype>
#include <bitset>
#include <type_traits>

#include <list>
using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define YES(j) cout << (j ? "YES" : "NO") << endl;
#define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
#define yes(j) std::cout << (j ? "yes" : "no") << endl;

int main(void)
{
    int n;
    cin >> n;
    string s, t;
    cin >> s >> t;
    long long ans = 1;
    long long MOD = 1000000007;
    int i = 0;
    while (i < n)
    {
        if (i == 0)
        {
            if (s[i] == t[i])
            {
                ans = 3;
                i++;
            }
            else
            {
                ans = 6;
                i += 2;
            }
        }
        else
        {
            if (s[i] == t[i])
            {
                if (s[i - 1] == t[i - 1])
                {
                    ans = (ans * 2) % MOD;
                }
                i++;
            }
            else
            {
                if (s[i - 1] == t[i - 1])
                {

                    ans = (ans * 2) % MOD;
                }
                else
                {
                    ans = (ans * 3) % MOD;
                }
                i += 2;
            }
        }
    }
    cout << ans << endl;
}

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

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MOD 1000000007

typedef long long ll;
typedef pair<int, int> p;

ll dp[300][100100];


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, w;
  cin >> n >> w;
  vector<int> val(n), weight(n);
  for (int i = 0; i < n; i++) {
    cin >> weight[i] >> val[i];
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < 100100; j++) {
      if(j >= weight[i-1]) {
        dp[i][j] = max(dp[i-1][j], dp[i-1][j-weight[i-1]] + val[i-1]);
      }else{
        dp[i][j] = dp[i-1][j];
      }
    }
  }

  cout << dp[n][w] << endl;

}


Measured memory_bytes: 79360
use std::io::*;
use std::ops::*;
const MOD: u64 = 1_000_000_007;

#[derive(Debug, Copy, Clone)]
struct Mint {
    value: u64,
}

impl Add for Mint {
    type Output = Mint;
    fn add(self, other: Mint) -> Mint {
        let mut res = self.value + other.value;
        if res >= MOD {
            res -= MOD;
        }
        Mint { value: res }
    }
}
impl AddAssign for Mint {
    fn add_assign(&mut self, other: Mint) {
        let mut res = self.value + other.value;
        if res >= MOD {
            res -= MOD;
        }
        *self = Mint { value: res };
    }
}

impl std::fmt::Display for Mint {
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
        write!(f, "{}", self.value)
    }
}

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let s: Vec<char> = itr.next().unwrap().chars().collect();

    let n = s.len();
    let mut dp: Vec<Vec<Mint>> = vec![vec![Mint { value: 0 }; 4]; n + 1];

    dp[0][0] = Mint { value: 1 };
    for i in 0..n {
        if s[i] == 'A' || s[i] == '?' {
            // use A
            dp[i + 1][1] += dp[i][0];
            // not use
            dp[i + 1][0] += dp[i][0];
            dp[i + 1][1] += dp[i][1];
            dp[i + 1][2] += dp[i][2];
            dp[i + 1][3] += dp[i][3];
        }
        if s[i] == 'B' || s[i] == '?' {
            // use B
            dp[i + 1][2] += dp[i][1];
            // not use
            dp[i + 1][0] += dp[i][0];
            dp[i + 1][1] += dp[i][1];
            dp[i + 1][2] += dp[i][2];
            dp[i + 1][3] += dp[i][3];
        }
        if s[i] == 'C' || s[i] == '?' {
            // use C
            dp[i + 1][3] += dp[i][2];
            // not use
            dp[i + 1][0] += dp[i][0];
            dp[i + 1][1] += dp[i][1];
            dp[i + 1][2] += dp[i][2];
            dp[i + 1][3] += dp[i][3];
        }
    }
    println!("{}", dp[n][3]);
}


Measured memory_bytes: 10492
#![allow(non_snake_case)]

// Input
#[allow(unused_macros)]
macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); let mut next = || { iter.next().unwrap() }; input_inner!{next, $($r)*} }; ($($r:tt)*) => { let stdin = std::io::stdin(); let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock())); let mut next = move || -> String{ bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect() }; input_inner!{next, $($r)*} }; }
macro_rules! input_inner { ($next:expr) => {}; ($next:expr, ) => {}; ($next:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($next, $t); input_inner!{$next $($r)*} };}
macro_rules! read_value { ($next:expr, ( $($t:tt),* )) => { ( $(read_value!($next, $t)),* ) }; ($next:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() }; ($next:expr, chars) => { read_value!($next, String).chars().collect::<Vec<char>>() }; ($next:expr, bytes) => { read_value!($next, String).into_bytes() }; ($next:expr, usize1) => { read_value!($next, usize) - 1 }; ($next:expr, $t:ty) => { $next().parse::<$t>().expect("Parse error") }; }

// Module
#[allow(unused_imports)]
use std::cmp::{min,max};
use std::collections::{HashSet};

// Main
fn main(){
    input!{
        a: u64,
        b: u64,
        c: u64,
    }
    let hs: HashSet<u64> = vec![a,b,c].into_iter().collect();
    println!("{}", hs.len());
}


Measured memory_bytes: 4352
#!/usr/bin/env python3
import sys
# import math
# import numpy as np
# from functools import lru_cache

args = sys.argv
if len(args) == 2:
  from IPython import embed
  em = True
else:
  em = False

# sys.setrecursionlimit(10000)

#### input
N = input()
# a, b = map(int, input().split())
H = list(map(int, input().split()))
# a = list(map(lambda x: int(x)*(-1), a))  # 各要素を-1倍


# n = int(input())
# t = [int(input()) for i in range(n)]
if em: sys.stdin = open('/dev/tty')

#### function
# @lru_cache(maxsize=10000)

#### process
# if em: embed()

now_step = 0
max_step = 0
for i in range(0, len(H)-1):
  if H[i] >= H[i + 1]:
    now_step = now_step + 1
  else:
    max_step = max(max_step, now_step)
    now_step = 0

max_step = max(max_step, now_step)

print(max_step)
## heapsort, O(logN)
# import heapq
# heapq.heapify(A)
# min = heapq.heappop(A)
# heapq.heappush(A, new_element)


Measured memory_bytes: 14480
n=int(input())
l=list(map(int,input().split()))
ans=0
if n==1 or n==2:
    print(0)
    exit()
l=sorted(l)

for i in range(n-2):
    for k in range(i+2,n):
        for j in range(i+1,k):
            
            if l[i]!=l[k] and l[k]!=l[j] and l[i]!=l[j] and l[i]+l[j]>l[k]:
                ans+=1
print(ans)
       


Measured memory_bytes: 9192
import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
from copy import copy, deepcopy
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque
#deque(l), pop(), append(x), popleft(), appendleft(x)
##listでqueの代用をするとO(N)の計算量がかかってしまうので注意
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
#import fractions#古いatcoderコンテストの場合GCDなどはここからimportする
from functools import lru_cache#pypyでもうごく
#@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率

def input(): return sys.stdin.readline()[:-1]
def printl(li): print(*li, sep="\n")
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def main():
    mod = 10**9+7
    #w.sort(key=itemgetter(1),reversed=True)  #二個目の要素で降順並び替え

    N = int(input())
    #N, K = map(int, input().split())
    ts = tuple(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列

    vs=tuple(map(int, input().split()))

    vmax=max(vs)
    tmax=sum(ts)
    inf=-vmax*tmax

    dp=[[inf]*(vmax+1) for _ in range(tmax+1)]
    dp[0][0]=0
    ti=0
    tcount=0
    for t in range (1,tmax+1):
        tcount+=1
        if tcount>ts[ti]:
            tcount-=ts[ti]
            ti+=1
        #print(tcount,ti,tmax)
        cvmax=vs[ti]
        for v in range(0,vmax+1):
            if v >cvmax:
                dp[t][v]=inf
                continue
            dp[t][v]=dp[t-1][v]+v
            if v+0.5<cvmax:
                dp[t][v]=max(dp[t][v],dp[t-1][v]+v+0.25)
            if v+1<=cvmax:
                dp[t][v]=max(dp[t][v],dp[t-1][v+1]+(2*v+1)*0.5)
            if v-1>=0:
                dp[t][v]=max(dp[t][v],dp[t-1][v-1]+(2*v-1)*0.5)
    print(dp[tmax][0])
    #print(dp)



        


if __name__ == "__main__":
    main()

Measured memory_bytes: 73564
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define SUB(a, b) a = (a+mod-b)%mod
#define MUL(a, b) a = (a * b) % mod
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define fi first
#define se second
typedef pair<int,int> P;
typedef pair<int, P> PP;
typedef pair<P, int> Pi;
typedef vector<int> vi;
typedef deque<int> dq;
const int inf = 1e9+7;
const int INF = 1e18+7;

signed main(){
	int h, w, d;
	scanf("%lld%lld%lld", &h, &w, &d);
	rep(i,h){rep(j,w)printf("%c", "RYGB"[((w+i+j)/d%2) | ((w+i-j)/d%2)<<1]);printf("\n");}
	return 0;
}






Measured memory_bytes: 512
import numpy as np

abcd = input()
#a,b,c,d = [s for s in abcd]

for i in range(2**3):
    ops = ["-","-","-",""]
    for j in range(3):
        if i>>j&1: ops[j] = "+"
    equa = ""
    for s,op in zip(abcd,ops): equa += s+op
    if eval(equa) == 7 : break

ans = equa + "=7"
print(ans)


Measured memory_bytes: 22940
#include<iostream>
#include <cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
const int MAX_C = 2010;
long long Com[MAX_C][MAX_C] = {0};

int main(){
  int N; string S; cin >> N >> S;
  int ans[N][4];
  if(S[0]=='o'){
    ans[0][0]=0; ans[1][0]=0; ans[N-1][0]=0;
    ans[0][1]=0; ans[1][1]=1; ans[N-1][1]=1;
    ans[0][2]=1; ans[1][2]=1; ans[N-1][2]=0;
    ans[0][3]=1; ans[1][3]=0; ans[N-1][3]=1;
  }
  else{
    ans[0][0]=0; ans[1][0]=1; ans[N-1][0]=0;
    ans[0][1]=0; ans[1][1]=0; ans[N-1][1]=1;
    ans[0][2]=1; ans[1][2]=1; ans[N-1][2]=1;
    ans[0][3]=1; ans[1][3]=0; ans[N-1][3]=0;
  }
  rep(i, 4){
    ans[N][i] = ans[0][i];
  }
  bool check[4];
  rep(i, 4)check[i]=true;
  for(int i=1; i<N; i++){
    if(S[i]=='o'){
      rep(j, 4){
        if(i==N-2 || i==N-1){
          if(ans[i][j] && ans[i-1][j]==ans[i+1][j]) check[j]=false;
          if(!(ans[i][j]) && ans[i-1][j]!=ans[i+1][j]) check[j]=false;
        }
        if(ans[i][j]) ans[i+1][j]=1-ans[i-1][j];
        else ans[i+1][j]=ans[i-1][j];                         
      }
    }
    else{
      rep(j, 4){
        if(i==N-2 || i==N-1){
          if(ans[i][j] && ans[i-1][j]!=ans[i+1][j]) check[j]=false;
          if(!(ans[i][j]) && ans[i-1][j]==ans[i+1][j]) check[j]=false;
        }
        if(ans[i][j]) ans[i+1][j]=ans[i-1][j];
        else ans[i+1][j]=1-ans[i-1][j];
      }
    }
  }
  rep(i, 4){
    if(check[i]){
      rep(j, N){
        if(ans[j][i]) cout << 'W'; else cout << 'S';
      }
      cout << endl; return 0;
    }
  }
  cout << -1 << endl;
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
const int MX = 1e6 + 5;

int gcd(int a, int b) {
	if (b == 0) 
		return a;
	return gcd(b, a % b);
}

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

	int n; cin >> n;
	vector<int> a(n), cnt(MX);
	int tot_gcd = 0;
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
		tot_gcd = (i == 0 ? a[i] : gcd(tot_gcd, a[i]));
		cnt[a[i]]++;
	}
	vector<bool> is_prime(MX, 1);
	is_prime[0] = is_prime[1] = 0;
	for (int i = 2; i < MX; ++i) {
		if (!is_prime[i]) continue;
		for (int j = 2 * i; j < MX; j += i) {
			is_prime[j] = 0;
		}
	}
	vector<int> primes; primes.reserve(MX);
	for (int i = 2; i < MX; ++i) {
		if (is_prime[i]) {
			primes.push_back(i);
		}
	}
	bool found = false;
	for (int prime: primes) {
		int p_cnt = 0; // how many elements in our array are multiples of this prime?
		for (int i = prime; i < MX && p_cnt < 2; i += prime) {
			p_cnt += cnt[i];
		}
		if (p_cnt >= 2) {
			found = true;
			break;
		}
	}
	if (!found) {
		cout << "pairwise coprime\n";
	} else if (tot_gcd == 1) {
		cout << "setwise coprime\n";
	} else {
		cout << "not coprime\n";
	}
	return 0;
}


Measured memory_bytes: 11388
#include <bits/stdc++.h>
// atoi : atoi(str.c_str())
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
#define fix10 cout << fixed << setprecision(10);
#define rep(i,n) for(int i=0; i<(int)(n);i++)

int main(){
  long n,m;
  cin >> n >> m;
  priority_queue<long> cost;
  rep(i,n){
    long a;
    cin >> a;
    cost.push(a);
  }
  rep(i,m){
    long tmp = cost.top();
    cost.pop();
    tmp /= 2;
    cost.push(tmp);
  }
  long sum = 0;
  while(!cost.empty()){
    long tmp = cost.top();
    cost.pop();
    sum += tmp;
  }
  cout << sum << endl;
}


Measured memory_bytes: 1400
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
public static class P
{
    public static void Main()
    {
        int n = int.Parse(Console.ReadLine());

        int[] parents = Enumerable.Repeat(-1, n).ToArray();
        int[][] childs = new int[n][];
        for (int i = 0; i < n; i++)
        {
            var data = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var id = data[0];
            var l = data[1];
            var r = data[2];
            for (int _ = 0; _ < 2; _++)
            {
                if (l != -1)
                {
                    parents[l] = id;
                }
                { var tmp = l; l = r; r = tmp; }
            }
            childs[id] = new[] { l, r };
        }

        var root = Array.IndexOf(parents, -1);

        Func<int, IEnumerable<int>> preOrder = null;
        preOrder = parent =>
            parent == -1 ? 
            Enumerable.Empty<int>() :
            Enumerable.Empty<int>()
            .Concat(new int[] { parent })
            .Concat(preOrder(childs[parent][0]))
            .Concat(preOrder(childs[parent][1]));
        
        Func<int, IEnumerable<int>> inOrder = null;
        inOrder = parent =>
           parent == -1 ?
           Enumerable.Empty<int>() :
           Enumerable.Empty<int>()
           .Concat(inOrder(childs[parent][0]))
           .Concat(new int[] { parent })
           .Concat(inOrder(childs[parent][1]));

        Func<int, IEnumerable<int>> postOrder = null;
        postOrder = parent =>
           parent == -1 ?
           Enumerable.Empty<int>() :
           Enumerable.Empty<int>()
           .Concat(postOrder(childs[parent][0]))
           .Concat(postOrder(childs[parent][1]))
           .Concat(new int[] { parent });


        Console.WriteLine("Preorder");
        Console.WriteLine(" " + string.Join(" ", preOrder(root)));

        Console.WriteLine("Inorder");
        Console.WriteLine(" " + string.Join(" ", inOrder(root)));

        Console.WriteLine("Postorder");
        Console.WriteLine(" " + string.Join(" ", postOrder(root)));
    }
}


Measured memory_bytes: 18388
import sys
import math

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


if 0 in A:
    print(0)
    sys.exit()

result = 1
for i in range(N):
    result *= A[i]
    if result > 10**18:
        print(-1)
        sys.exit()

print(result)

Measured memory_bytes: 22156
#include <cstdio>

int main(){
    int a, m, f, r;
    a = 1;
    while (a == 1){
        scanf("%d %d %d\n", &m, &f, &r);
        if (m == -1 && f == -1 && r == -1){
            break;
        } else if (m == -1 || f == -1){
            printf("F\n");
        } else if (m + f >= 80){
            printf("A\n");
        } else if (m + f >= 65 && m + f < 80){
            printf("B\n");
        } else if (m + f >= 50 && m + f < 65){
            printf("C\n");
        } else if (m + f >= 30 && m + f < 50){
            if (r >= 50){
                printf("C\n");
            } else {
                printf("D\n");
            }
        } else if (m + f < 30){
            printf("F\n");
        }
        m = 0;
        f = 0;
        r = 0;
    }
    return 0;
}


Measured memory_bytes: 2592
import java.util.Scanner;

public class Main {

	static long mod = 1_000_000_007;

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int N = in.nextInt(), K = in.nextInt();
		int a[] = new int[N + 1];
		for ( int i = 1; i <= N; i++ ) {
			a[i] = in.nextInt();
		}
		in.close();

		long dp[][] = new long[N + 1][K + 1];
		dp[0][0] = 1;

		for ( int n = 1; n <= N; n++ ) {
			for ( int k = 0; k <= K; k++ ) {
				if ( k == 0 ) {
					dp[n][k] = 1;

				} else {
					dp[n][k] = (dp[n][k - 1] + dp[n - 1][k]) % mod;

				}

				if ( a[n] < k ) {
					dp[n][k] = (dp[n][k - 1] + dp[n - 1][k] - dp[n - 1][k - a[n] - 1]) % mod;

				}
			}
		}
		System.out.println((dp[N][K] + mod) % mod);
	}
}


Measured memory_bytes: 129620
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <utility>
#include <tuple>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
using ll = long long int;
using P = pair<ll, ll>;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...) do{ } while(false)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template<typename T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }
template<typename T> void print(T a) { cout << a << endl; }
template<typename T, typename... Ts> void print(T a, Ts... ts) { cout << a << ' '; print(ts...); }
template<typename T> istream &operator,(istream &in, T &t) { return in >> t; }
// clang-format on

using ull = unsigned long long;

bool bits(ull x, int n) {
    return (x >> n) & 1;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int t;
    cin, t;
    REP(_, 0, t) {
        int n;
        cin, n;
        vector<ull> a(n);
        REP(i, 0, n) {
            cin, a[i];
        }
        string s;
        cin, s;

        reverse(a.begin(), a.end());
        reverse(s.begin(), s.end());

        const int mx = 64;
        vector<ull> mat(mx, 0);
        auto func = [&]() {
            REP(i, 0, n) {
                if (s[i] == '0') {
                    for (int j = mx - 1; j >= 0; j--) {
                        if (bits(a[i], j)) {
                            if (mat[j] > 0) {
                                a[i] ^= mat[j];
                            } else {
                                mat[j] = a[i];
                                break;
                            }
                        }
                    }
                } else {
                    bool contained = false;
                    for (int j = mx - 1; j >= 0; j--) {
                        if (bits(a[i], j)) {
                            if (mat[j] > 0) {
                                a[i] ^= mat[j];
                            }
                        }
                        if (a[i] == 0) {
                            contained = true;
                            break;
                        }
                    }
                    if (!contained) {
                        return 1;
                    }
                }
            }
            return 0;
        };
        cout << func() << endl;
    }
    return 0;
}


Measured memory_bytes: 3584
n = int(input())
le = [input() for j in range(0,n)]
f = [True]
for i in range(1,n):
    if le.count(le[i])>1:
        f[0]=False
        break
    if le[i][0]!=le[i-1][-1]:
        f[0]=False
        break

if f[0]==True:
    print('Yes')

if f[0]!=True:
    print('No')
    

Measured memory_bytes: 3060
N,x=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
total=0
j=0
ssum=sum(a)

if ssum>=x:
    for i in range(N):
        total+=a[i]
        if total>x:
            break
        j+=1
    print(j)
else:
    print(N-1)


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

typedef long long ll;
#define vec vector<int>
#define vecll vector<ll>
#define vpair vector<pair<int, int>>
#define vpairll vector<pair<ll, ll>>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define rep(i,n)   for(int i=(int)0; i<(int)n; i++)
#define llrep(i,n)   for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n) for(int i=(int)m; i<(int)n; i++)
#define all(var)     (var).begin(), (var).end()
#define prt(var)     cout << var << endl
#define prt_dbl(i,var) cout<<fixed<<setprecision(i)<<var<<endl;
template <typename Val>
Val gcd(Val a, Val b) {
//use ll or int for gcd
    if (b==0) return a;
    else return gcd(b, a%b);
}
template <typename Val>
Val vec_max(vector<Val> v){
  return *max_element(v.begin(),v.end());
}
template <typename Val>
Val vec_min(vector<Val> v){
  return *min_element(v.begin(),v.end());
}

//---------------------------------------------------------------

int main(){
  ll N,K;
  cin>>N>>K;
  vector<pair<int,int>> R;
  rep(i,N){
    int a,b;
    cin>>a>>b;
    R.emplace_back(a,b);
  }
  sort(R.begin(),R.end());
  ll count=0;
  int ans;
  rep(i,N){
    count+=R.at(i).second;
    if(K<=count){
      ans = R.at(i).first;
      break;
    }
  }
  cout<<ans<<endl;




}


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

int main(){
  int X,Y,money;
  cin >> X >> Y;
  if((X == 1)&&(Y == 1)){
    cout << "1000000\n";
    return 0;
  }
  if(X != Y){
    for(int i = 1;i < 4;i++){
      if((X == i)||(Y == i))
        money += (4 - i) * 100000;
    }
  }
  if(X == Y){
    if((X > 0)&&(X < 4))
      money = (4 - X) * 200000;
  }
  cout << money << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/range/adaptor/reversed.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
typedef long long int ll;

#define PI (acos(-1))
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define dumparr(x) cerr << #x ; for(auto elem: x){cerr << " " << elem;} cerr << endl;
#define dumppairs(x) cerr << #x ; for(auto elem: x){cerr << "(" << elem.first << " " << elem.second << ") ";} cerr << endl;
#define dumpline cerr << "**********************" << endl;
#define dumpwline(x) cerr << "******** " << #x << "=" << (x) << " ********" << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

int main(void){
    ll n; cin >> n;
    ll a; cin >> a;
    ll b; cin >> b;
    ll ans = 0;
    ans += n / (a+b) * a;
    ans += min(n%(a+b), a);
    cout << ans  << endl;
    return 0;
}

Measured memory_bytes: 256
K = int(input())
tmp = input()
tmp = str.split(tmp,' ')
A = int(tmp[0])
B = int(tmp[1])
flag = 0
for i in list(range(A,B+1)):
    if(i%K == 0):
        flag = 1
        break;

if(flag == 1):
    print("OK")
else:
    print("NG")


Measured memory_bytes: 9188
#include<stdio.h>
#define MAX_RANGE 4
int main() {
	int i,cnt=0;
	char S[MAX_RANGE], T[MAX_RANGE];
	scanf("%s", S);
	scanf("%s", T);
	for (i = 0; S[i] != '\0' && T[i] != '\0'; i++)
		if (S[i] == T[i])cnt++;
	printf("%d", cnt);
	return 0;
}

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

int main(){
  int a,b,c,x,y;
  cin>>a>>b>>c>>x>>y;
  int ans=0;
  if((a+b)/2.0<=c)
    ans+=a*x+b*y;
  else{
    ans+=2*c*min(x,y);
    if(x>y)
      ans+=(x-y)*min(a,2*c);
    else
      ans+=(y-x)*min(b,2*c);
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    long[][] cnt = new long[n][3];
    long[][] sum = new long[n][3];
    for(int i = 0;i < n;i++){
      cnt[i][0]=sc.nextLong();
      cnt[i][1]=sc.nextLong();
      cnt[i][2]=sc.nextLong();
    }
    for(int i=0;i<3;i++)sum[0][i]=cnt[0][i];
    for(int i=1;i<n;i++)
      for(int j=0;j<3;j++)
        sum[i][j]=cnt[i][j]+Math.max(sum[i-1][(j+1)%3],sum[i-1][(j+2)%3]);
    System.out.println(Math.max(sum[n-1][0],Math.max(sum[n-1][1],sum[n-1][2])));
  }
}


Measured memory_bytes: 104184
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define mp make_pair
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define REP(i, s, n) for(int i = s; i < n; i++)
#define rRep(i, n) for(int i = n - 1; i >= 0; i--)

int32_t main() {
	FAST
	int n;
	cin >> n;

	int num = sqrt(n);
	int ans = -1;
	for(int i = num; i >= 2; i--)
	{
		if(n%i == 0)
		{
			ans = i;
			break;
		}
	}

	if(ans == -1)
	{
		ans = 1;
	}
	cout << (ans - 1) + (n/ans - 1) << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned int ui;
#define infin (ll)(pow(10,9)+7)
#define push_back pb;
using namespace std;
int main()
{
   string s;
   cin>>s;
   if (s[s.size()-1]=='s')
      s=s+"es";
   else
   {
      s=s+'s';
   }
   cout<<s<<endl;
}

Measured memory_bytes: 3632