akhauriyash/Code-Regression huggingface dataset:
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
 
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
 
// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
 
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define f(i, n) for(int i = 0; i < n; ++i)
#define pb push_back
#define eb emplace_back
#define m_p make_pair
#define T int t = 0; cin >> t; while(t--)
#define pr(a) for(int i = 0; i < (int)a.size(); ++i)cout << a[i] << " ";cout << endl;
#define b_e(a) a.begin(), a.end()
typedef long long ll;
typedef long double lld;
const ll mod = 1e9 + 7;
const ll mx = 2e5 + 1;
const ll inf = 1e9;
const int sz = 20;

void input(){
    IOS;
    int n;
    cin >> n;
    vector<ll>a(n);
    map<ll, ll>mp;
    f(i, n)cin >> a[i], mp[a[i]]++;
    int q;
    cin >> q;
    ll sum = accumulate(b_e(a), 0LL);
    while(q--){
        int b, c;
        cin >> b >> c;
        if(mp.find(b) != mp.end()){
            sum -= mp[b] * b;
            sum += mp[b] * c;
            ll cnt = mp[b];
            mp.erase(mp.find(b));
            mp[c] += cnt;
        }
        cout << sum << endl;
    }
}
int main(){
    input();
    return 0;
} 
/*
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
*/

Measured memory_bytes: 7944
#include <iostream>

using namespace std;

int main()
{
	int n;
	while(true){
		int count = 0;
		cin >> n;
		if(cin.eof()) return 0;
		for(int a = 0; a <= 9; a++){
			for(int b = 0; b <= 9; b++){
				for(int c = 0; c <= 9; c++){
					for(int d = 0; d <= 9; d++){
						if(a + b + c + d == n) count++;
					}
				}
			}
		}
	cout << count << endl;
	}

	return 0;
}

Measured memory_bytes: 1160
#include <map>
#include <set>
#include <list>
#include <ctime>
#include <cmath>
#include <queue>
#include <stack>
#include <bitset>
#include <vector>
#include <cstdio>
#include <string>
#include <cstring>
#include <sstream>
#include <iomanip>
#include <cstdlib>
#include <utility>
#include <iostream>
#include <algorithm>
using namespace std;
int a[100005];
int main ( ) {
	string s;
	cin>>s;
	int i,ls,ans=0;
	ls=s.length();
	for (i=1;i<=ls;i++) a[i]=s[i-1]-96;//x=24
	int l=1,r=ls;
	while (l<r) {
		while (a[l]==24 && a[r]==24 && l<r) {
			l++;r--;
		}
		if (l>=r) break;
		while (a[l]==24 && l<=ls) l++,ans++;
		while (a[r]==24 && r>=1) r--,ans++;
		if (l>=r || l>ls || r<1) break;
		if (a[l]!=a[r]) {
			puts("-1");return 0;
		}
		l++;r--;
	}
	printf("%d\n",ans);
	return 0;
}
/*
xabxa
2
*/

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

int main(){
    int N, K;
    cin >> N >> K;
    vector<int> H(N);
    for(int i=0; i<N; i++) cin >> H[i];
    sort(H.rbegin(), H.rend());
    int64_t ans = 0;
    for(int i=K; i<N; i++) ans += H[i];
    cout << ans << endl;
    return 0;
}


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

#define LOG(variable) cout << #variable":\t" << (variable) << endl
#define LOGCON(i, container) for(int (i) = 0; (i) < (container).size(); ++(i)) cout << (i) << ":\t" << (container)[(i)] << endl
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(i, r, n) for (int i = (r); i < (n); ++i)
#define REPR(i, n) for(int i = (n); i >= 0; --i) // from n to 0
#define REPRS(i, r, n) for(int i = (n); i >= (r); --i) // from n to r
#define REPOBJ(itr, obj) for(auto itr = (obj).begin(); itr != (obj).end() ; ++itr)
#define REPROBJ(itr, obj) for(auto itr = (obj).rbegin(), e = (obj).rend(); itr != e; ++itr)
#define COUTB(x) cout << (x) << "\n"
#define COUTS(x) cout << (x) << " "
#define PB push_back
#define SORT(obj) sort((obj).begin(), (obj).end())
#define SORTR(obj) sort((obj).begin(), (obj).end(), greater<>())
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define PI (acos(-1))

int lcm(int, int);
map<int,int> GetPrimeFactors(int);
bool IsPrime(int);
int Factorial(int);
int npr (int, int);
int ncr (int, int);

/***** MAIN *****/
void Main() {
    int n, m, d;
    cin >> n >> m >> d;
    if(d) {
        cout << 2.0 * (n-d) / (n*n) * (m-1);
    } else {
        cout << double(m-1) / n;
    }

    cout << "\n";
}
/***** MAIN *****/

signed main() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}

int lcm(int a, int b) { return a / __gcd(a,b) * b;}

map<int,int> GetPrimeFactors(int n) {
    map<int,int> mp;
    // dived by 2, 3, 5, ...
    for(int i=2; i*i<=n; i+=2) {
        if(i==4) i = 3;
        while(n%i == 0) {
            ++mp[i];
            n /= i;
        }
    }
    if(n!=1) ++mp[n];

    return mp;
}

bool IsPrime(int a) {
    if(a <= 1) return false;
    if(a == 2) return true;
    if(a%2 == 0) return false;
    for(int i = 3; i*i <= a; i+=2) {
        if(a%i==0) return false;
    }
    return true;
}

int Factorial(int n){
    int ans = 1;
    while(n > 1){
        ans *= n;
        --n;
    }
    return ans;
}

int npr(int n, int r) {
    return Factorial(n)/Factorial(n-r);
}

int ncr (int n, int r){
    return npr(n,r)/Factorial(r);
}


Measured memory_bytes: 256
#include <stdio.h>

int L, R;

int main()
{
	scanf ("%d %d", &L, &R);

	int ans = 2019;
	for (int i = L, c = 0; i <= R && c < 2019; i++, c++){
		for (int j = i + 1, d = 0; j <= R && d < 2019; j++, d++){
			int k = 1ll * i * j % 2019;
			if (ans > k)
				ans = k;
		}
	}
	printf ("%d\n", ans);
	return 0;
}


