akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ull = unsigned long long;

void ABC132E()
{
	int N, M;
	cin >> N >> M;
	vector<set<int> > graph(N);
	for (int i = 0; i < M; ++i)
	{
		int u, v;
		cin >> u >> v;
		graph[u-1].insert(v-1);
	}
	int S, T;
	cin >> S >> T;
	--S; --T;
	vector<int> dist(N, N+5);
	queue<int> qu;
	dist[S] = 0;
	qu.push(S);
	set<int> checked1st;
	set<int> checked2nd;
	while (!qu.empty())
	{
		int x = qu.front(); qu.pop();
		int d = dist[x];
		for (auto y : graph[x])
		{
			if (checked1st.find(y) != checked1st.cend())
				continue;
			checked1st.insert(y);

			for (auto z : graph[y])
			{
				if (checked2nd.find(z) != checked2nd.cend())
					continue;
				checked2nd.insert(z);
				for (auto u : graph[z])
				{
					if (dist[u] > d + 1)
					{
						dist[u] = d + 1;
						qu.push(u);
						if (u == T)
						{
							cout << d + 1 << endl;
							return;
						}
					}
				}
			}
		}
	}
	cout << -1 << endl;
}

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

Measured memory_bytes: 19328
// C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#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>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
// #include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// 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>

#if __cplusplus >= 201103L
#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>
#endif

using namespace std;
typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;
#define REP(i,n) for(ll i=0; i<(n); i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define ALL(n) begin(n),end(n)
#define IN(a, x, b) (a<=x && x<b)
#define INIT std::ios::sync_with_stdio(false);std::cin.tie(0);
template<class T> inline T CHMAX(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T CHMIN(T & a, const T b) { return a = (a > b) ? b : a; }

const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);
const long long MOD = 1000000007;

int main(void){
    ll x;
    cin >> x;
    if(x >= 30){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;

    }
    return 0;
}

Measured memory_bytes: 3120
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        if ((a*b)%2==0){
            System.out.println("Even");
        }else{
            System.out.println("Odd");
        }
    }
}

Measured memory_bytes: 21972
import java.util.Arrays;
    import java.util.HashMap;
    import java.util.Scanner;
    import java.util.Map;
    class Main{
      public static void main(String[] args){
       Scanner sc = new Scanner(System.in);
       int n = sc.nextInt();
       HashMap<String,Integer> ars = new HashMap<>();
       long a = 0L;
       for(int i = 0; i < n; i++){
         char[] input = sc.next().toCharArray();
         Arrays.sort(input);
         String str = String.valueOf(input);
         int cnt=0;
         if(ars.containsKey(str)){
           cnt = ars.get(str);
           a += cnt;
         } 
         ars.put(str,cnt+1);
       }
       System.out.println(a);
      }
    }

Measured memory_bytes: 52484
#include <iostream>
#include <cmath>
#include <vector>
#include <stack>
#include <algorithm>
using namespace std;
int main () {
while(true){
	int a,b;
	cin >> a >> b;
	if(a == 0 && b == 0){
		break;
	}
	int n;
	cin >> n;
	int blockX[n];
	int blockY[n];
	for(int i = 0; i < n; i++){
		cin >> blockX[i] >> blockY[i];
	}
	int map[a][b];
	//initialize map
	for(int i = 0; i < a; i++){
		for(int j = 0; j < b; j++){
			map[i][j] = 0;
		}
	}
	for (int i = 0; i < a; i++)
	{
		/* code */
		map[i][0] = 1;
	}
	for (int i = 0; i < b; i++)
	{
		/* code */
		map[0][i] = 1;
	}
	for(int i = 0; i < n; i++) {
		map[blockX[i]-1][blockY[i]-1] = -1;
		if(blockX[i]-1 == 0){
			for (int j = blockY[i]; j < b; ++j)
			{
				/* code */
				map[0][j] = 0;
			}

		}
		if(blockY[i]-1 == 0){
			for (int j = blockX[i]; j < a; ++j)
			{
				/* code */
				map[j][0] = 0;
			}
			
		}

	}
	//end initialize map
	for(int x = 1; x < a; x++){
		for(int y = 1; y < b; y++){
			if(map[x][y] != -1){
				if(map[x-1][y] != -1){
					map[x][y] += map[x-1][y];
				}
				if(map[x][y-1] != -1){
					map[x][y] += map[x][y-1];
				}
			}
		}
	}
	cout << map[a-1][b-1] << endl;
}

}


Measured memory_bytes: 3068
#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(){
    ll s; cin >> s;
    int x1 = 0,y1 = 0;
    int x2 = 1000000000;
    int y3 = s/x2;
    int y2 = 1;
    int x3 = x2-s%x2;
    y3++;
    if(s == 1e18) y2 = 0,x3 = 0,y3--;
    cout << x1 << " " << y1 << " " << x2 << " " << y2 << " " << x3 << " " << y3 << endl;
}



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

using ll = long long;
const ll MOD = 998244353;