Measured memory_bytes: 128
import Data.IORef
import Control.Monad
 
main :: IO()
main = getLine >> getContents >>= (\(x:y:xs) -> solve (y - x) (min x y) xs).map read.lines >>= print
 
solve :: Int -> Int -> [Int] -> IO Int
solve a b xs = do
                a' <- newIORef a
                b' <- newIORef b
                forM_ xs $ \z -> do
                    x <- readIORef a'
                    y <- readIORef b'
                    when (z - y > x) $ writeIORef a' (z - y)
                    when (z < y)     $ writeIORef b' z
                readIORef a'

Measured memory_bytes: 5556
#include <bits/stdc++.h>
using namespace std;
int main(void){

    int n;
    cin >> n;
    vector<int> t(n);
    for(int i=0; i<n; i++) cin >> t[i];
    
    int m;
    cin >> m;
    vector<pair<int,int>> px(m);
    for(int i=0; i<m; i++) cin >> px[i].first >> px[i].second;
    
    for(int i=0; i<m; i++) {
        int sum = 0;
        for(int j=0; j<n; j++) {
            if(px[i].first-1 == j) {
                sum += px[i].second;
            }
            else {
                sum += t[j];
            }
        }
        cout << sum << endl;
    }
    
    return 0;
}


Measured memory_bytes: 764
#include <iostream>
using namespace std;
int main()
{
  int h,w;
  cin>>h>>w;
  char s[h][w];
  for(int i=0;i<h;i++)
  {
  	for(int j=0;j<w;j++)
  	cin>>s[i][j];
  }
  for(int i=0;i<w+2;i++)
  cout<<"#";
  cout<<endl;
  for(int i=0;i<h;i++)
  {
  	cout<<"#";
  	for(int j=0;j<w;j++)
  	{
  		
  		cout<<s[i][j];
  		
  		
	  }
	  cout<<"#"<<endl;
	  
  
	  
  }
  for(int i=0;i<w+2;i++)
  cout<<"#";
  cout<<endl;
  return 0;
}

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

m = [0]*(N+1)
r = [0]*(N+1)
for i in range(M):
    p,S = input().split()
    p = int(p)
    if r[p] == 0:
        if S == "WA":
            m[p] += 1
        else:
            r[p] = 1
mistake = sum([r[i]*m[i] for i in range(N+1)])
print(sum(r),mistake)

Measured memory_bytes: 5528
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
    	InputStream input = System.in;
      	OutputStream output = System.out;
      	Scanner sc = new Scanner(input);
      	PrintWriter out = new PrintWriter(output);
      	int A = Integer.parseInt(sc.next());
      	int B = Integer.parseInt(sc.next());
      	int max = Math.max(A + B, Math.max(A - B, A * B));
      	out.println(max);
      	out.close();
    }
}

Measured memory_bytes: 23636
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
ans=0
for i in range(n):
    if a[i]>b[i]:
        ans+=b[i]
    else:
        ans+=a[i]
        b[i]-=a[i]
        if a[i+1]<=b[i]:
            ans+=a[i+1]
            a[i+1]=0
        else:
            ans+=b[i]
            a[i+1]-=b[i]
print(ans)
        

Measured memory_bytes: 18624
#include<bits/stdc++.h>
#define INF 2000000000
#define MOD 1000000007
#define EPS (1e-10)

using namespace std;

int main(int argc, char *argv[]) {

	long N; cin >> N;

	vector<char> alphabet(26,0);

	for (int i = 0; i < 26; i++) {
		alphabet[i] = char(65+i);
	}


	string ans = "";
	while(N > 0) {
		N -= 1;
		ans += tolower(alphabet[N%26]);
		N /= 26;
	}
	reverse(ans.begin(), ans.end());
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3504
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v)   (v).begin(),(v).end()
#define INF      (int)1e9
#define MOD      ((int)1e9+7)
using namespace std;
typedef long long     llong;
typedef pair<int,int> pii;
typedef vector<int>   vi;
typedef vector<vi >   vvi;
typedef vector<vvi >  vvvi;
template<class Type> void join(const Type &a){for(auto elem:a)cout<<elem<<' ';cout<<endl;}

struct UnionFind{
	vector<int> par;//xの親はpar[x].x自身が親ならpar[x]<0で、-par[x]がその集合のサイズ.
	
	UnionFind(int n):par(n,-1){}//コンストラクタ.
	
	void reset(int n){par.assign(n,-1);}
	int root(int x){return par[x]<0?x:par[x]=root(par[x]);}//再帰.
	int size(int x){return -par[root(x)];}
	bool same(int x,int y){return root(x)==root(y);}
	bool unite(int x,int y){
		x=root(x);
		y=root(y);
		if(x==y) return false;//do nothing.
		if(size(x)<size(y)) swap(x,y);//merge technique.
		par[x]+=par[y];
		par[y]=x;
		return true;
	}
};

int main(){
	int n,k,l;
	cin>>n>>k>>l;
	
	UnionFind uf(n),uff(n);
	REP(i,k){
		int p,q;
		cin>>p>>q;
		uf.unite(--p,--q);
	}
	REP(i,l){
		int r,s;
		cin>>r>>s;
		uff.unite(--r,--s);
	}
	
	map<pii,int> mp;
	REP(i,n){
		pii p(uf.root(i),uff.root(i));
		mp[p]++;
	}
	
	REP(i,n){
		pii p(uf.root(i),uff.root(i));
		cout<<mp[p]<<endl;
	}
	return 0;
}//解説参考.

Measured memory_bytes: 13568
n = int(input())

tp = 0
xp = 0
yp = 0
flag = [0]*n
for i in range(n):
  t, x, y = map(int,input().split())
  dt = t-tp
  dx = abs(xp-x)
  dy = abs(yp-y)
  if dt==dx+dy:
    flag[i]=1
  elif dt>dx+dy and dt%2==0 and dx%2==0 and dy%2==0:
    flag[i]=1
  elif dt>dx+dy and dt%2==0 and dx%2==1 and dy%2==1:
    flag[i]=1
  elif dt>dx+dy and dt%2==1 and dx%2==0 and dy%2==1:
    flag[i]=1
  elif dt>dx+dy and dt%2==1 and dx%2==1 and dy%2==0:
    flag[i]=1
  tp=t
  xp=x
  yp=y

f=1
for i in range(n):
  f *= flag[i]
  
if f==1:
  print("Yes")
else:
  print("No")

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

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

Measured memory_bytes: 256
package main

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

var scanner = bufio.NewScanner(os.Stdin)

func nextString() string {
	scanner.Scan()
	return scanner.Text()
}

func nextInt() (int, error) {
	return strconv.Atoi(nextString())
}

func stringifyArray(arr []int) string {
	return strings.TrimRight(fmt.Sprintf("%+v", arr)[1:], "]")
}

func main() {
	scanner.Split(bufio.ScanWords)

	rooms := make([]int, 10*3*4)

	n, _ := nextInt()
	for i := 0; i < n; i++ {
		b, _ := nextInt()
		f, _ := nextInt()
		r, _ := nextInt()
		v, _ := nextInt()

		rooms[10*3*(b-1)+10*(f-1)+(r-1)] += v
	}

	for i := 0; i < 3*4; i++ {
		fmt.Println(" " + stringifyArray(rooms[(10*i):(10*i+10)]))
		if i%3 == 2 && i < 11 {
			fmt.Println(strings.Repeat("#", 20))
		}
	}
}



Measured memory_bytes: 1176
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define SIZE 200005
#define INF 1000000005LL
#define MOD 1000000007

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

map<char,ll> T;
int N;
string S;