int main() {
    int K, X;
    cin >> K >> X;
    if (K * 500 >= X) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve(args);
    }

    public void solve(String[] args) {
        MyScanner scanner = new MyScanner();
        int n = scanner.nextInt();
        int tmp;
        int max1=0;
        int max2=0;
        int[] array = new int[n];

        for(int i=0;i<n;i++) {
        	array[i] = scanner.nextInt();
        	if(array[i]>max1) {
        		max2 = max1;
        		max1 = array[i];
        	}else if(array[i]>max2) {
        		max2 = array[i];
        	}
        }
        for(int j=0;j<n;j++) {
        	if(array[j]!=max1) {
        		System.out.println(max1);
        	}else {
        		System.out.println(max2);
        	}
        }
    }

    private static long gcd(long m, long n) {
        if(m < n) return gcd(n, m);
        if(n == 0) return m;
        return gcd(n, m % n);
    }

    private static long lcm(long m, long n) {
        return m * n / gcd(m, n);
    }

    private class MyScanner {
        String[] s;
        int i;
        BufferedReader br;
        String reg = " ";
        MyScanner () {
            s = new String[0];
            i = 0;
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        public String next() {
            try {
                if (i < s.length) return s[i++];
                String line = br.readLine();
                while (line.equals("")) {line = br.readLine();}
                s = line.split(reg, 0);
                i = 0;return s[i++];
            } catch (Exception e) {e.printStackTrace();}
            return null;
        }
        public int nextInt() {
            try {return Integer.parseInt(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
        public double nextDouble() {
            try {return Double.parseDouble(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
        public long nextLong()  {
            try {return Long.parseLong(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
    }
}

Measured memory_bytes: 57096
while True:
    n = int(input())
    if n == 0: break
 
    data = {}
    staff = []
    for i in range(n):
        tmp = list(map(int, input().split(' ')))
        if tmp[0] in data:
            data[tmp[0]] += tmp[1] * tmp[2]
        else:
            data[tmp[0]] = tmp[1] * tmp[2]
            staff.append(tmp[0])
 
    if max(data.values()) < 1000000:
        print('NA')
    else:
        for k in staff:
            if data[k] >= 1000000:
                print(k)

Measured memory_bytes: 6752
#include"bits/stdc++.h"
using namespace std;

void Main() {
  string s;
  cin >> s;
  int ans = 0;
  for (int i = 0; i < s.size() / 2; i++) {
    if (s[i] != s[s.size() - 1 -i]) ans++;
  }
  cout << ans << endl;
}

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


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <set>
#include <queue>
#include <map>
#include <numeric>
#include <functional>
#include <math.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

#define INF ((int)1e9)
#define INFLL ((ll)1e18)
#define MOD (1000000007LL)


int main(int argc, const char * argv[]) {
    ios_base::sync_with_stdio(false);
    
    int N, K;
    cin >> N >> K;
    
    double Ret = 0.0;
    if (N >= K) {
        Ret += double(N-K+1)/N;
    }
    int p = 1;
    for (int n = min(K-1, N); n >= 1; --n) {
        while (n * (1 << p) < K) ++p;
        Ret += pow(2.0, -p)/N;
    }
    cout.precision(15);
    cout << Ret << endl;

    return 0;
}


Measured memory_bytes: 256
n, m = map(int, input().split())
L = 0
R = 100000

for i in range(m):
    l, r = map(int, input().split())
    if l > L:
        L = l
    if r < R:
        R = r

if L <= R:
    print(R - L + 1)
else:
    print(0)

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
using P = pair<int, int>;
P u = P(-1, 0);
P d = P(1, 0);
P l = P(0, -1);
P r = P(0, 1);
P dir[4] = { u, d, l, r };

int main()
{
    int H, W;
    scanf("%d %d", &H, &W);
    vector<vector<bool>> s(H, vector<bool>(W));
    int white = 0;
    for (int i = 0; i < H; ++i)
    {
        char str[60];
        scanf("%s", str);
        for (int j = 0; j < W; ++j)
        {;
            if (str[j] == '.')
            {
                s[i][j] = true;
                ++white;
            }
            else
            {
                s[i][j] = false;
            }
        }
    }
    constexpr int inf = 1 << 30;
    vector<vector<int>> dp(H, vector<int>(W, inf));
    dp[0][0] = 0;
    queue<P> q;
    q.push(P(0, 0));
    while(!q.empty())
    {
        P cur = q.front();
        q.pop();
        for (int i = 0; i < 4; ++i)
        {
            P next = P(cur.first + dir[i].first, cur.second + dir[i].second);
            if (next.first >= 0 && next.first < H && next.second >= 0 && next.second < W && s[next.first][next.second])
            {
                dp[next.first][next.second] = dp[cur.first][cur.second] + 1;
                s[next.first][next.second] = false;
                q.push(next);
            }
        }
    }
    
    if (s[H - 1][W - 1])
    {
        printf("%d\n", -1);
        return 0;
    }

    printf("%d\n", white - 1 - dp[H - 1][W - 1]); // 原点(0, 0)の白1個を引く 
    
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<map>

int main()
{
	int n, tmp;
	std::map<int, int> v[2];

	v[0][0] = v[1][0] = 0;
	scanf("%d", &n);
	for (int i = 0; i < n; ++i)
	{
		scanf("%d", &tmp);
		if (v[i % 2].find(tmp) == v[i % 2].end())
			v[i % 2][tmp] = 1;
		else
			v[i % 2][tmp]++;
	}

	std::pair<int, int> max[2]{};
	int max_second[2]{};
	for (int i = 0; i < 2; ++i)
	{
		for (auto e : v[i])
			if (e.second > max[i].second)
				max[i] = e;
		v[i][max[i].first] = 0;
		for (auto e : v[i])
			if (e.second > max_second[i])
				max_second[i] = e.second;
	}

	if (max[0].first == max[1].first)
		printf("%d\n", n - std::max(max_second[0] + max[1].second, max_second[1] + max[0].second));
	else
		printf("%d\n", n - max[0].second - max[1].second);

	return 0;
}

Measured memory_bytes: 4864
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(long long i=0;i<(long long)(n);i++)
#define N 200010

long long kai[N];
long long rkai[N];
long long r2[N];
long long xx[30];
int yy[30];

void kaiz(void) {
	kai[0] = 1;
	f(i, N - 1) {
		kai[i + 1] = kai[i] * (i + 1);
		kai[i + 1] = kai[i + 1] % MOD;
	}
	int x = MOD - 2;
	f(i, 30) {
		if (x % 2 == 1)yy[i] = 1;
		else yy[i] = 0;
		x = x / 2;
	}
	f(i, N) {
		xx[0] = kai[i];
		f(j, 29) {
			xx[j + 1] = xx[j] * xx[j];
			xx[j + 1] = xx[j + 1] % MOD;
		}
		rkai[i] = 1;
		f(j, 30) {
			if (yy[j] == 1) {
				rkai[i] = rkai[i] * xx[j];
				rkai[i] = rkai[i] % MOD;
			}
		}
	}
	r2[0] = 1;
	f(i, N - 1)r2[i + 1] = (r2[i] * 500000004) % MOD;
}

long long ni(long long x, long long y) {
	if (x < 0 || y<0 || y>x)return 0;
	long long re = kai[x];
	re = re * rkai[x - y];
	re = re % MOD;
	re = re * rkai[y];
	re = re % MOD;
	return re;
}


int main() {
	long long ans[N];
	long long bv;
	long long wv;
	long long q, n, k;
	long long x, y, z;
	bool v = true;
	f(i,N)ans[i] = 0;
	kaiz();
bv=0;
  wv=0;
	scanf("%lld %lld", &n, &k);

	for (long long i = 1; i <= (n + k); i++) {
		ans[i] = (1 - wv - bv + MOD + MOD) % MOD;
		ans[i] = (ans[i] * r2[1]) % MOD;
		ans[i] = (ans[i]+wv)%MOD;
		x = ni(i - 1, n - 1);
		x = x % MOD;
		x *= r2[i];
		x = x % MOD;
		bv = (bv + x) % MOD;
		x = ni(i - 1, k - 1);
		x = x % MOD;
		x *= r2[i];
		x = x % MOD;
		wv = (wv + x) % MOD;
        
	}
	f(i, n + k)printf("%lld\n", ans[i + 1]);
	return 0;
}


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

int n,m;
int arr[100005];
vector<int> ans;

int main(){
scanf("%d%d",&n,&m);
int numodd = 0;

for (int x = 0; x<m; x++){
    scanf("%d",&arr[x]);
    if (arr[x]%2==1) numodd++;
    if (numodd>2) {
        printf("Impossible");
        return 0;
    }
}
if (m==1){
    printf("%d\n",arr[0]);
    if (arr[0]!=1){
        printf("2\n%d 1",arr[0]-1);
    }
    else printf("1\n1");
    return 0;
}
for (int x = 0; x<n; x++){
    if (arr[x]%2==1 && arr[0]%2!=1) swap(arr[0],arr[x]);
    if (arr[x]%2==1 && arr[m-1]%2!=1) swap(arr[x],arr[m-1]);
}
if (arr[0]!=1) ans.push_back(arr[0]-1);
for (int x = 1; x<m-1; x++){
    ans.push_back(arr[x]);
}
ans.push_back(arr[m-1]+1);
for (int x = 0; x<m; x++){
    printf("%d ",arr[x]);
}
printf("\n%d\n",ans.size());
for (auto x : ans){
    printf("%d ",x);
}
}


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

int main(void){
    ll n; cin >> n;
    vector<ll>h(n);
    for(int i=0;i<n;i++) cin >> h[i];
    vector<ll>cost(n);
    cost[0] = 0; cost[1] = abs(h[1]-h[0]);
    for(int i=2;i<n;i++){
        cost[i]=min(cost[i-1]+abs(h[i]-h[i-1]),cost[i-2]+abs(h[i]-h[i-2]));
    }
    cout << cost[n-1] << endl;
    return 0;
}

Measured memory_bytes: 1792
len_s = int(input())
s = [int(i) for i in input().split()]
len_t = int(input())
t = [int(i) for i in input().split()]
cnt = 0

for f in t:
    i = 0
    while i < len(s) and s[i] != f:
        i += 1
    if i < len(s):
        cnt +=1
print(cnt)

Measured memory_bytes: 8404
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
      int K=sc.nextInt();
      int A=sc.nextInt();
      int B=sc.nextInt();
      boolean H=false;
      while(B>=A){
         if(B%K==0){
            H=true;
         }
         B--;
      }
      if(H==true){
         System.out.println("OK");
      }else{
         System.out.println("NG");
      }
   }
}


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

using namespace std;

int c[100010];

int main() {
	ios::sync_with_stdio(false);
	int n, x;
	cin >> n;
	int mi = n + 2, mx = -1;
	for(int i = 1; i <= n; i++) {
		cin >> x;
		c[x]++;
		mi = min(mi, x);
		mx = max(mx, x);
	}
	if(mx - mi > 1) puts("No");
	else if(mx == mi) {
		if(mi == n - 1 || (mi << 1) <= n) puts("Yes");
		else puts("No");
	} else {
		int c1 = c[mi], c2 = c[mx];
		if(c1 > mi) puts("No");
		else if(n - c1 >= (mx - c1) * 2) puts("Yes");
		else puts("No");
	}
	return 0;
}


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

using namespace std;

inline void quit(){ exit(0); }

typedef long long ll;

ll mpow(ll _x, ll _y, ll _mod){
    if(_y==0) return 1;
    if(_y==1) return _x%_mod;
    if(_y&1) return (mpow(_x, _y-1, _mod)*_x)%_mod;
    ll _tmp = mpow(_x, _y>>1, _mod);
    return (_tmp*_tmp)%_mod;
}

ll n;

int main(){
    cin >> n;
    cout << (n*(n-1)/2);
}


Measured memory_bytes: 256
n,m,c=map(int,input().split())
b=list(map(int,input().split()))
count=0
for i in range(n):
    *a,=map(int,input().split())
    s=c
    for j in range(m):
        s+=(a[j]*b[j])
    if s>0: count+=1
print(count)       

Measured memory_bytes: 3060
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <numeric>
#include <queue>
#include <map> 
#include <set>
#include <string>
#include <functional>
#include <list>
#include <random>
#include <time.h>
#include <iomanip>
#include <assert.h>
#include <numeric>
#define int long long
#define double long double
#define oku7 1000000007
#define MAXN (int)1e+5 * 2+1
#define LL_MAX 9223372036854775807	//ない環境用
#define LL_HALFMAX 9223372036854775807 / 2	//ない環境用

using namespace std;
std::mt19937 mt((int)time(0));

int dx[4] = { 0, 1, 0, -1 }; // x軸方向への変位
int dy[4] = { 1, 0, -1, 0 }; // y軸方向への変位

int x[101], y[101], h[101];

int a[2001], b[2001][2001], sum[100001];


signed main() {
	int N, M;
	cin >> N >> M;
	int ans = 1;
	vector<int> v;
	for (int i = 1; i*i <= M; i++) {
		if (M%i == 0) {
			//約数はiとM/i
			//相方がNを超えてればOK
			v.push_back(i);
			if (i != M / i) v.push_back(M / i);
		}
	}
	//約数のうち、Mを割ってN以上になるものが答え
	for (int i : v) {
		if (i > ans && M / i >= N) ans = i;
	}

	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int S=0,h=0,m=0,s=0;
    cin>>S;
    h=S/3600;
    m=(S-(3600*h))/60;
    s=S-(60*m)-(3600*h);
    cout<<h<<":"<<m<<":"<<s<<endl;
    return 0;
}


Measured memory_bytes: 3088
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
const int INF=0x3f3f3f3f;
const int MOD=20010905;
const int maxn=1e5+10;
int H,W,N;
int main()
{
    scanf("%d %d %d",&H,&W,&N);
    if(H>W)
        printf("%d\n",N/H+(N%H!=0));
    else
        printf("%d\n",N/W+(N%W!=0));
    return 0;
}


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

void solve(long long A, long long B)
{
    cout << ((A <= 9 && B <= 9) ? A * B : -1) << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main()
{
    long long A;
    scanf("%lld", &A);
    long long B;
    scanf("%lld", &B);
    solve(A, B);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
const int MAX_N = 20;
int n;
int A[MAX_N];

bool solve(int i, int M) {
	if (i == n) return false;
	if (M - A[i] == 0) return true;
	if (M - A[i] < 0) return solve(i + 1, M);
	return solve(i + 1, M) || solve(i + 1, M - A[i]);
}

int main () {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> A[i];
	}
	int q;
	cin >> q;
	for (int i = 0; i < q; i++) {
		int M;
		cin >> M;
		cout << (solve(0, M) ? "yes" : "no") << endl;
	}
	return 0;
}

Measured memory_bytes: 1152
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

void printAry(int a[], int n){
    for(int k=0; k<n; k++){
            if(k == n-1){
                printf("%d\n", a[k]);
                continue;
            }
            printf("%d ", a[k]);
    }
}

int main(){
    int n, a[100];
    scanf("%d", &n);
    for(int m=0; m<n; m++){
        scanf("%d", &a[m]);
    }
    printAry(a, n);
    for(int i=1; i<n; i++){
        int j = i-1;
        int p = a[i];
        while(p <= a[j] && j >= 0){
            a[j+1] = a[j];
            j--;
        }
        a[j+1] = p;
        printAry(a, n);
    }
}


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

int main() {
	string A, B, C;
	cin >> A >> B >> C;
	int next = 0, Acount = 0, Bcount = 0, Ccount = 0;
	while (1) {
		if (next == 0) {
			if (Acount >= A.size()) {
				cout << "A" << endl;
				break;
			}
			char x = A[Acount];
			if (x == 'a') {
				next = 0;
				Acount++;
				continue;
			}
			if (x == 'b') {
				next = 1;
				Acount++;
				continue;
			}
			if (x == 'c') {
				next = 2;
				Acount++;
				continue;
			}
		}
		else if (next == 1) {
			if (Bcount >= B.size()) {
				cout << "B" << endl;
				break;
			}
			char x = B[Bcount];
			if (x == 'a') {
				next = 0;
				Bcount++;
				continue;
			}
			if (x == 'b') {
				next = 1;
				Bcount++;
				continue;
			}
			if (x == 'c') {
				next = 2;
				Bcount++;
				continue;
			}
		}
		else {
			if (Ccount >= C.size()) {
				cout << "C" << endl;
				break;
			}
			char x = C[Ccount];
			if (x == 'a') {
				next = 0;
				Ccount++;
				continue;
			}
			if (x == 'b') {
				next = 1;
				Ccount++;
				continue;
			}
			if (x == 'c') {
				next = 2;
				Ccount++;
				continue;
			}
		}
	}
}

Measured memory_bytes: 256
#ifdef LOCAL111
	#define _GLIBCXX_DEBUG
#else
	#define NDEBUG
#endif
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
const int INF = 1e9;
using namespace std;
template<typename T, typename U> ostream& operator<< (ostream& os, const pair<T,U>& p) { cout << '(' << p.first << ' ' << p.second << ')'; return os; }

#define endl '\n'
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#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(i,0,n)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#ifdef LOCAL111
	#define DEBUG(x) cout<<#x<<": "<<(x)<<endl
	template<typename T> void dpite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
#else
	#define DEBUG(x) true
	template<typename T> void dpite(T a, T b){ return; }
#endif
#define F first
#define S second
#define SNP string::npos
#define WRC(hoge) cout << "Case #" << (hoge)+1 << ": "
template<typename T> void pite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
template<typename T> bool chmax(T& a, T b){if(a < b){a = b; return true;} return false;}
template<typename T> bool chmin(T& a, T b){if(a > b){a = b; return true;} return false;}

typedef long long int LL;
typedef unsigned long long ULL;
typedef pair<int,int> P;

void ios_init(){
	//cout.setf(ios::fixed);
	//cout.precision(12);
#ifdef LOCAL111
	return;
#endif
	ios::sync_with_stdio(false); cin.tie(0);	
}

int main()
{
	ios_init();
	int n;
	while(cin >> n) {
		vector<int> a(n);
		REP(i,n) cin >> a[i];
		map<int,int> cnt;
		REP(i,n){
			cnt[a[i]]++;
		}
		int ans = SZ(cnt)-(n-SZ(cnt))%2;
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 5376
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define call(var) cout<<#var<<"="<<var<<endl;
using ll=long long;
using vi = vector<int>;
using vl = vector<ll>;
using Graph = vector<vi>;
using P = pair<int,int>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}

int main(){
    int n,m;
    cin >> n >> m;
    map<int,int> ap;
    rep(i,m){
        int a,b;
        cin >> a >> b;
        ap[a]++;
        ap[b]++;
    }
    bool ok = true;
    for(auto t : ap){
        ok &= !(t.second&1);
    }
    cout << (ok?"YES":"NO") << endl;
}

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

int main(void) {
	char S[1024], T[1024];
	int sl, tl;
	int i, j;
	int kotae = 9999;
	if (scanf("%1023s", S) != 1) return 1;
	if (scanf("%1023s", T) != 1) return 1;
	sl = (int)strlen(S);
	tl = (int)strlen(T);
	for (i = 0; i + tl <= sl; i++) {
		int score = 0;
		for (j = 0; j < tl; j++) {
			if (S[i + j] != T[j]) score++;
		}
		if (score < kotae) kotae = score;
	}
	printf("%d\n", kotae);
	return 0;
}


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

int main() {
  long long N,K,mod=1000000007;
  long long ans = 0;
  cin >> N >> K;
  vector<int> A(N);
  
  for(int i=0;i<N;i++){
    cin >> A[i];
    for(int j=i-1;j>=0;j--){
      if(A[j]>A[i]) ans++;
    }
  }
  ans %= mod;
  ans *= K;
  ans %= mod;
  
  sort(A.begin(),A.end());
  long long base=0 , equal=0;
  for(int i=1;i<N;i++){
    if(A[i] == A[i-1]) equal++;
    else equal = 0;
    base += i - equal;
    base %= mod;
  }
  long long x;
  if((K-1)%2 == 1) x = (1+(K-1))/2 * (K-1);
  else x = (1+(K-1)) * (K-1)/2;
  x %= mod;
  base *= x;
  base %= mod;
  ans += base;
  ans %= mod;
  
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>

#define FASTIO

#ifdef FASTIO
#define scanf abacaba
#define printf abacaba
#endif

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

using namespace std;


/*
ll pw(ll a, ll b) {
	ll ans = 1; while (b) {
		while (!(b & 1)) b >>= 1, a = (a * a) % MOD;
		ans = (ans * a) % MOD, --b;
	} return ans;
}
*/

const int MAXN = 220000;

int n;
ll a[MAXN];
pair<ll, ll> gl[MAXN];
pair<ll, ll> gr[MAXN];


int main() {
#ifdef FASTIO
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#endif
	cin >> n;
	for (int i = 0; i < n; ++i)
		cin >> a[i];

	ll sl = 0;
	ll sr = 0;
	int now = 0;
	for (int i = 0; i < n; ++i) {
		sr += a[i];
		while (now <= i && abs(sl - sr) >= abs(sl + a[now] - (sr - a[now])))
			sl += a[now], sr -= a[now], ++now;
		gl[i] = make_pair(sl, sr);
	}
	sl = 0;
	sr = 0;
	now = n - 1;
	for (int i = n - 1; i >= 0; --i) {
		sl += a[i];
		while (now >= i && abs(sl - sr) >= abs(sl - a[now] - (sr + a[now])))
			sl -= a[now], sr += a[now], --now;
		gr[i] = make_pair(sl, sr);
	}
	ll ans = ll(1e18);
	for (int i = 1; i < n - 2; ++i) {
		vector<ll> vv;
		vv.push_back(gl[i].first);
		vv.push_back(gl[i].second);
		vv.push_back(gr[i + 1].first);
		vv.push_back(gr[i + 1].second);
		sort(vv.begin(), vv.end());
		ans = min(ans, vv[3] - vv[0]);
	}
	cout << ans << "\n";
	return 0;
}




Measured memory_bytes: 8704
#include<stdio.h>
int main(void){
    int n,i=1,x=0;
    scanf("%d",&n);
    for(i=1;i<=n;i++){
        if(i%3==0){
            printf(" %d",i);
        }else{
            if(i%10==3){
            printf(" %d",i);
            }else{
                x=i;
                while(x!=0){
                    if(x%10!=3){
                    x/=10;
                    }else{
                        printf(" %d",i);
                        break;
                    }
                }
            }
        }
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 2144
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class MainClass
{
	public const long Giri = 1000000007;

	public static void Main(string[] args)
	{
		var n = Console.ReadLine().ToInt();
		var a = Input().ToInt();
		
		var ary = new int[n+4];
		var prevI = ary.Length / 2;
		var nextI = prevI+1;
		for(int i = 0; i < n; i++)
		{
			if(i%2==0)
			{
				ary[nextI] = a[i];
				nextI++;
			}
			else
			{
				ary[prevI] = a[i];
				prevI--;
			}
		}
		for(int i = 0; i < n; i++)
		{
			var t = prevI+1 + i;
			if(n % 2==1)
				t = nextI - 1 - i;
			Console.Write(ary[t] + " ");
		}
		Console.WriteLine();
	}
	

	static long GCD(long a, long b)
	{
		var v = new[] { a, b };
		while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
		return v[0];
	}
	public static string[] Input() { return Console.ReadLine().Split(' '); }
	public static int Clamp(int val, int max, int min = 0) { return Math.Min(max, Math.Max(min, val)); }
}

public static class Smarter
{
	public static int ToInt(this string str) { return int.Parse(str); }
	public static long ToLong(this string str) { return long.Parse(str); }
	public static int[] ToInt(this string[] str)
	{
		var r = new int[str.Length];
		for(int i = 0; i < str.Length; i++) r[i] = str[i].ToInt();
		return r;
	 }
}



Measured memory_bytes: 38312
#include<bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define REPvec(itr, mp) for(auto itr = mp.begin();itr != mp.end(); itr ++)
#define all(x) x.begin(), x.end()
#define MOD 1000000007//1e9+7
using namespace std;
typedef long long ll;
typedef vector<int >    vecint;
typedef vector<double >    vecd;
typedef vector<vector<int> >  vec2int;
typedef vector<vector<double> >  vec2d;
typedef vector<ll >     vecll;
typedef vector<string > vecstr;
typedef vector<bool > vecbool;
typedef vector<vector< bool > > vec2bool;
typedef vector<bool > vecbool;
////////////////////////////////////////////////
int main()
{
  ll a, b, c, k; cin >> a >>b >> c>> k;
  // a_{n + 1}  - b_{n + 1} = b_n + c_n - (c_n + a_n) = (b_n - a_n)
  if(k % 2 == 0){
    cout << a - b << endl;
  }else{
    cout << b - a << endl;
  }
} 

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;

int main()
{
    int sum=0,res=0;
    char s[110];
    cin >>s;
    int n=strlen(s);
    for(int i=0;i<n;i++)
    {
        if(s[i]=='A'||s[i]=='T'||s[i]=='C'||s[i]=='G')
        {
            sum++;
            res=max(sum,res);
        }
        else
            sum=0;
    }
    printf("%d",res);
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")
#pragma G++ optimize("O3")

#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/priority_queue.hpp>

//using namespace __gnu_pbds;
using namespace std;

#define ll long long
#define ld long double
#define ull unsigned long long
#define mst(a, b) memset((a), (b), sizeof(a))
#define mp(a, b) make_pair(a, b)
#define pi acos(-1)
#define endl '\n'
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pdd pair<double, double>
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define lson root << 1, l, mid
#define rson root << 1 | 1, mid + 1, r
#define ls t[root << 1]
#define rs t[root << 1 | 1]
#define tr t[root]
#define lowbit(x) x &(-x)
#define all(x) (x).begin(), (x).end()
#define sf(x) scanf("%d", &x)
#define pf(x) printf("%d", x)
#define debug(x) cout << x << endl
#define mod(x) (x % mod + mod) % mod

template <typename T>
void read(T &x)
{
    x = 0;
    char ch = getchar();
    ll f = 1;
    while (!isdigit(ch))
    {
        if (ch == '-')
            f *= -1;
        ch = getchar();
    }
    while (isdigit(ch))
    {
        x = x * 10 + ch - 48;
        ch = getchar();
    }
    x *= f;
}

const int INF = 0x3f3f3f3f;
const ll inf = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-8;
const int maxn = 2e5 + 7;
const int maxm = 1e3 + 7;
const int mod = 1e9 + 7;

#define IO ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
//template<typename T> using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
ll a[maxn], sum[maxn];
int main()
{
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    sum[n - 1] = a[n - 1];
    for (int i = n - 2; i >= 0; --i)
        sum[i] = (sum[i + 1] + a[i]) % mod;
    ll ans = 0;
    for (int i = 0; i < n - 1; ++i)
        ans += a[i] * sum[i + 1] % mod;
    cout << ans % mod << endl;
    return 0;
}


Measured memory_bytes: 6648
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;

string s, t;
int cnt1[26];
int cnt2[26];

signed main() {
	int i;
	
	cin >> s >> t;
	rep(i, s.length()) cnt1[s[i] - 'a']++;
	rep(i, t.length()) cnt2[t[i] - 'a']++;
	sort(cnt1, cnt1 + 26);
	sort(cnt2, cnt2 + 26);
	rep(i, 26) if (cnt1[i] != cnt2[i]) { cout << "No" << endl; return 0; }
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 1020
#include <iostream>
using namespace std;
char chess(int h,int w){
    if((h+w)%2==0){
        return'#';
    }
    return'.';
}
int main(void){
    int H,W;
    while(true){
    cin>>H>>W;
    
    if(H==0&&W==0)  {break;}
    for(int j=0;j<H;j++){
        for(int i=0;i<W;i++){
            cout<<chess(i,j);
        }
        cout<<endl;
    }
    cout<<endl;
}}


Measured memory_bytes: 3068
import java.util.*;

public class Main{
	private static final Scanner scan = new Scanner(System.in);

	public static void main(String[] args){
		
		int[] nums = new int[5];
		for(int i = 0; i < 5; i++){
			nums[i] = scan.nextInt();
		}

		for(int i = 0; i < 5 - 1; i++){
			for(int j = 5 - 1; j > i; j--){
				if(nums[i] < nums[j]){
					int big = nums[j];
					nums[j] = nums[i];
					nums[i] = big;
				}
			}
		}
		System.out.printf("%d %d %d %d %d\n", nums[0], nums[1], nums[2], nums[3], nums[4]);
	}
}

Measured memory_bytes: 26228
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <stdio.h>
#include <cmath>
#include <math.h>
#include <sstream>
#include <iomanip>
#include <time.h>
#include <fstream>

using namespace std;

int main(){
	int a,b;
	cin>>a>>b;
	string s;
	cin>>s;
	for(int i = 0; i < a; i++){
		int x = s[i]-'0';
		if (x<0){
			cout<<"No"<<endl;
			return 0;
		}
		if (x>9){
			cout<<"No"<<endl;
			return 0;
		}
	}
	if (s[a]!='-'){
		cout<<"No"<<endl;
		return 0;
	}

	for(int i = 0; i < b; i++){
		int x = s[a + 1 + i]-'0';
		if (x<0){
			cout<<"No"<<endl;
			return 0;
		}
		if (x>9){
			cout<<"No"<<endl;
			return 0;
		}
	}
	cout<<"Yes"<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <string>
#include <set>
#include <bitset>
#include <unordered_map>

using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
template <class T>
using Vvec = vector<vector<T> >;

int main()
{
    int N;
    string S;
    cin >> N >> S;

    if(N % 2 != 0){cout << "No\n"; return 0;}
    for(int i=0; i<N/2; i++){
        if(S[i] != S[i+N/2]){cout << "No\n"; return 0;}
    }
    cout << "Yes\n";
}

Measured memory_bytes: 256
import java.util.Locale;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in).useLocale(Locale.ENGLISH);
        int count = scanner.nextInt();
        double[] arr = new double[count + 1];
        for (int i = 1; i <= count; ++i) {
            arr[i] = scanner.nextDouble();
        }

        double[][] dp = new double[count + 1][count + 1];
        double res = 0.0;
        dp[0][0] = 1.0;
        for (int i = 0; i <= count; ++i) {
            for (int j = 0; i + j <= count; ++j) {
                if (i > 0) {
                    dp[i][j] += dp[i - 1][j] * arr[i + j];
                }
                if (j > 0) {
                    dp[i][j] += dp[i][j - 1] * (1.0 - arr[i + j]);
                }
                if (i + j == count && i > j) {
                    res += dp[i][j];
                }
            }
        }

        System.out.println(res);
    }
}

Measured memory_bytes: 122600
use std::io::{stdin, BufRead};
fn main() {
    let stdin = stdin();
    let mut stdinlock = stdin.lock();
    let mut n = String::with_capacity(5);
    let _ = stdinlock.read_line(&mut n);
    let mut scores: Vec<u32> = stdinlock
        .lines()
        .map(|score| score.expect("unwrap").trim().parse().expect("parse"))
        .collect();
    scores.sort();
    let scores: Vec<u32> = scores;
    println!("{}", solve(&scores));
}

fn solve(scores: &[u32]) -> u32 {
    let mut minimum_nonzero = None;
    let mut total = 0;
    for score in scores {
        if minimum_nonzero.is_none() && score % 10 != 0 {
            minimum_nonzero = Some(score);
        }
        total += score;
    }
    if total % 10 != 0 {
        total
    } else {
        if let Some(n) = minimum_nonzero {
            total - n
        } else {
            0
        }
    }
}


Measured memory_bytes: 2164
#include <iostream>
using namespace std;
int main() {
    int a,b,ans;
    char op;
    while(cin >> a >> op >> b) {
        if (op == '+') ans = a+b;
        else if (op == '-') ans = a-b;
        else if (op == '*') ans = a*b;
        else if (op == '/') ans = a/b;
        else break;
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3092
n = int(input())
s = [list(input()) for i in range(n)]
ans = 0
for a in range(n):
    check = True
    for x in range(n):
        for y in range(x):
            if s[(x+a)%n][y] != s[(y+a)%n][x]:
                check = False
                break
        if check == False:
            break
    if check:
        ans += n-a
    if a == 0:
        continue
    check = True
    for x in range(n):
        for y in range(x):
            if s[x][(y+a)%n] != s[y][(x+a)%n]:
                check = False
                break
        if check == False:
            break
    if check:
        ans += n-a
print(ans)

Measured memory_bytes: 77580
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  Int x,y;
  cin>>x>>y;
  cout<<x+(y/2)<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
	
	char str[10];
	
	scanf("%s",str);
	
	int count=0;
	
	for(int i=0;i<4;i++){
		
		if(str[i]=='+'){
			
			count+=1;
			
		}
		
		if(str[i]=='-'){
			count-=1;
		}
		
	}
	
	printf("%d\n",count);
	
	return 0;
}

Measured memory_bytes: 128
/**
*	  Name: Ajay Subhash Jadhav
*	  Institute: International Institute of Technology Hyderabad 
*/

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <deque>
#include <vector>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <ctime>
#include <string.h>
#define LL long long
#define inf 0x7fffffff
#define mod 1000000007
#define pb push_back
#define ppi pair<int,int>
#define vi vector<int>
#define vii vector<ppi>
#define vll vector<LL>
#define mp make_pair
using namespace std;

void fastio()
{
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}
void inputread()
{
  #ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
  #endif
}

struct no
{
	int total;
	char left;
	char right;
};

string s;
no tree[4*100001];
int n;

void build(int node,int start,int end)
{
	if(start==end)
	{
		tree[node].total=0;
		tree[node].left=s[start];
		tree[node].right=s[start];
		return;
	}

	build(2*node,start,(start+end)/2);
	build(2*node+1,(start+end)/2+1,end);

	tree[node].total=tree[2*node].total+tree[2*node+1].total+(tree[2*node].right=='A' && tree[2*node+1].left=='C');
	tree[node].left=tree[2*node].left;
	tree[node].right=tree[2*node+1].right;
}

no query(int node,int start,int end,int l,int r)
{
	if(l>r or r<start or end<l)
		return {};
	if(l<=start && end<=r)
	{
		return tree[node];
	}

	no left=query(2*node,start,(start+end)/2,l,r);
	no right=query(2*node+1,(start+end)/2+1,end,l,r);
	no res;
	res.total=left.total+right.total+(left.right=='A'&& right.left=='C');
	res.left=left.left;
	res.right=right.right;
	return res;
}

int main()
{
      
  fastio();
  int i,q;
  cin>>n>>q;
  cin>>s;
  build(1,0,n-1);
  while(q--)
  {
  	int l,r;
  	cin>>l>>r;
  	l--;r--;
 		cout<<query(1,0,n-1,l,r).total<<"\n";
  }
  return 0;
}

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

int main() {
 string S;
 string T;
 int ans=0;
 cin>>S>>T;
 rep(i,S.size()){
     if(S[i]!=T[i]){
         ans++;
     }
 }
 cout<<ans<<endl;
}


Measured memory_bytes: 3920
import sys
from collections import deque as dq
input = sys.stdin.readline
N = int(input())
a = []
for _ in range(N):
  a.append(int(input()))
sa = dq(sorted(a))
res = 0
x = [0] * N
x[0] = sa[N // 2]
for i in range(1, N):
  if i % 2 == 0:
    x[i] = sa.popleft()
  else:
    x[i] = sa.pop()

for i in range(N - 1): res += abs(x[i + 1] - x[i])
res2 = 0
sa = dq(sorted(a))
x = [0] * N
x[0] = sa[-N // 2]
for i in range(1, N):
  if i % 2:
    x[i] = sa.popleft()
  else:
    x[i] = sa.pop()
for i in range(N - 1): res2 += abs(x[i + 1] - x[i])
print(max(res, res2))

Measured memory_bytes: 53160
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int m = sc.nextInt();

        int[] x = new int[m];
        for(int i = 0; i < m; i++){
            x[i] = sc.nextInt();
        }
        Arrays.sort(x);
        int l = x[m - 1] - x[0];

        Integer[] y = new Integer[m - 1];
        for(int i = 0; i < m - 1; i++){
            y[i] = x[i + 1] - x[i];
        }
        Arrays.sort(y, Comparator.reverseOrder());

        for(int i = 0; i < Math.min(n - 1, m - 1); i++){
            l -= y[i];
        }

        System.out.println(l);

    }
}


Measured memory_bytes: 47620
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int d[200][200];
int const inf=1<<28;
int main(){
    int n;
    while(cin>>n){
        for(int i=0;i<=n;i++)for(int j=0;j<=n;j++)d[i][j]=inf;
        for(int i=0;i<=n;i++)d[i][i]=0;
        vector<pair<bool,string>> v;
        for(int i=0;i<n;i++){
            string s;cin>>s;
            bool b;
            if(s=="goto"){
                cin>>s;
                s.back()=':';
                b=true;
            }else{
                b=false;
            }
            v.push_back(make_pair(b,s));
        }
        for(int i=0;i<n;i++){
            if(v[i].first){
                d[i][i+1]=1;
                for(int j=0;j<n;j++){
                    if(!v[j].first && v[j].second==v[i].second){
                        d[i][j]=0;
                        break;
                    }
                }
            }else{
                d[i][i+1]=0;
            }
        }
        for(int i=0;i<=n;i++){
            for(int j=0;j<=n;j++){
                for(int k=0;k<=n;k++){
                    d[j][k]=min(d[j][k],d[j][i]+d[i][k]);
                }
            }
        }
        cout<<d[0][n]<<endl;
    }
}

Measured memory_bytes: 1308
import java.util.*;
public class Main{
    public static void main(String[] args){
	new Main().run();
    }

    Scanner kbd = new Scanner(System.in);
    int i, j, l;

    void run(){
	while(kbd.hasNext()){
	    int cnt = 0;
	    int n = kbd.nextInt(); // テ」ツつヲテ」ツつオテ」ツつョテ」ツ?ョテヲツ閉ー
	    boolean[] rab = new boolean[n+1]; // テヲツーツ療・ツ按?」ツつ津ヲツつェテ」ツ?湘」ツ?療」ツ?ヲテ」ツ??」ツ?淌」ツつ映alse, 0テヲツ慊ェテ、ツスツソテァツ板ィ
	    Arrays.fill(rab, true);
	    int k = kbd.nextInt(); // テ」ツδ愿」ツδシテ」ツδ暗」ツ?ョテヲツ閉ー
	    int [][] boat = new int[k][n+1]; // [テ」ツδ愿」ツδシテ」ツδ暗ァツ閉ェテ・ツ渉キ][テ」ツつヲテ」ツつオテ」ツつョテァツ閉ェテ・ツ渉キ]

	    for(i=0; i<k; i++){
		j = kbd.nextInt();
		while(j>0){
		    boat[i][j] = kbd.nextInt();
		    j--;
		}
	    }

	    int r = kbd.nextInt(); // テ、ツサツイテヲツつェテ」ツ??」ツδ堙」ツつ「
	    boolean[][] bad = new boolean[n+1][n+1]; // false テ」ツ?ェテ」ツつ嘉、ツサツイテヲツつェテ」ツ??
	    for(i=0; i<n+1; i++){
		Arrays.fill(bad[i], true);
	    }
	
	    for(i=0; i<r; i++){
		int a = kbd.nextInt();
		int b = kbd.nextInt();
		bad[a][b] = false;
		bad[b][a] = false;
		//System.out.println("*"+a+" "+b);
	    }



	    // テ・ツ崢榲ァツュツ氾」ツ?禿」ツ?禿」ツ?凝」ツつ?
	    for(i=0; i<k; i++){  // テ」ツδ愿」ツδシテ」ツδ暗ァツ閉ェテ・ツ渉キ
		for(j=0; j<n; j++){ // テ」ツつヲテ」ツつオテ」ツつョ1
		    for(l=j+1; l<=n; l++){ // テ」ツつヲテ」ツつオテ」ツつョ2
			int rab1 = boat[i][j];
			int rab2 = boat[i][l];
			if(!bad[rab1][rab2]){
			    if(rab[rab1]){
				rab[rab1] = false;
				cnt++;
			    }
			    if(rab[rab2]){
				rab[rab2] = false;
				cnt++;
			    }
			    //System.out.println(rab1+" "+rab2);
			}
		    }
		}
	    }

	    /*
	    for(i=0; i<rab.length; i++){
		if(!rab[i]){
		    cnt++;
		}
	    }
	    */

	    System.out.println(cnt);
	}
    }
}

Measured memory_bytes: 24516
#include <iostream>
#include <vector>
using namespace std;
#define rep(i,a) for(int i = 0 ; i < a ; i++)
int main(void){
	int n;
	while(cin>>n,n){
		vector<int>in(n);
		int cnt = 0;
		rep(i,n)cin>>in[i];
		while(1){
			bool judge = true;
			rep(i,in.size())if(in[i]!=i+1)judge=false;
			if(judge)break;
			cnt++;
			int tmp = in.size();
			for(vector<int>::iterator it=in.begin();it!=in.end();it++){
				(*it)--;
				if(!*it){
					in.erase(it);
					it--;
				}
			}
			in.push_back(tmp);
			if(cnt>10000)break;
		}
		if(cnt<=10000)cout<<cnt<<endl;
		else cout<<-1<<endl;
	}
}

Measured memory_bytes: 1236
import sys
sys.setrecursionlimit(10**7)

n, q = map(int, sys.stdin.readline().split())

graph = [[] for _ in range(n+1)] 
for i in range(1, n):
  a, b = map(int, sys.stdin.readline().split())
  graph[a].append(b)
  graph[b].append(a)

point = [0]*(n+1)
for i in range(q):
  p, x = map(int, sys.stdin.readline().split())
  point[p] += x

seen = [False]*(n+1)
counter = [0]*(n+1)
sum_point = 0

def dfs(v):
  
  global graph
  global seen
  global sum_point
  global counter
  
  seen[v] = True
  sum_point += point[v]
  
  for next_v in graph[v]:
    
    if seen[next_v]: 
      continue
    dfs(next_v)
  
  counter[v] = sum_point
  sum_point -= point[v]

dfs(1)
print(*counter[1::])

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

using namespace std;
#define ll long long
#define ull unsigned long long
#define pb push_back
#define lin "\n"
#define fast_io ios_base::sync_with_stdio(0), cin.tie(NULL), cout.tie(0)
#define mod 1000000007
#define PI 2 * acos(0.0)

void solve() {
    ll n;
    cin >> n;
    ll ans = 0;
    ll x = 1;
    for (int i = 1; i <= n; ++i) {
        x = 10 * x % mod;
    }
    ans += (x % mod);
    x = 1;
    for (int i = 1; i <= n; ++i) {
        x = 9 * x % mod;
    }
    ans = ans - (x % mod);
    if (ans < 0) {
        ans += mod;
    }
    ans = ans - (x % mod);
    if (ans < 0) {
        ans += mod;
    }
    x = 1;
    for (int i = 1; i <= n; ++i) {
        x = 8 * x % mod;
    }
    ans += (x % mod);
    cout << ans % mod << lin;
}

int main() {
    fast_io;
    int t = 1;
//    cin >> t;
//    scanf("%d", &t);
    int c = 1;
    while (t--) {
//        printf("Case %lld:\n", c);
//        cout << "Case " << c << ":\n";
        solve();
        c++;
    }
}

Measured memory_bytes: 3656