int main(){
  cin >> N >> S;
  for(auto u : S){
    T[u]++;
  }
  ll ans = 1LL;
  for(auto t : T){
    ans = ans*(t.second+1LL)%MOD;
  }
  ans += MOD-1;
  ans %= MOD;
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 512
n = int(input())
a = list(map(int, input().split()))
a.sort()
count =0
for i in range(len(a)):
  for j in range(i+1,len(a)):
    for k in range(j+1, len(a)):
      if a[i]+a[j]>a[k] and a[i]+a[k]>a[j] and a[j]+a[k]>a[i]:
        if a[i]!=a[j] and a[j]!=a[k] and a[i]!=a[k]:
          count +=1
print(count)

Measured memory_bytes: 68116
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <fstream>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string toStr(T x) { ostringstream sout; sout << x; return sout.str();}
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
const double EPS = 1e-12;
const double PI = acos(-1.0);
const int INF = INT_MAX/10;

struct state {
	int p, c, m;
	state(int p, int c, int m) : p(p), c(c), m(m) {};
	bool operator<(const state &o)const {
		return o.c<c;
	}
};

int main() {
	int N, M, L, K, A, H;
	while(cin >> N >> M >> L >> K >> A >> H, N) {
		vector<bool> freeze(N, false);
		int x, y, t;
		REP(i, L) {
			cin >> t;
			freeze[t] = true;
		}

		vvi dist(N, vi(N, INF));
		REP(i, K) {
			cin >> x >> y >> t;
			dist[x][y] = dist[y][x] = t;
		}

		priority_queue<state> Q;
		Q.push(state(A, 0, M));
		vvi cost(N, vi(M+1, INF));
		REP(i, M+1) {
			cost[A][i] = 0;
		}
		int ans = INF;
		while(!Q.empty()) {
			state st = Q.top();
			Q.pop();

			if(st.p == H) {
				ans = st.c;
				break;
			}

			REP(i, N) {
				if(st.p != i && dist[st.p][i] != INF) {
					int nc = st.c+dist[st.p][i];
					int nm = st.m-dist[st.p][i];
					if(nm < 0) {
						continue;
					}

					if(freeze[i]) {
						REP(j, M-nm+1) {
							if(nc+j < cost[i][nm+j]) {
								cost[i][nm+j] = nc+j;
								Q.push(state(i, nc+j, nm+j));
							}
						}						
					} else {
						if(nc < cost[i][nm]) {
							cost[i][nm] = nc;
							Q.push(state(i, nc, nm));
						}
					}
				}
			}
		}


		if(ans == INF) {
			cout << "Help!" << endl;
		} else {
			cout << ans << endl;
		}
	}

	return 0;
}

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

typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

string s, t;
int ans;
int main(){
  cin >> s >> t;
  rep(i,3){
    if(s.at(i) == t.at(i)){
      ans++;
    }
  }
  cout << ans <<endl;
}



Measured memory_bytes: 256
# nCkの計算するやつ
# (n!)/(k!(n-k)!) mod p
# (n!) * (k!)^-1 * ((n-k)!)^-1 mod p

def comInit(MOD, n):
    fact=[1,1] # fact[n]はnの階乗
    invr=[0,1] # invr[n]はnの逆元
    invr_fact=[1,1] # invr_fact[n]は逆元の階乗

    for i in range(2,n+1):
        fact.append(fact[-1]*i%MOD)
        invr.append(-invr[MOD%i]*(MOD//i)%MOD)
        invr_fact.append(invr_fact[-1]*invr[-1]%MOD)
    return fact,invr_fact

def calCom(n,k,MOD,fact,invr_fact):
    k=min(k,n-k)
    return fact[n]*invr_fact[k]*invr_fact[n-k]%MOD

def main():
    x,y=map(int,input().split())

    if (x+y)%3!=0:
        print(0)
        return

    temp=int((x+y)/3)
    if temp*2 < x or temp > x:
        print(0)
        return
    f,inf=comInit(10**9+7,temp)
    # n,kはしっかりはっきりさせよ明日

    # ans=factorial(temp) / factorial(x-temp) / factorial(2*temp-x)
    ans=calCom(temp,abs(x-temp),10**9+7,f,inf)

    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 118636
package main

import "fmt"

func main() {
	var a, b, c int
	fmt.Scan(&a, &b, &c)

	slice := []int{a, b, c}

	var count int

	if slice[0] != slice[1] {
		count++
	}
	if slice[0] != slice[2] {
		count++
	}
	if slice[1] != slice[2] {
		count++
	}
	if (slice[0] == slice[1]) && (slice[0] == slice[2]) && (slice[1] == slice[2]) {
		count++
	}
	fmt.Println(count)
}

Measured memory_bytes: 1764
#include <stdio.h>

int
main(int argc, char *argv[])
{
  int n, a[100000], ans = - 1;
  scanf("%d", &n);
  for(int i = 0; i < n; i++){
    scanf("%d", &a[i]);
  }

  int b[100000], i = 0;
  b[0] = 1;
  while(1){
    b[i + 1] = a[b[i] - 1]; 
    if(b[i + 1] == 2){
      ans = i + 1;
      break;
    }
    else if(i == n) break;
    i++;
  }
  
  printf("%d\n", ans);
  
  return 0;
}

Measured memory_bytes: 512
import java.util.Scanner;
import java.util.HashMap;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        HashMap<Integer,Boolean> map= new HashMap<Integer,Boolean>();
        int N = sc.nextInt();
        int[] a = new int [N];
        for(int i = 0;i < N;i++){
            a[i] = sc.nextInt();
        }
        for(int i = 0;i < N;i++){
            if(map.containsKey(a[i]) && map.get(a[i])){
                map.put(a[i],false);
            }
            else{
                map.put(a[i],true);
            }
        }
        int count = 0;
        for(Integer key : map.keySet()){
            if(map.get(key)){
                count++;
            }
        }
        System.out.println(count);
    }
}


Measured memory_bytes: 54168
s = input()

ans1 = 0
for i in range(len(s)):
    if i%2==0:
        if s[i] != '0':
            ans1 += 1
    else:
        if s[i] != '1':
            ans1 += 1

ans2 = 0
for i in range(len(s)):
    if i%2==0:
        if s[i] != '1':
            ans2 += 1
    else:
        if s[i] != '0':
            ans2 += 1

print(min(ans1, ans2))

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

//Rummy
public class Main{

	int[] a, c;
	int[][] as;
	char[] s;
	
	boolean dfs(int k){
		if(k==9){
			for(int i=0;i<3;i++)if(s[as[i][0]]!=s[as[i][1]]||s[as[i][1]]!=s[as[i][2]])return false;
			for(int i=0;i<3;i++){
				int[] t = new int[3];
				for(int j=0;j<3;j++)t[j]=a[as[i][j]];
				Arrays.sort(t);
				if(!(t[0]==t[1]&&t[1]==t[2]||t[0]+1==t[1]&&t[1]+1==t[2]))return false;
			}
			return true;
		}
		for(int i=0;i<3;i++){
			if(c[i]==3)continue;
			as[i][c[i]] = k;
			c[i]++;
			if(dfs(k+1))return true;
			c[i]--;
		}
		return false;
	}
	
	void run(){
		Scanner sc = new Scanner(System.in);
		int T = sc.nextInt();
		while(T--!=0){
			a = new int[9]; s = new char[9]; c = new int[3];
			for(int i=0;i<9;i++)a[i]=sc.nextInt();
			for(int i=0;i<9;i++)s[i]=sc.next().charAt(0);
			as = new int[3][3];
			System.out.println(dfs(0)?1:0);
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 12000
#include <bits/stdc++.h> // only for GCC
using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

template<class T> inline T sqr(T x) {return x*x;}

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

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

const double EPS = 1e-10;
const double PI  = acos(-1.0);

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

int main() {
  int n, m;

  while(cin >> n >> m, n+m) {
    VI v;
    int x;

    REP(i, n) {
      cin >> x;
      v.PB(x);
    }
    sort(ALL(v), greater<int>());

    int ans = 0;
    REP(i, n) {
      if(i%m != m-1) ans += v[i];
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 1228
package main

import (
	"fmt"
)

func main() {
	var N int
	fmt.Scan(&N)
	p := make([]int, N+1)
	for i := 1; i <= N; i++ {
		fmt.Scan(&p[i])
	}

	s := false
	for i := 1; i <= N; i++ {
		if !s && i != p[i] {
			p[i], p[p[i]] = p[p[i]], p[i]
			s = true
		}

		if i != p[i] {
			fmt.Println("NO")
			return
		}
	}
	fmt.Println("YES")
}


Measured memory_bytes: 512
#include <iostream>

int main()
{
    long long h, w;
    std::cin >> h >> w;
    if (h == 1 || w == 1)
    {
        std::cout << 1 << std::endl;
        return 0;
    }

    long long oddH = (h + 1) / 2;
    long long oddW = (w + 1) / 2;
    long long evenH = h / 2;
    long long evenW = w / 2;

    long long ans = oddH * oddW + evenH * evenW;

    std::cout << ans << std::endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
ll n, k;
cin >> n >> k;
vector<ll> all_snakes(n);
for (int i = 0; i < n; i++) all_snakes[i] = i + 1;
unordered_set<ll> all_snakes_set(all_snakes.begin(), all_snakes.end());
unordered_set<ll> done;
for (int i = 0; i < k; i++) {
ll d;
cin >> d;
for (int i = 0; i < d; i++) {
ll u;
cin >> u;
done.insert(u);
}
}
ll ds = done.size();
cout << n - ds << endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
#include <iomanip>
using namespace std;
#define pb push_back
#define mp make_pair
typedef pair<int,int> pii;
typedef long long ll;
typedef double ld;
typedef vector<int> vi;
#define fi first
#define se second
#define fe first
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define Edg int M=0,fst[SZ],vb[SZ],nxt[SZ];void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}void adde(int a,int b){ad_de(a,b);ad_de(b,a);}
#define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);}
#define es(x,e) (int e=fst[x];e;e=nxt[e])
#define esb(x,e,b) (int e=fst[x],b=vb[e];e;e=nxt[e],b=vb[e])
#define VIZ {printf("digraph G{\n"); for(int i=1;i<=n;i++) for es(i,e) printf("%d->%d;\n",i,vb[e]); puts("}");}
#define VIZ2 {printf("graph G{\n"); for(int i=1;i<=n;i++) for es(i,e) if(vb[e]>=i)printf("%d--%d;\n",i,vb[e]); puts("}");}
#define SZ 666666
ll Q,H,S,D,N;
int main()
{
	cin>>Q>>H>>S>>D>>N;
	H=min(H,Q+Q);
	S=min(S,H+H);
	D=min(D,S+S);
	ll ans=N/2*D+(N&1)*S;
	cout<<ans<<"\n";
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <cassert>
using namespace std;
#define MOD 1000000007

long long dp0[111111];
long long dp1[111111];

int main(){
    string L;
    cin >> L;
    int N = L.size();
    dp0[0] = 1;
    for(int i=0; i<N; i++){
        if(L[i] == '0'){
            dp0[i+1] = dp0[i];
            dp1[i+1] = (3 * dp1[i]) % MOD;
        }else{
            dp0[i+1] = (2 * dp0[i]) % MOD;
            dp1[i+1] = (dp0[i] + (3 * dp1[i]) % MOD) % MOD;
        }
    }
    cout << (dp0[N] + dp1[N]) % MOD << endl;

    return 0;
}

Measured memory_bytes: 2048
#include<cstdio>
#include<algorithm>
using namespace std;

int main(){
  while(true){
    int w,h,n;
    static int cnt[1000][1000],dir[1000][1000],field[1000][1000];
    scanf("%d %d %d",&h,&w,&n);
    if(h==0&&w==0&&n==0) return 0;
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
        scanf("%d",&dir[i][j]);
        if(i==0&&j==0) cnt[i][j] = n - 1;
        else if(i==0) cnt[i][j] = cnt[i][j - 1] / 2 + ((cnt[i][j - 1]) % 2) * dir[i][j - 1];
        else if(j==0) cnt[i][j] = cnt[i - 1][j] / 2 + ((cnt[i - 1][j]) % 2) * (1^dir[i - 1][j]);
        else cnt[i][j] = cnt[i - 1][j] / 2 + ((cnt[i - 1][j]) % 2) * (1^dir[i - 1][j]) + cnt[i][j - 1] / 2 + ((cnt[i][j - 1]) % 2) * dir[i][j - 1];
        field[i][j] = (dir[i][j] + cnt[i][j]) % 2;
      }
    }
    int x = 0, y = 0;
    while(x<h&&y<w){
      if(field[x][y]) y++;
      else x++;
    }
    printf("%d %d\n",x+1,y+1);
  }
}

Measured memory_bytes: 14428
#include <bits/stdc++.h>
#define ll long long
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) // rep(i, 1, 5) --> {1,2,3,4} // rep(i, 5, 1) --> {4,3,2,1} // rep(it, end(v), begin(v)) --> *it

using namespace std;

int main()
{   
    ll n,m;
    cin >> n >> m;
    vector<double> v(n);
    queue<double> q;
    rep(i, 0, n)
        cin >> v[i];
    sort(begin(v), end(v));
    ll i = v.size() - 1;
    double curr = v[i];
    while(m--)
    {
        curr = curr / 2.0;
        curr = (curr-(ll)curr>0.5?ceil(curr):floor(curr));
        q.push(curr);
        if (m == 0)
            break;
        if (!q.empty() && i != 0 && q.front() > v[i-1])
        {
            curr = q.front();
            q.pop();
        }
        else if (i == 0)
        {
            curr = q.front();
            q.pop();
        }
        else         
        {
            i--;
            curr = v[i];
        }
    }
    ll res = 0;
    while (!q.empty())
    {
        double x = q.front();
        q.pop();
        res += x;
    }
    rep(j, 0, i)
        res += v[j];
    cout << res;
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>

#include <bits/stdc++.h>
#include<string>
#include<string.h>
#define ll long long
#define ll long long
#define ld long double
#define ctoi(x) x-'0'
#define pshb(a) cin >> x;a.push_back(x)
#define fr(i,n) for(ll i=0;i<n;i++)
#define alph "abcdefghijklmnopqrstuvwxyz"
#define alph1 "abcdefghijklmnopqrstuvwxyz"
#include <vector>#include <bits/stdc++.h>
#include<string>
#include<string.h>
#define ll long long
#define ll long long
#define ld long double
#define ctoi(x) x-'0'
#define pb(x) cin>>x; a.push_back(x)
#define srt() sort(a.begin(),a.end())
#define fr(i,n) for(ll i=0;i<n;i++)
#define alph "abcdefghijklmnopqrstuvwxyz"
#define alph1 "abcdefghijklmnopqrstuvwxyz"
#include <vector>
#include<math.h>
#define WUBBAxxLUBAxxDUBxxDUB int main
#define salamo3lekooooom ios::sync_with_stdio(false)
using namespace std;
bool sortbysec(const pair<int,int> &a,
               const pair<int,int> &b)
{
    return (a.second < b.second);
}
#define LIMIT 1000000
long long i, j;
long long prime_flag[LIMIT];
void calculate_prime_flag()
{
    prime_flag[0] = prime_flag[1] = 1;
    for(i=2; i<LIMIT; i++)
    {
        if (prime_flag[i]==0)
        {
            for(j=i*i; j<LIMIT; j+=i)
            {
                prime_flag[j] = 1;
            }
        }
    }
}

#include <iostream>
#include <math.h>
using namespace std;
// Get SHWIFTY
vector<string>v;
int LPS(char *str)
{
    int n=strlen(str);
    int i,j,cl;
    int l[n][n];
    for(i=0; i<n; i++)
        l[i][i]=1;
    for(cl=2; cl<=n; cl++)
    {
        for(i=0; i<n-cl+1; i++)
        {
            j=i+cl-1;
            if(str[i]==str[j]&&cl==2)
                l[i][j]=2;
            else if (str[i]==str[j])
                l[i][j]=l[i+1][j-1]+2;
            else
                l[i][j]=max(l[i][j-1],l[i+1][j]);


        }
    }
    return l[0][n-1];


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

// Function to find gcd of array of
// numbers
int findGCD(int arr[], int n)
{
    int result = arr[0];
    for (int i = 1; i < n; i++)
        result = gcd(arr[i], result);

    return result;
}
/////3aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa


vector <int> adj[10];
    bool visited[10];

    void dfs(int s) {
        visited[s] = true;
        for(int i = 0;i < adj[s].size();++i)    {
         if(visited[adj[s][i]] == false)
             dfs(adj[s][i]);
        }
    }

    void initialize() {
        for(int i = 0;i < 10;++i)
         visited[i] = false;
    }

WUBBAxxLUBAxxDUBxxDUB()
{
    salamo3lekooooom;
    ll n;
    cin>>n;
    ll x;
    vector<ll>a;
    for(int i=0;i<n;i++)
    {
        cin>>x;
        a.push_back(x);
    }
    sort(a.begin(),a.end());
        ll sum=0;
    for(int i=0;i<n;i++)
    {
        for(int j=i+1;j<n;j++)
        {
            sum+=a[i]*a[j];
        }
    }
    cout<<sum<<endl;

}


Measured memory_bytes: 256
n = int(input())
p = list(map(int, input().split()))
q = list(range(1, n + 1))

if p == q:
    print('YES')
else:
    count = 0
    for i in range(n):
        a = p[i] - q[i]
        if a == 0:
            count += 1
    if count == n - 2:
        print('YES')
    else:
        print('NO')

Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		Scanner sc = new Scanner(System.in);
	     int a= sc.nextInt();
	     int h,m,s;
	     int x,y;

	     h=a/3600;
	     x=a%3600;
	     m=x/60;
	     s=x%60;

	     System.out.println(h+":"+m+":"+s);

	}
}

Measured memory_bytes: 26312
//#include <bits/stdc++.h>
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <limits.h>
#include <algorithm>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <bitset>
#include <string>
#include <time.h>
using namespace std;
long double esp=1e-11;
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define cle(a) while(!a.empty())a.pop()
#define mem(p,c) memset(p,c,sizeof(p))
#define mp(A, B) make_pair(A, B)
#define pb push_back
typedef long long int LL;
const long double PI = acos((long double)-1);
const LL INF=0x3f3f3f3f3f3f3f3fll;
const int MOD =1000000007ll;
const int maxn=100100;
char s[100];
char g[100];
int main()
{
    //freopen("in.txt", "r", stdin);
    //freopen("in1.txt", "w", stdout);
    //::iterator iter;                  %I64d
    //for(int x=1;x<=n;x++)
    //for(int y=1;y<=n;y++)
    //scanf("%d",&a);
    //printf("%d\n",ans);
    printf("? 1000000000000\n");
	fflush(stdout);
	scanf("%s",s);
	if(s[0]=='Y')
	{
		LL ans=1;
		LL tem=9;
		for(int x=1;x<=10;x++)
		{
			printf("? %lld\n",tem);
			fflush(stdout);
			scanf("%s",s);
			if(s[0]=='Y')
				break;
			ans*=10;
			tem=tem*10+9;
		}
		printf("! %lld\n",ans);
		fflush(stdout);
		return 0;
	}
	else
	{
		g[0]='1';
		for(int x=1;x<=10;x++)
		{
			g[x]='0';
			printf("? %s\n",g);
			fflush(stdout);
			scanf("%s",s);
			if(s[0]=='N')
			{
				g[x]='\0';
				break;
			}
		}
		int len=strlen(g);
		if(len==1)
		{
			for(int x=1;x<=9;x++)
			{
				printf("? %d\n",x*10);
				fflush(stdout);
				scanf("%s",s);
				if(s[0]=='Y')
				{
					printf("! %d\n",x);
					fflush(stdout);
					return 0;
				}
			}
		}
		for(int x=0;x<=len-2;x++)
		{
			int l,r;
			if(x==0)l=1;
			else l=0;
			r=9;
			while(l<r)
			{
				int m=(l+r+1)/2;
				g[x]=m+'0';
				string ss(g,g+x+1);
				printf("? %s\n",ss.c_str());
				fflush(stdout);
				scanf("%s",s);
				if(s[0]=='Y')l=m;
				else r=m-1;
			}
			g[x]=l+'0';
		}
		g[len]='9';
		for(int x=0;x<=9;x++)
		{
			g[len-1]='0'+x;
			string ss(g,g+len+1);
			printf("? %s\n",ss.c_str());
			fflush(stdout);
			scanf("%s",s);
			if(s[0]=='Y')
			{
				string ss(g,g+len);
				printf("! %s\n",ss.c_str());
				fflush(stdout);
				return 0;
			}
		}
	}
	return 0;
}


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

int main() {
	int N;
	cin >> N;
	int A[2][100];
	int S[3][100];
	int result=0;
	for (int i = 0; i < 2; ++i) {
		for (int j = 0; j < N; ++j) cin >> A[i][j];
	}
	S[0][0] = A[0][0];
	S[1][N-1] = A[1][N-1];
	for (int j = 1; j < N; ++j) {
		S[0][j] = S[0][j - 1] + A[0][j];
		S[1][N - 1 - j] = S[1][N - j] + A[1][N - 1 - j];
	}
	for (int j = 0; j < N; ++j) {
		int temp_ = S[0][j] + S[1][j];
		if (temp_ > result) result = temp_;
	}
	cout << result << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream> //入出力
#include <stdio.h>
#include <map>
#include <string>
#include <math.h>
#include <vector>
#include <cstdlib>
#include <queue>
#include <stack>

#include <iomanip> //小数点以下を表示させる(setprecision())

#define debug(x) cerr << x << " " \
                      << "(L:" << __LINE__ << ")" << '\n'
#define PRINT(V)                                   \
        {                                          \
                for (int i = 0; i < V.size(); i++) \
                {                                  \
                        cout << V[i] << " ";       \
                }                                  \
                cout << endl;                      \
        }

typedef long long ll; //64bit型
using namespace std;
const ll INF = 1LL << 20;

int main()
{
        int N;
        cin >> N;
        vector<int> vec(N + 1);
        for (int i = 0; i < N; i++)
        {
                cin >> vec[i];
        }

        int ans = 1e9;
        for (int i = -100; i <= 100; i++)
        {
                debug(i);
                int cost = 0;
                for (int j = 0; j < N; j++)
                {
                        cost += ((vec[j] - i) * (vec[j] - i));
                }
                ans = min(ans, cost);
        }
        cout << ans << endl;
}

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

int main() {
    char s[12];
    fgets(s, 12, stdin);
    int len = strlen(s);
    if (s[len-1] == '\n')  len--;
    int s_n = 0;
    for (int i=0; i<len; i++) {
        s_n += s[i] - '0';
    }
    int n = 0;
    sscanf(s, "%d", &n);
    if (n%s_n == 0) printf("Yes\n");
    else printf("No\n");
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using pii = pair<int, int>;

//const ll INF = 1e18L + 5;
//const int INF = 1e9 + 5;
//const double pi = 3.14159265358979323846;

#include <bits/stdc++.h>

using namespace std;

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

	int n;
	string s;
	cin >> n >> s;
	for (char c : s) {
		int i = c - 'A';
		cout << (char)('A' + ((i + n) % 26));
	}
	cout << endl;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtcoderCS
{
    class Program
    {
        static void Main(string[] args)
        {
            long N = long.Parse(Console.ReadLine());

            string s = Console.ReadLine();

            long[] L = s.Split().Select(a => long.Parse(a)).ToArray();

            var length = L.Length;

            long answer = 0;
            for(long i = 0; i < length; i++)
            {
                //Console.WriteLine(L[i]);
                for (long j = i+1; j < length; j++)
                {
                    for(long k = j+1;k < length; k++)
                    {
                        if(L[i] != L[j] && L[j] != L[k] && L[i] != L[k] && Math.Abs(L[i] - L[j]) < L[k] && L[k] < L[i] + L[j])
                        {
                            //Console.WriteLine(i.ToString() + ":" + j.ToString() + ":" + k.ToString());
                            answer++;
                        }
                    }
                }
            }

            Console.WriteLine(answer);
        }
    }
}


Measured memory_bytes: 28196
#include <cstdio>
#include <cstring>
#include <vector>

using namespace std;

const int N = 200'009;

int a[N];
int f[N];

int main() {
  int n;
  scanf("%d", &n);
  memset(a, 0, sizeof a);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", a + i);
  }
  vector<int> ans;
  for (int i = n; i >= 1; --i) {
    int s = 0;
    for (int j = 2 * i; j <= n; j += i) {
      s += f[j];
    }
    f[i] = s % 2 != a[i];
    if (f[i] == 1) {
      ans.push_back(i);
    }
  }
  printf("%d\n", (int)ans.size());
  for (int i = 0; i < (int)ans.size(); ++i) {
    if (i > 0) {
      putchar(' ');
    }
    printf("%d", ans[i]);
  }
  if (!ans.empty()) {
    putchar('\n');
  }
}


Measured memory_bytes: 3192
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back 
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>
#define ld long double
#define int long long int 
#define F first 
#define S second

signed main()
{
    fast;
    int a,b;
    cin>>a>>b;
    if(a<=9 && b<=9)
        cout<<a*b;
    else cout<<-1;
}

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

#[allow(unused_macros)]
macro_rules! debug {
    ( $x:ident [ $i:expr ] ) => {
        if cfg!(debug_assertions) {
            println!("{}[{}] = {:?}", stringify!($x), $i, $x[$i]);
        }
    };
    ( $x:ident [ $i:expr ][ $j:expr ] ) => {
        if cfg!(debug_assertions) {
            println!("{}[{}][{}] = {:?}", stringify!($x), $i, $j, $x[$i][$j]);
        }
    };
    ( $x:expr ) => {
        if cfg!(debug_assertions) {
            println!("{}:{} {} = {:?}", line!(), column!(), stringify!($x), $x);
        }
    };
}

fn main() {
    let stdin = std::io::stdin();
    let mut stdin = my::io::InputReader::new(stdin.lock());

    let N: usize = stdin.read();
    let mut n_children = vec![0usize; N];
    for _ in 0..N - 1 {
        let A = stdin.read::<usize>() - 1;
        n_children[A] += 1;
    }
    for i in 0..N {
        println!("{}", n_children[i]);
    }
}

#[allow(unused_must_use)]
mod my {
    pub mod io {
        use std::io::{BufRead, ErrorKind, Result};
        use std::str::{FromStr, from_utf8};
        use std::fmt::Debug;

        pub fn read_word<R: BufRead>(r: &mut R, buf: &mut Vec<u8>)
                                              -> Result<usize> {
            let mut read = 0;
            loop {
                let (done, used) = {
                    let available = match r.fill_buf() {
                        Ok(n) => n,
                        Err(ref e) if e.kind() == ErrorKind::Interrupted => continue,
                        Err(e) => return Err(e)
                    };
                    match available.iter().position(|&x| x == b'\n' || x == b' ') {
                        Some(i) => {
                            buf.extend_from_slice(&available[..i]);
                            (true, i + 1)
                        }
                        None => {
                            buf.extend_from_slice(available);
                            (false, available.len())
                        }
                    }
                };
                r.consume(used);
                read += used;
                if done || used == 0 {
                    return Ok(read);
                }
            }
        }

        pub struct InputReader<R: BufRead> {
            reader: R,
            buf: Vec<u8>,
        }

        impl<R: BufRead> InputReader<R> {
            pub fn new(reader: R) -> InputReader<R> {
                InputReader {
                    reader: reader,
                    buf: Vec::<u8>::new(),
                }
            }

            pub fn read_word(&mut self) {
                read_word(&mut self.reader, &mut self.buf);
            }
            
            pub fn read<T>(&mut self) -> T
                where T: FromStr,
                      T::Err: Debug
            {
                self.buf.clear();
                self.read_word();
                from_utf8(&self.buf).unwrap().trim().parse().unwrap()
            }
        }
    }
}


Measured memory_bytes: 3584
const input = require('fs').readFileSync('/dev/stdin', 'utf8');
const lines = input.trim().split('\n');

let array;
let index = 0;
let n;
let m;
let answers = [];
while (line = lines.shift()) {
    if(index === 0){
        const test = line.split(' ').map(Number);
        n = test[0];
        m = test[1];
        index ++;
    } else {
        array = line.split(' ').map(Number);


        let answer = 0;
        for(let i = 0; i<n ;i++){
            for(let j = 0;j<n;j++){
                if(i === j){
                    continue;
                }
                const test = array [i] + array [j];
                if(test > answer && test <= m){
                    answer = test;
                }
            }
        }
        index = 0;
        answers.push(answer);

    }
}
answers.forEach(data => console.log(data ? data : 'NONE'))


Measured memory_bytes: 18552
def main():

    H, W = map(int, input().split())
    S = []
    for _ in range(H):
        S.append(input())

    ans = 0
    mv = [[1,0], [-1,0], [0, 1], [0,-1]]
    for i in range(H):
        for j in range(W):
            if S[i][j] == ".":
                cnt = 0
                cur = [[i, j]]
                visited = set([(i, j)])
                while cur:
                    temp = []
                    for k, l in cur:
                        for dk, dl in mv:
                            k1, l1 = k+dk, l+dl
                            if 0<=k1<H and 0<=l1<W and S[k1][l1] == "." and (k1,l1) not in visited:
                                visited.add((k1,l1))
                                temp.append([k1, l1])
                    cur = temp
                    if len(cur) > 0: cnt += 1
                ans = max(ans, cnt)
    return ans

if __name__ == '__main__':
    print(main())

Measured memory_bytes: 43356
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

s = input()

g = s.count("g")
p = s.count("p")
if len(s) % 2 == 0:
	print(int(len(s)/2 - p))
else:
	print(int((len(s)-1)/2 - p))

Measured memory_bytes: 4084
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
    	InputStream inputStream = System.in;
    	OutputStream outputStream = System.out;
    	Scanner sc = new Scanner(inputStream);
    	PrintWriter out = new PrintWriter(outputStream);
      	int N = Integer.parseInt(sc.next());
      	String S = sc.next();
      	int ans = 0;
		for(int i = 1; i < N; i++){
          //out.println(S.substring(0, i) + " " + S.substring(i, N));
         	int count = Count(S.substring(0, i), S.substring(i, N));
          	ans = Math.max(ans, count);
        }
      	out.println(ans);
    	out.close();
    }
  	private static int Count(String front, String back){
      	int count = 0;
      	for(char c = 'a'; c <= 'z'; c++){
          	boolean front_judge = false;
      		boolean back_judge = false;
        	for(int i = 0; i < front.length(); i++){
              	if(c == front.charAt(i)){ front_judge = !front_judge; break;}
            }
          	for(int i = 0; i < back.length(); i++){
              	if(c == back.charAt(i)){ back_judge = !back_judge; break;}
            }
          if(front_judge && back_judge){
          	count++;
          }
        }
    	return count;
    }
}

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

using namespace std;

int main() {
	long long int n;
	cin >> n;
	vector<long long int> a(n);
	for (long long int i = 0; i < n; i++) {
		cin >> a[i];
	}

	long long int cc = 1;
	long long int ans = 0;

	sort(a.begin(), a.end());

	for (long long int i = 1; i < n; i++) {
		if (a[i] == a[i - 1]) {
			cc++;
		}
		else {
			if (a[i-1] < cc) {
				ans += cc - a[i-1];
			}
			else if (a[i-1] != cc){
				ans += cc;
			}
			cc = 1;
		}
	}

	if (a[n - 1] < cc) {
		ans += cc - a[n - 1];
	}
	else if (a[n - 1] != cc) {
		ans += cc;
	}
	cout << ans << endl;

	return 0;
}

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

using namespace std;

const int N=110;

int h,w;
char g[N][N];
bool vish[N],visw[N];

int main()
{
	cin>>h>>w;
	for(int i=1;i<=h;++i)
	{
		for(int j=1;j<=w;++j)
		{
			cin>>g[i][j];
			if(g[i][j]=='#')
			{
				vish[i]=true;
				visw[j]=true;
			}
		}
	}
	bool ok;
	for(int i=1;i<=h;++i)
	{
		ok=true;
		for(int j=1;j<=w;++j)
		{
			if(!vish[i]||!visw[j])continue;
			cout<<g[i][j];
			ok=false;
		}
		if(!ok)cout<<endl;
	}
	//for(int i=1;i<=h;++i){if(vish[i])cout<<"true"<<" ";else cout<<"false"<<" ";}
//	cout<<endl;
	//for(int i=1;i<=w;++i){if(visw[i])cout<<"true"<<" ";else cout<<"false"<<" ";}
	return 0;
}

Measured memory_bytes: 256
from sys import stdin, setrecursionlimit
from itertools import accumulate

setrecursionlimit(10 ** 9)
INF = 1 << 60


def input():
    return stdin.readline().strip()


def prime_numbers(n):
    if n < 2:
        return []

    m = (n + 1) // 2
    p = [True] * m
    for i in range(1, int((n ** 0.5 - 1) / 2) + 1):
        if p[i]:
            for j in range(2 * i * (i + 1), m, 2 * i + 1):
                p[j] = False

    return {2} | {2 * i + 1 for i in range(1, m) if p[i]}

def main():
    N = 10 ** 5
    primes = prime_numbers(N)
    a = [1 if n in primes and (n + 1) // 2 in primes else 0 for n in range(N + 1)]
    a = tuple(accumulate(a))

    ans = []
    Q, *LR = map(int, open(0).read().split())
    for l, r in zip(*[iter(LR)] * 2):
        ans.append(a[r] - a[l - 1])

    print('\n'.join(map(str, ans)))

if __name__ == "__main__":
    main()

Measured memory_bytes: 29016
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
#include<cstdio>
#include<cstdlib>
#include<unordered_map>
#include<unordered_set>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592
#define PI acos(-1.0);

const double EPS = 1e-10;

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;




int main(){
	int a,b,c,x,y; cin >> a >> b >> c >> x >> y;
	if(a+b<2*c){
		cout << a*x+b*y << endl;
	}
	else{
		int d = min(x,y);
		int e = max(x,y);
		x-=d,y-=d;
		cout << min(2*c*e,2*c*d+a*x+b*y) << endl;
	}
}



Measured memory_bytes: 256
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		string str = Console.ReadLine();
		string str2 = Console.ReadLine();
		int N = int.Parse(str2);
		string ans = "";
		int i = 0;
		while(true){
			ans += str.Substring(i,1);
			i += N;
			if(i>=str.Length){
				break;
			}
		}
		Console.WriteLine(ans);
	}
}

Measured memory_bytes: 13140