akhauriyash/Code-Regression huggingface dataset:
#include<iostream>

using namespace std;

int main()
{
	int next[3]={-1,0,1};
	int x,y,i,j;
	
	for(;;)
	{
		cin >> x >> y ;
		if(x==0 && y==0)
			break;
		int map[20][20]={0};
		int ansmap[20][20]={0};
		int ans=0;
		for(i=0;i<y;i++)
		{
			for(j=0;j<x;j++)
			{
				cin >> map[i][j] ;
			}
		}
		for(i=0;i<x;i++)
		{
			ansmap[0][i]=1;
		}
		for(i=0;i<y;i++)
		{
			for(j=0;j<x;j++)
			{
				if(i==0)
				{
					if(map[i][j]==1)
					{
						ansmap[i][j]=0;
					}
					else if(map[i][j]==2)
					{
						ansmap[i+2][j]+=ansmap[i][j];
					}
					else if(map[i][j]==0 && i<y-1)
					{
						for(int k=0;k<3;k++)
						{
							if(j+next[k]>=0 && j+next[k]<x)
							{
								if(map[i+1][j+next[k]]==0)
								{
									ansmap[i+1][j+next[k]]+=ansmap[i][j];
								}
								else if(map[i+1][j+next[k]]==2 && next[k]==0)
								{
									ansmap[i+1][j]+=ansmap[i][j];
								}
							}
						}
					}
				}
				else
				{
					if(map[i][j]==1)
					{
						ansmap[i][j]=0;
					}
					else if(map[i][j]==2)
					{
						ansmap[i+2][j]+=ansmap[i][j];
					}
					else if(map[i][j]==0 && i<y-1)
					{
						for(int k=0;k<3;k++)
						{
							if(j+next[k]>=0 && j+next[k]<x)
							{
								if(map[i+1][j+next[k]]==0)
								{
									ansmap[i+1][j+next[k]]+=ansmap[i][j];
								}
								else if(map[i+1][j+next[k]]==2 && next[k]==0)
								{
									ansmap[i+1][j+next[k]]+=ansmap[i][j];
								}
							}
						}
					}
				}
			}
		}
		for(i=-1;i<1;i++)
		{
			for(j=0;j<x;j++)
			{
				ans+=ansmap[y+i][j];
			}
		}
		cout << ans << endl;
	}
}

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

using namespace std;

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

#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<(b);i++)
#define repr(i,b,a) for(int i=int(b);i>=(a);i--)
#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool valid(int lx,int ux,int ly,int uy,int x,int y){
	return lx<=x&&x<ux&&ly<=y&&y<uy; 
}
ll power(ll x,ll p){
	if(p==0)return 1;
	ll res=power(x*x%mod,p/2);
	if(p%2==1)res=res*x%mod;
	return res;
}

bool isin(string s, char c){
	rep(i,s.size()){
		if(s[i]==c)return true;
	}
	return false;
}

int main()
{
	int n;
	vector<int> x(3);
	cin>>n;
	rep(i,3)cin>>x[i];
	vector<string> s(n);
	rep(i,n)cin>>s[i];

	vector<char> ans;
	rep(i,n){

		if(x[s[i][0]-'A']==0 && x[s[i][1]-'A']==0){
			cout<<"No"<<endl;
			return 0;
		}

		if(x[s[i][0]-'A'] < x[s[i][1]-'A']){
			x[s[i][0]-'A']++;
			x[s[i][1]-'A']--;
			ans.push_back(s[i][0]);
		}else if(x[s[i][0]-'A'] > x[s[i][1]-'A']){
			x[s[i][0]-'A']--;
			x[s[i][1]-'A']++;
			ans.push_back(s[i][1]);
		}else{
			if(i==n-1)ans.push_back(s[i][0]);
			else if(s[i+1]==s[i]){
				x[s[i][0]-'A']--;
				x[s[i][1]-'A']++;
				ans.push_back(s[i][1]);
			}else if(isin(s[i+1],s[i][0])){
				x[s[i][0]-'A']++;
				x[s[i][1]-'A']--;
				ans.push_back(s[i][0]);
			}else{
				x[s[i][0]-'A']--;
				x[s[i][1]-'A']++;
				ans.push_back(s[i][1]);
			}
		}
	}

	cout<<"Yes"<<endl;
	rep(i,n)cout<<ans[i]<<endl;
	return 0;
}


Measured memory_bytes: 6716
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {

	/** グリッドのサイズ */
	private static final int N = 3;

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int[][] c = new int[N][N];
			IntStream.range(0, N).forEach(i -> IntStream.range(0, N).forEach(j -> c[i][j] = scanner.nextInt()));
			boolean result = true;
			for (int i = 0; i < N - 1; i++) {
				int diff1 = c[i + 1][0] - c[i][0];
				int diff2 = c[0][i + 1] - c[0][i];
				for (int j = 1; j < N; j++) {
					if ((c[i + 1][j] - c[i][j]) != diff1) {
						result = false;
						break;
					}
					if ((c[j][i + 1] - c[j][i]) != diff2) {
						result = false;
						break;
					}
				}
			}
			System.out.println(result ? "Yes" : "No");
		}
	}
}


Measured memory_bytes: 36088
#include <bits/stdc++.h>
#define range(i, l, r) for(long long int (i) = (l); (i) < (r); (i)++)
#define reversed_range(i, l, r) for (long long int (i) = (r) - 1; (i) >= l; (i)--)
using namespace std;
template <typename T>
using vec = vector<T>;
using lint = long long;
using ulint = unsigned long long;
using pint = pair<int, int>;
using plint = pair<lint, lint>;

template <typename S, typename T>
ostream& operator <<(ostream& os, pair<S, T> p) {
    os << "(";
    os << p.first << ", " << p.second;
    return os << ")";
}

template <typename T>
ostream& operator <<(ostream& os, vec<T> v) {
    os << "[";
    if (v.size() == 0) return os << "]";
    for (int i = 0; i < v.size() - 1; i++) {
        os << v.at(i) << ", ";
    }
    return os << v.at(v.size() - 1) << "]";
}

template <typename T>
ostream& operator <<(ostream& os, set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    os << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        os << ", " << *it;
    }
    return os << "}";
}

template <typename T>
ostream& operator <<(ostream& os, unordered_set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    os << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        os << ", " << *it;
    }
    return os << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    os << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        os << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, unordered_map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    os << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        os << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

lint pow(lint num, lint e, lint MOD) {
    lint res = 1;
    lint cur_num = num;
    while (e) {
        if (e & 1) {
            res *= cur_num;
            res %= MOD;
        }
        cur_num *= cur_num;
        cur_num %= MOD;
        e >>= 1;
    }
    return res;
}

int main() {
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    lint N; cin >> N;
    vec<lint> A_list(N);
    range(i, 0, N) cin >> A_list.at(i);
    range(i, 0, N) {
        lint A = A_list.at(i);
        if (A % 2 == 0 and (A % 3 and A % 5)) {
            cout << "DENIED" << "\n";
            return 0;
        }
    }
    cout << "APPROVED" << "\n";
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    static Scanner scanner = new Scanner(System.in);

    public static void main(String[]$) {
        int n = scanner.nextInt();
        int[] a = new int[n];
        Arrays.setAll(a, i -> scanner.nextInt());
        Arrays.sort(a);
        System.out.println(a[n - 1] - a[0]);
    }
}

Measured memory_bytes: 26196
#include <stdio.h>
#include <stdlib.h>

long gcd(long m, long n){
	long temp;
	while (m % n != 0){
		temp = n;
		n = m % n;
		m = temp;
	}
	return n;
}

long lcm(long c, long d){
    return c * d / gcd(c, d);
}
int main(void){
    long a, b, c, d;
    scanf("%ld%ld%ld%ld", &a, &b, &c, &d);
    //(B-A-1) - (cで割れる数) - (dで割れる数) + (cでもdでも割れる = cとdの最小公倍数で割れる数)
    long e = lcm(c, d);
    long xc = (b / c) - ((a-1) / c);
    long xd = (b / d) - ((a-1) / d);
    long xe = (b / e) - ((a-1) / e);
    long ans = b - a + 1 - xc - xd + xe;
    printf("%ld\n", ans);
    return 0; 
}


Measured memory_bytes: 128
#include<stdio.h>
#include<iostream>
#include<stack>
#include<map>
#include<queue>
#include<vector>
#include<utility>
#include<algorithm>
#include<string>
#include<math.h>
#include<deque>
#include<string.h>
#include<bitset>
#define n 200000
#define loop(i, a, b) for(int i=a; i<=b; i++)
#define mem(arr) memset(arr, 0, sizeof(arr))
using namespace std;
typedef long long lli;
typedef double llf;
typedef pair<int, int> P;
struct edge{
	int from, to, weight;
};
vector<int> V[n + 50];
void solve();
int main()
{
	int times = 1;
//	cin >> times;
	loop(i, 1, times)
	{
		solve();
		cout << '\n';
	}
	return 0;
}

int a, b, c, d, e, f;
int arr[n + 50], arr1[n + 50], arr2[n + 50];
string str, str1, str2;

///////////////////////////////


void solve()
{
	cin >> a;
	loop(i, 0, a - 1 )
		cin >> arr[i];
	int counting1[n + 50];
	int counting2[n + 50];
	mem(counting1); mem(counting2);
	for(int i=0; i<a; i+=2)
		counting1[arr[i]] ++;
	for(int i=1; i<a; i+=2)
		counting2[arr[i]] ++;
	int one = 0, two = 0;
	for(int i=1; i<n; i++)
	{
		if(counting1[i] >= counting1[one]) one = i;
		if(counting2[i] >= counting2[two]) two = i;
	}
	int sum = a - (counting1[one] + counting2[two]);
	if(one == two)
	{
		int one2 = 0, two2 = 0;
		for(int i=0; i<n; i++)
		{
			if(counting1[i] > counting1[one2] && i != two) one2 = i;
			if(counting2[i] > counting2[two2] && i != one) two2 = i;
		}
//		cout << one2 << ' ' << two2 << '\n';
		sum = a - max(counting1[one2] + counting2[two], counting1[one] + counting2[two2]);
	}
	cout << sum;
}

Measured memory_bytes: 7168
#include <iostream>
#include <set>
using namespace std;
set<int> g1 = {1, 3, 5, 7, 8, 10, 12};
set<int> g2 = {4, 6, 9, 11};
set<int> g3 = {2};

int main() {
	int a, b;
	cin >> a >> b;
	if ((g1.find(a)!=g1.end() && g1.find(b) != g1.end())
		|| (g2.find(a)!=g2.end() && g2.find(b) != g2.end())
		|| (g3.find(a)!=g3.end() && g3.find(b) != g3.end())) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
	return 0;
}




Measured memory_bytes: 888
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    S = I()

    # (0, 0), (10**9, 1), (x, y) とおくと
    # S = 10**9 * y - x
    y = (S - 1) // 10 ** 9 + 1
    x = 10 ** 9 * y - S

    print(0, 0, 10 ** 9, 1, x, y)

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 10112
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1000000007;

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

typedef pair<int, int> P;

int main(){
    int n, m;
    cin >> n >> m;
    vector<P> bri;
    for (int i = 0; i < m; i++){
        int a, b;
        cin >> a >> b;
        bri.push_back(P(b, a));
    }

    sort(bri.begin(), bri.end());
    
    int last = -1, cnt = 0;
    for (int i = 0; i < (int)bri.size(); i++){
        if (last <= bri[i].second){
            cnt++;
            last = bri[i].first;
        }
    }

    cout << cnt << endl;

    return 0;
}

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

typedef long long ll;
typedef int64_t i6;

#define rep(i, n) for (ll i = 0; i < n; ++i)
#define Sort(x) sort(x.begin(), x.end())
#define Sort_rev(x) sort(x.begin(), x.end(), greater<int>())
#define ALL(v) (v).begin(), (v).end()

//π M_PI
//deg = rad*180/M_PI

int main() {
    ll n;
    cin >> n;
    ll p[n];
    rep(i, n) {
        cin >> p[i];
    }

    ll Min = p[0];
    ll ans = 1;
    rep(i, n) {
        if ( i > 0 ) {
            if ( Min > p[i] ) {
                ans++;
            }
            Min = min(Min, p[i]);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e9
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;

signed main(){
    string s;
    cin>>s;
    int n=s.size();
    int cnt=0;
    if(n==1){
        cout<<1<<endl;
        return 0;
    }
    string t="";
    for (int i = 0; i < n; i++)
    {
        if(i+2==n){
            if(s[i]==s[i+1]) {
                cnt++;
                break;
            }
        }
        
        if(s.substr(i,1)!=t){
            t=s.substr(i,1);
        }
        else{
            t=s.substr(i,2);
            i++;
        }
        cnt++;
    }
    cout<<cnt<<endl;
    

    return 0;
}

Measured memory_bytes: 640
#include<stdio.h>
int main()
{
  char str[3];
  for(int i=0;i<3;i++)
    scanf("%s",&str[i]);
  
  if(str[0]==str[1]&&str[1]==str[2])
    puts("No");
  else
    puts("Yes");
  
  return 0;
}

Measured memory_bytes: 128
// C++ implementation of the above approach 
#include <bits/stdc++.h>
using namespace std; 

// Function for finding the power 
unsigned long power(unsigned long x, unsigned long y) 
{ 
	unsigned long res = 1; // Initialize result 

	while (y > 0) { 

		// If y is odd, multiply x with result 
		if (y & 1) 
			res = (res * x); 

		// y must be even now 
		y = y >> 1; // y = y/2 
		x = (x * x); 
	} 
	return res; 
} 

// Function to calculate the number of ways 
int ways(int n, int m) 
{ 
	// Answer must be modulo of 10^9 + 7 
	return power(m - 1, n - 1) * m; 
} 

// Driver code 
int main() 
{ 
	int n, m;
  	cin>>n>>m;
	cout << ways(n, m); 

	return 0; 
} 


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

int head(int x) {
    while (x >= 10) x /= 10;
    return x;
}

int main() {
    int n;
    cin >> n;
    int v[10][10] = {};
    for (int i = 1; i <= n; i++) {
        int h, t;
        t = i % 10;
        h = head(i);
        if (t != 0) v[h][t]++;
    }
    ll ans = 0;
    for (int i = 1; i < 10; i++) {
        for (int j = 1; j < 10; j++) {
            ans += v[i][j] * v[j][i];
        }
    }
    cout << ans << endl;
    return 0;
}

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

typedef long long ll;
#define pii pair<int , int>
#define _FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MAXX 1005

int x;
string s;

int gcd(int a , int b){
    while(a > 0 && b > 0){
        if(a > b)   a %= b;
        else    b %= a;
    }
    return a + b;
}

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

int main()
{
    _FastIO;

    cin >> x;
    cout << lcm(x , 360) / x << endl;

    return 0;
}


Measured memory_bytes: 3688
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
  ll N;
  cin>>N;
  //１が何個あるか、２が何個あるか、を知ればいいかな
  //５個あったとして、5*4/2=10通り
  //１をとったら４個なので4*3/2=6　10-6=4を全体からひけばいい
  vector<ll> Z(N+1,0),Y(N+1,0),X(N,0);
  for(int i=0; i<N; i++){
    ll A;
    cin>>A;
    X[i]=A;
    Z[A]++;
  }
  ll total=0;
  for(int i=0; i<=N; i++){
    if(Z[i]>=2){
      Y[i]=Z[i]*(Z[i]-1)/2;
      total+=Y[i];
    }
  }
//  cout<<"t:"<<total<<endl;
  for(int i=0; i<N; i++){
    ll ans;
    ans=total-(Y[X[i]]-((Z[X[i]]-1)*(Z[X[i]]-2)/2));
//    cout<<"i:"<<i<<" Y:"<<Y[i]<<" Z:"<< Z[i]<<endl;
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 7296
# coding: utf-8


def solve(*args: str) -> str:
    n, m = map(int, args[0].split())
    SC = [tuple(map(int, sc)) for sc in map(str.split, args[1:])]

    D = [None]*(n+1)

    for s, c in SC:
        if not D[s]:
            D[s] = c
        elif D[s] != c:
            return '-1'

    ret = ''
    if D[1] is None and 1 < n:
        D[1] = 1

    for d in D[1:]:
        ret += str(d) if d else '0'
    ret = str(int(ret))

    return ret if len(ret) == n else '-1'


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))


Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

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

        final int A = sc.nextInt();
        final int B = sc.nextInt();

        System.out.println(A >= 13 ? B : A >= 6 ? B/2 : 0);
    }
}


Measured memory_bytes: 21844
import java.util.*;
import java.util.Arrays;
public class Main{
    
    public static boolean keta(int k){
        int ans =0;
        while(k>0){
            k /=10;
            ans++;

        }
        if(ans%2==0){
            return false;

        }
        else{
            return true;
        }
    }
    public static void main(String[] args){
       Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        System.out.println(Math.max(Math.max(a+b,a-b),a*b));

        
        
    }
   
    
       
    
}

Measured memory_bytes: 21844
import java.time.LocalDate;
import java.util.Scanner;

public class Main {

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

		while(sc.hasNext()) {
			int m = sc.nextInt();
			int d = sc.nextInt();

				if (m == 0) {
					break;
				} else {
					dispDoW(m, d);
				}
		}

	}
	private static void dispDoW(int m, int d) {
		LocalDate date = LocalDate.of(2004, m, d);

		switch (date.getDayOfWeek()) {
			case SUNDAY:
				System.out.println("Sunday");
			break;
			case MONDAY:
				System.out.println("Monday");
			break;
			case TUESDAY:
				System.out.println("Tuesday");
			break;
			case WEDNESDAY:
				System.out.println("Wednesday");
			break;
			case THURSDAY:
				System.out.println("Thursday");
			break;
			case FRIDAY:
				System.out.println("Friday");
			break;
			case SATURDAY:
				System.out.println("Saturday");
			break;

		}


	}

}


Measured memory_bytes: 31488
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long llong;
typedef unsigned long long ullong;

using namespace std;

int main() {

	int n;
	cin >> n;
	double ans = n*n*n / 27.0;
	printf("%.16f", ans);
}

Measured memory_bytes: 256
import sys
x=int(input())
a=x%100
b=x-a
i=int(b/100)
sample_list = [1, 2, 3, 4, 5]

for j in reversed(sample_list):
  c=a//j
  a=a%j
  i=i-c
  if i<0:
    print(0)
    sys.exit()
  elif i==0:
    if a==0:
      print(1)
      sys.exit()
    else:
      print(0)
      sys.exit()
  elif i>0:
    if a==0:
      print(1)
      sys.exit()
print(0)



Measured memory_bytes: 3064
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
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()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
from decimal import *

n = INT()
a = LIST()

p = max(a)
m = (p+1)/2 - 0.1
b = []
a.remove(p)
for x in a:
	b.append((x, abs(x-m)))

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

print(p, b[0][0])


Measured memory_bytes: 20588
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};


int main(){
    int x, y;
    cin >> x >> y;
    string ans = "No";
    rep(i, 100) rep(j, 100) {
        int a = i+j;
        int b = 2*i + 4*j;
        if (a==x && b==y) {
            ans = "Yes";
        }
    }
    
    
    cout << ans << endl;
    return 0;
}


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

int f(int n){
 if(n % 2 == 0) return n / 2;
  else return 3 * n + 1;
}

int main(void){
  int N;
  cin >> N;
  vector<int> p(N);
  int sum = 0;
  for(int i = 0; i < N; i++){
    cin >> p[i];
    sum += p[i];
  }
  sort(p.begin(), p.end());
  cout << sum - p[N - 1] / 2;
  return 0;
}

Measured memory_bytes: 256
// NTL_1_B
#include <bits/stdc++.h>
#define endl "\n"
#define rep(i,n) for(int i=0;i<int(n);i++)
#define e_b emplace_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> ipair;
typedef pair<ll,ll> lpair;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v) //vectorの中身を見る
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
void map_p(map<int,int>& d){cout<<"map: ";for(auto a : d){cout<<"{"<<a.first<<":"<<a.second<<"}";}cout<<endl;} //mapの中身を見る
void set_p(set<int>& d){cout<<"set: ";for(int a : d){cout<<a<<" ";}cout<<endl;} //setの中身を見る

ll mod=pow(10,9)+7;
ll modpow(ll m,ll n){ //m^n(mod)
    if(n==0) return 1;
    if(n==1) return m%mod;
    if(n%2==1){
        ll kari=modpow(m,n-1);
        kari*=m;
        kari%=mod;
        return kari;
    }
    ll kari=modpow(m,n/2);
    kari*=kari;
    kari%=mod;
    return kari;
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);

    ll m,n;
    cin>>m>>n;
    cout<<modpow(m,n)<<endl;
    return 0;
}


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

int main()
{
  int n; cin>>n;
  long long a[n];
  for(int i=0; i<n; i++) cin>>a[i];
  
  long long ans = 0;
  
  for(int i=1; i<n; i++)
  {
    if(a[i]<a[i-1]) 
    {
       ans += a[i-1]-a[i];
       a[i] = a[i-1];
    }
  
  }
  
  cout<<ans<<endl;
  
  
}


Measured memory_bytes: 5108
#coding: utf-8
N, K = (int(n) for n in input().split())
A = [int(n) for n in input().split()]

def is_ok(X):
    return sum([-(-n // X) - 1 for n in A]) <= K

def meguru_bisect(ng, ok):
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok(mid):
            ok = mid
        else:
            ng = mid
    return ok

print(meguru_bisect(0, max(A)+1))


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

int main()
{
    int n, m;
    cin >> n >> m;
    vector< pair<long long, long long> > s, c;
    for(int i = 0; i < n; i++)
    {
        long long x, y;
        cin >> x >> y;
        s.push_back(make_pair(x, y));
    }
    for(int i = 0; i < m; i++)
    {
        long long x, y;
        cin >> x >> y;
        c.push_back(make_pair(x, y));
    }
    for(int i = 0; i < s.size(); i++)
    {
        long long S = __LONG_LONG_MAX__;
        int ans;
        for(int j = 0; j < c.size(); j++)
        {
            int sn = abs(s[i].first - c[j].first) + abs(s[i].second - c[j].second);
            if(sn < S)
            {
                ans = j + 1;
                S = sn;
            }
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define all(v) (v).begin(),(v).end()
typedef long long int ll;
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int,int>

int main(){
  ll L, R; cin >> L >> R;
  if (R-L<2018 && R/2019==L/2019){

    ll retval = 2019;
    for (ll i=L;i<=R;i++){
      for (ll j=i+1;j<=R;j++){
        retval = min(retval, (i*j)%2019);
      }
    }
    cout << retval << endl;

  }
  else {
    cout << 0 << endl;
  }
  
  // cout << fixed << setprecision(10);
  
  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <queue>

using namespace std;

char data[1000][1000];
bool visited[1000][1000];
int h, w, n;
class State{
public:
  int x;
  int y;
  int hp;
  int min;
};

int bfs(int, int);
void syokika();
main(){
  while(cin >> h){
    cin >> w >> n;

    int sx, sy;
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	cin >> data[i][j];
	if(data[i][j]=='S'){
	  sx=j;
	  sy=i;
	  data[i][j]='.';
	}
      }
    }

    cout << bfs(sy, sx) << endl;
  }
  return 0;
}


int bfs(int sy, int sx){
  State u, v;
  queue<State> Q;
  int dy[4]={0, -1, 0, 1};
  int dx[4]={1, 0, -1, 0};
  int ny, nx;

  syokika();

  u.y=sy;
  u.x=sx;
  u.hp=1;
  u.min=0;
  visited[u.y][u.x]=true;
  Q.push(u);

  while(!Q.empty()){
    u=Q.front(); Q.pop();
    //    printf("%d %d %d %d\n", u.x, u.y, u.hp, u.min); 
    if(data[u.y][u.x]==u.hp+'0'){
      if(u.hp==n) return u.min;
      u.hp++;
      while(!Q.empty()){
	Q.pop();
      }
      syokika();
      visited[u.y][u.x]=true;
    }
    for(int i=0;i<4;i++){
      nx=u.x+dx[i];
      ny=u.y+dy[i];
      if(nx>=0 && nx<w){
	if(ny>=0 && ny<h){
	  if(data[ny][nx]=='X') continue;
	  if(!visited[ny][nx]){
	    v.y=ny;
	    v.x=nx;
	    v.hp=u.hp;
	    v.min=u.min+1;
	    visited[ny][nx]=true;
	    Q.push(v);
	  }
	}
      }
    }
  }
  return -1;
}

void syokika(){
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      visited[i][j]=false;
    }
  }
}

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

int main() {
  bool flag=true;
  int n;
  cin >> n;
  vector<int> v(n);
  r(i,n)cin >> v[i];
  r(i,n){
    if(v[i]%2==0){
      if(v[i]%3!=0&&v[i]%5!=0)flag=false;
    }
  }
  if(flag)cout<<"APPROVED"<<endl;
  else cout<<"DENIED"<<endl;
}

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

N = int(input())
s = [input() for _ in range(N)]

M = int(input())
t = [input() for _ in range(M)]

result = 0
trash = []
for w in s:
    if w not in trash:
        tmp = s.count(w) - t.count(w)
        if tmp > result:
            result = tmp
        trash.append(w)

print(result)

Measured memory_bytes: 3064
n,a = input().split(' ')

n = int(n)
a = int(a)
b = a

values = {}

i = 2

while(i*i <= a):
    
    count = 0
    while(b%i == 0):
        b = b/i
        count += 1
        
    if count > 0:
        values[i] = count

    i = i+1

if b > 0:
    values[b] = 1

result = 1

for i in values.keys():
    result *= pow(i,values[i]//n)
    
print(int(result))

Measured memory_bytes: 3188
#include <iostream>
#include <stdio.h>

using namespace std;

int main(void){
  int a_1 = 2;
  int x;
  int s = 0;

  while(scanf("%d", &x) != EOF ){
    if(x == 1){
      printf("%d\n", a_1);
    }else{
      s += a_1;
      for(int i = 2; i <= x; i++){
        s += i;
      }
      printf("%d\n", s);
    }
    s = 0;
  }
  
  return 0;
}


Measured memory_bytes: 3204
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <numeric>
#include <queue>
#include <random>
#include <stdlib.h>
#include <string>
using namespace std;

#define rep(i, b, e) for(i = b; i < e; ++i)
#define ull unsigned long long int

int main() {

    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n, c;
    cin >> n >> c;

    if (n - c * 2 <= 0) cout << 0 << endl;
    else cout << n - c * 2 << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <complex>
#include <vector>
#include <algorithm>
#include <stack>
#include <tuple>
#include <cstdio>
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;
typedef complex<double> Point;

namespace std {
  bool operator < (const Point& a, const Point& b) {
    return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
  }
}

struct UF {
	int par[100];
	UF() { int i; rep(i, 100) par[i] = i; }
	int root(int x) { if (par[x] == x) return x; return par[x] = root(par[x]); }
	void unit(int x, int y) { x = root(x); y = root(y); par[x] = y; }
	bool same(int x, int y) { return root(x) == root(y); }
};

int n, m;
vector<Point> ps;
int s[1000], t[1000];

double cross(Point a, Point b) {
	return a.real() * b.imag() - a.imag() * b.real();
}

void reverse(vector<int> &res) {
	int l = 0;
	int r = res.size() - 1;
	while (l < r) {
		swap(res[l], res[r]);
		l++;
		r--;
	}
}

vector<int> convexHull(vector<Point> ps) {
	typedef pair<Point, int> P;
	vector<P> sp;
	stack<int> stk1, stk2;
	int i;
	
	rep(i, ps.size()) sp.push_back(P(ps[i], i));
	sort(sp.begin(), sp.end());
	
	//下凸法 (反時計回り)
	rep(i, sp.size()) {
		while (stk1.size() >= 2) {
			int p2 = stk1.top(); stk1.pop();
			int p1 = stk1.top();
			if (cross(sp[p2].first - sp[p1].first, sp[i].first - sp[p2].first) > 0) {
				stk1.push(p2);
				break;
			}
		}
		stk1.push(i);
	}
	
	//上凸法 (時計回り）
	rep(i, sp.size()) {
		while (stk2.size() >= 2) {
			int p2 = stk2.top(); stk2.pop();
			int p1 = stk2.top();
			if (cross(sp[p2].first - sp[p1].first, sp[i].first - sp[p2].first) < 0) {
				stk2.push(p2);
				break;
			}
		}
		stk2.push(i);
	}
	
	//反時計回りの凸多角形を作りたいので…（始点 = 終点のデータ構造にします）
	vector<int> ret;
	while (!stk1.empty()) {
		ret.push_back(stk1.top());
		stk1.pop();
	}
	reverse(ret);
	
	if (!stk2.empty()) stk2.pop();
	while (!stk2.empty()) {
		ret.push_back(stk2.top());
		stk2.pop();
	}
	
	//番号の変換
	rep(i, ret.size()) ret[i] = sp[ret[i]].second;
	return ret;
}

double dist(Point p, Point q) {
	return abs(p - q);
}

UF uf;

int main() {
	int i;
	
	cin >> n >> m;
	rep(i, n) { double x, y; cin >> x >> y; ps.push_back(Point(x, y)); }
	rep(i, m) { cin >> s[i] >> t[i]; s[i]--; t[i]--; }
	
	vector<int> ids = convexHull(ps);
	
	//境界線を引く
	double ans = 0;
	rep(i, (int)ids.size() - 1) {
		uf.unit(ids[i], ids[i + 1]);
		ans += dist(ps[ids[i]], ps[ids[i + 1]]);
	}
	
	//(境界線（凸法）の頂点を一つのグループにまとめたのち、)最小全域木をする。（クラスカル）
	typedef tuple<double, int, int> T;
	vector<T> edges;
	
	rep(i, m) {
		edges.push_back(T(dist(ps[s[i]], ps[t[i]]), s[i], t[i]));
	}
	sort(edges.begin(), edges.end());
	
	rep(i, m) {
		double cst = get<0>(edges[i]);
		int u = get<1>(edges[i]);
		int v = get<2>(edges[i]);
		if (!uf.same(u, v)) {
			uf.unit(u, v);
			ans += cst;
		}
	}
	
	printf("%.14f\n", ans);
	return 0;
}


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

int main()
{
    int n, d, x;
    cin >> n >> d >> x;
    vector<int> a(n);

    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    
    int sum = x + n;

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

    cout << sum << endl;
}

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

using namespace std;

int
main(int argc, char *argv[])
{
	vector<string> v;

	int N,L;
	cin >> N >> L;
	while (N--)
	{
		string s;
		cin >> s;
		v.push_back(s);
	}
	sort(v.begin(),
		v.end()
	);
	for (auto p : v)
	{
		cout << p;
	}
	cout << endl;

	return 0;
}

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

#define sswap(x, y) { x+=y; y=x-y; x-=y; }
#define LSOne(S) ((S) & (-S))

#define EPS 1e-6
#define MOD 1000000007

#define fi first
#define se second
#define pb push_back
#define ende '\n'

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define mset(x, y) memset(&x, (y), sizeof(x))

using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;

#define M 1000000000000000000

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
	int n; cin >> n;
	unsigned long long m = 1;
	bool limit_reached = false;
	bool seen_zero = false;
	while (n--) {
		unsigned long long e; cin >> e;
		if (e == 0) seen_zero = true;
		if (!seen_zero && !limit_reached) {
				if (m > M/e) {
					m = 1;
					limit_reached = true;
				}
				else m *= e;
		}
	}
	if (seen_zero) cout << 0 << ende;
	else if (limit_reached) cout << -1 << ende;
	else cout << m << ende;
  return 0;
}


Measured memory_bytes: 3672
#include <iostream>
#include <cstdio>
#include <string>

using namespace std;

int main()
{
	int h, w;
	cin >> h >> w;

	string str[26][26];
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cin >> str[i][j];

			if (str[i][j] == "snuke") {
				printf("%c%d\n", 'A' + j, i + 1);
			}
		}
	}

	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <math.h>
using namespace std;

int main()
{
	int n, k;
	cin >> n >> k;
	vector<int> l(n);
	for (int i = 0; i < n; i++) cin >> l[i];
	sort(l.rbegin(), l.rend());
	int sum = 0;
	for (int i = 0; i < k; i++) {
		sum += l[i];
	}
	cout << sum << endl;
}

Measured memory_bytes: 256
#include <stdlib.h>
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
using ll=long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}

int main() {
  long long a;
  cin>>a;
  map<string,long long> mp;
  rep(i,a){
    string s;
    cin>>s;
    sort(s.begin(),s.end());
    mp[s]++;
  }
  long long ans=0;
  for(auto& p:mp){
    long long s=p.second;
    ans+=s*(s-1)/2;
  }
  cout<<ans<<endl;

}


Measured memory_bytes: 11136
import java.util.Scanner;

public class Main {

	private static int[][] map;
	private static int MAX = 1000000;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (true) {
			int n = sc.nextInt();
			if (n == 0) {
				sc.close();
				break;
			}
			int m = sc.nextInt();
			int s = sc.nextInt() - 1;
			int g1 = sc.nextInt() - 1;
			int g2 = sc.nextInt() - 1;

			map = new int[n][n];
			for (int i = 0; i < m; i++) {
				int b1 = sc.nextInt() - 1;
				int b2 = sc.nextInt() - 1;
				int cost = sc.nextInt();
				map[b1][b2] = cost;
			}

			WarshallFloyd();
			/*
			 * それぞれの基地について, 水源からのコストと目的地までのコストの合計値を出す。
			 * この時s->iという向きと、i->gという向きに注意する。
			 */
			int minCost = Integer.MAX_VALUE;
			for (int i = 0; i < n; i++) {
				int cost = map[s][i] + map[i][g1] + map[i][g2];
				minCost = Math.min(minCost, cost);
			}
			System.out.println(minCost);
		}
	}

	static void WarshallFloyd() {
		// 任意の2点間の最小時間を入れる
		int n = map.length;

		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				if (map[i][j] == 0 && i != j) {
					map[i][j] = MAX;
				}
			}
		}

		for (int k = 0; k < n; k++) {
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < n; j++) {
					map[i][j] = Math.min(map[i][j], map[i][k] + map[k][j]);
				}
			}
		}
	}

}

Measured memory_bytes: 63812
from collections import deque

def main():
    n = int(input())
    a = [int(x) for x in input().split()]
    ans = 0
    a.sort(reverse=True)
    q = deque([])
    q.append(a[0])
    for i in range(1, n):
        ans += q.popleft()
        # ここを現状最大を2回加えることがポイント（両脇分）
        q.append(a[i])
        q.append(a[i])
    print(ans)

if __name__ == '__main__':
    main()



Measured memory_bytes: 32452
#include <bits/stdc++.h>
using namespace std;
#define int long long
// Big two primes
#define X 1001100011100001111ll
#define mod 1000000007
#define ll long long
#define all(a) a.begin(),a.end()
#define sortall(a) sort(all(a))
#define fo(i, n) for (int i = 0; i < n; i++)
#define fo1(i, n) for (int i = 1; i <= n; i++)
#define loop(i,a,b) for (int i = a; i < b; i++)
#define nloop(i,a,b) for (int i = a ; i>=b;i--)
#define tc(t) int t; cin >> t; while (t--)
#define arrip(a,n)  int a[n]; fo(i, n) cin >> a[i];
#define arrop(n)  fo(i,n) cout<<a[i]<<" ";
#define pb push_back
#define mp make_pair
#define itr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626

#define fio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define rr return 0
#define prec(n) fixed<<setprecision(n)
#define maxpq priority_queue<int>
#define minpq priority_queue<int, vector<int>, greater<int> >
#define inf (int)(1e18)
#define ini(a, i) memset(a, i, sizeof(a))
#define vi vector<int>
#define fi first
#define se second
#define endl "\n"
#define pi pair<int, int>
#define vpi vector<pi>
#define sz(s) s.size()
#define bits(n) __builtin_popcount(n)//Count set bits

const int MAXN = (int)((1e5) + 100);
int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a);}
int max(int a, int b) {if (a > b) return a; else return b;}
int min(int a, int b) {if (a < b) return a; else return b;}



int32_t main()
{
#ifndef ONLINE_JUDGE
	freopen("atcoderi.txt", "r", stdin);
	freopen("atcodero.txt", "w", stdout);
#endif
	fio;

	int n = 5, k;
	arrip(a, n);
	cin >> k;
	bool f = true;
	fo(i, 5)
	{
		for (int j = i + 1; j < 5; j++)
		{
			int res = abs(a[i] - a[j]);
			if (res > k)
				f = false;
		}
	}
	if (f == false)
		cout << ":(" << endl;
	else
		cout << "Yay!" << endl;
}

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

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
ld EPS = 1e-12;
int INF = numeric_limits<int>::max() / 2;
int MOD = 1e9 + 7;
#define rep(i,n) for(int i=0;i<n;i++)


ll f(ll n) {
	ll p = n / 4 * 4;
 
	ll ret = 0;
	for (ll i = p; i <= n; ++i) {
		ret ^= i;
	}
	return ret;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll a, b;
	cin >> a >> b;
	cout << (f(b) ^ f(a - 1)) << endl;
}


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

typedef long long               ll;
typedef long double             ld;


#define racecar          ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define CLOCK			 cerr << "\nTime elapsed: " << 1000.0 * clock() / CLOCKS_PER_SEC << " ms\n";
#define si(a)            scanf("%d", &a)
#define si2(a,b)         scanf("%d %d", &a,&b)
#define sll(a)           scanf("%I64d",&a)
#define sll2(a,b)        scanf("%I64d %I64d",&a,&b)
#define pb               push_back
#define pi(a)            printf("%d",int(a))
#define pll(a)           printf("%I64d",ll(a))
#define all(x)           (x).begin(),(x).end()
#define rall(x)          (x).rbegin(),(x).rend()
#define ps               printf(" ")
#define nln              printf("\n")
#define ff               first
#define ss               second
#define vi               vector<int>
#define vll              vector<ll>
#define vstr             vector<string>
#define vc               vector<char>
#define PII              pair<int,int>
#define PLL              pair<ll,ll>
#define PI               acos(-1)
#define sq(x)            x*x
#define forr(i,a,b)      for(ll i=ll(a);i<ll(b);i++)
#define forn(i,a,b)      for(ll i=ll(a);i>ll(b);i--)
#define max3(a,b,c)      max(a,max(b,c))
#define max4(a,b,c,d)    max(max3(a,b,c),d)
#define min3(a,b,c)      min(a,min(b,c))
#define mod              1000000007
#define inf              9223372036854775807

///knight moves:
///int dx[] = {-2, -1, 1, 2, -2, -1, 1, 2};
///int dy[] = {-1, -2, -2, -1, 1, 2, 2, 1};


ll power(ll b,ll n)
{
    if(n==0) return 1;
    else if(n%2) return b*power(b,n/2)*power(b,n/2);
    else return power(b,n/2)*power(b,n/2);
}

ld root(ll n,ll r)
{
    ld dif=0.0001;
    ld guess=n/2.0;
    while(abs(pow(guess,r)-n)>=dif)
    {
        ld temp=pow(guess,r)-n;
        ld tmp=r*pow(guess,r-1);
        guess-=temp/tmp;
    }
    return guess;
}

void fileio()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
}


int solve()
{
	int n,q;
	si2(n,q);

	string x;
	cin>>x;

	int ara[n+1];
	forr(i,0,n+1) ara[i]=0;
	forr(i,0,x.size()-1)
	{
		if(x[i]=='A' && x[i+1]=='C') 
		{
			ara[i+1]++;
			ara[i+2]++;
		}
	}
	
	int sum[n+1];
	sum[0]=0;
	forr(i,1,n+1) sum[i]=sum[i-1]+ara[i];
	
	/*forr(i,1,n+1) pi(ara[i]),ps;
	nln;
	
	forr(i,0,n+1) pi(sum[i]),ps;
	nln;*/
	
	
	
	while(q--)
	{
		int l,r;
		si2(l,r);
		
		int tot=sum[r]-sum[l-1];
		
		r--;l--;
		if(x[l]=='C' && ara[l+1]) tot--;
		if(x[r]=='A' && ara[r+1]) tot--;
		
		pi(tot/2);
		nln;
	}
		
		
			
	
    return 0;
}


int main()
{
//    racecar;
//    cout<<fixed<<setprecision(6);
//    fileio();
    solve();
//	CLOCK;   
    return 0;
}



///    Before submission=>
///    ***check for integer overflow,array bounds
///    ***check for n


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;
using ll = long long;

int32_t main() {
  ios::sync_with_stdio(0); cin.tie(0);
  int n;
  cin >> n;
  cout << fixed << setprecision(12) << double((n + 1) / 2) / n << '\n';
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()

using namespace std;
typedef long long ll;

int main(){
    ll n;
    cin >> n;
    vector<ll> a(n-1, 0);
    map<ll, ll> m;
    REP(i, n-1){
        m[i] = 0;
    }

    REP(i, n-1){
        cin >> a[i];
        m[a[i]-1]++;
    }

    REP(i, n-1){
        cout << m[i] << endl;
    }
    cout << '0' << endl;
}


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

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

    int X, Y;
    cin >> X >> Y;
    int ret = 0;
    if (X == 3) ret += 100000;
    if (X == 2) ret += 200000;
    if (X == 1) ret += 300000;
    if (Y == 3) ret += 100000;
    if (Y == 2) ret += 200000;
    if (Y == 1) ret += 300000;
    if (X == 1 && Y == 1) ret += 400000;
    cout << ret << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <vector>
using namespace std;
int main()
{
  int n; cin>>n; set<int> s;
  vector<int>v; 
  int sieve[1000001] = {0};  int max = 0;
  for(int i = 0; i < n; i++)
  {	int x; cin>>x;
    if(s.find(x) == s.end())
    {
      s.insert(x); v.push_back(x);
      if(x > max)
        max = x;
    }
   else
   {
     sieve[x] = 1;
   }
  }
  for(int i = 0; i < v.size(); i++)
  {
    int j = 2;
    while((v[i]*j) <= max)
    {
      sieve[v[i]*j] = 1;
      j++;
    }    
  }
  int count = 0;
  for(int i = 0; i < v.size(); i++)
  {
    if(sieve[v[i]] == 0)
      	count++;
  }
  cout<<count;
}


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

    int right = 1;
    int left;
    int ans;
    for(int i=2; i<=999; i++){
        left = right;
        right += i;
        if(left-a == right-b){
            ans = left - a;
        }
    }
    cout << ans << endl;

    return 0;
}

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

#define rep(i, n) for(int i = 0; i < n; i++)

typedef long long ll;
using namespace std;
int mod = 1000000007;

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    queue<ll> que;
    for(int i = 1; i <= 9; i++) que.push(i);

    int K; cin >> K;
    for(int i = 1; i <= K; i++){
        ll op = que.front();
        que.pop();
        if(i == K) cout << op << endl;
        else{
            ll op10 = op*10;
            ll dig_tail = op % 10;
            if(dig_tail == 0){
                que.push(op10);
                que.push(op10+1);
            }
            else if(dig_tail == 9){
                que.push(op10+8);
                que.push(op10+9);
            }
            else{
                que.push(op10+dig_tail-1);
                que.push(op10+dig_tail);
                que.push(op10+dig_tail+1);
            }
        }
    }
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <algorithm>
#include <array>
#include <set>
#include <map>
#include <queue>
#include <tuple>
#include <unordered_set>
#include <unordered_map>
#include <functional>
#include <cassert>
#define repeat(i,n) for (int i = 0; (i) < (n); ++(i))
#define whole(f,x,...) ([&](decltype((x)) y) { return (f)(begin(y), end(y), ## __VA_ARGS__); })(x)
using namespace std;
struct disjoint_sets {
    vector<int> xs;
    explicit disjoint_sets(size_t n) : xs(n, -1) {}
    bool is_root(int i) { return xs[i] < 0; }
    int find_root(int i) { return is_root(i) ? i : (xs[i] = find_root(xs[i])); }
    int set_size(int i) { return - xs[find_root(i)]; }
    int union_sets(int i, int j) {
        i = find_root(i); j = find_root(j);
        if (i != j) {
            if (set_size(i) < set_size(j)) swap(i,j);
            xs[i] += xs[j];
            xs[j] = i;
        }
        return i;
    }
    bool is_same(int i, int j) { return find_root(i) == find_root(j); }
};
struct edge_t { int s, t, c; };
bool operator < (edge_t const & a, edge_t const & b) { return a.c < b.c; } // strict weak ordering
int main() {
    while (true) {
        int n, m; cin >> n >> m;
        if (n == 0 and m == 0) break;
        vector<edge_t> es(m);
        repeat (i,m) {
            cin >> es[i].s >> es[i].t >> es[i].c;
            -- es[i].s;
            -- es[i].t;
        }
        whole(sort, es);
        disjoint_sets t(n);
        vector<int> acc;
        for (edge_t e : es) {
            if (not t.is_same(e.s, e.t)) {
                t.union_sets(e.s, e.t);
                acc.push_back(e.c);
            }
        }
        whole(sort, acc);
        double ans = (n-1) % 2 == 0 ? (acc[(n-1)/2] + acc[(n-1)/2+1]) / 2.0 : acc[(n-1)/2];
        cout << ans << endl;
    }
    return 0;
}

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

int main(){
    int64_t N, A, B;
    cin >> N >> A >> B;
    if(A > B) swap(A, B);
    int64_t d = B-A, ans;
    if(d%2){
        int64_t m1 = (N-A) + (N-B) + 1, m2 = (A-1) + (B-1) + 1;
        ans = min(m1, m2)/2;
    }else{
        ans = d/2;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string.h>
#include<string>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<bitset>
#include<math.h>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<iomanip>
#include<unordered_map>
using namespace std;
#define ll long long
#define ull unsigned long long
#define mod 1000000007
#define mod2 998244353
#define SORT(v) sort(v.begin(), v.end())
#define RSORT(v) sort(v.rbegin(), v.rend())
typedef pair<int, int> pii;

ll exp(ll taban, ll us) {
    ll carpan = taban % mod;
    ll temp = us;
    ll res = 1;
    while(temp){
        if(temp % 2) res = (res*carpan) % mod;
        temp /= 2;
        carpan = (carpan*carpan) % mod;
    }
    return res;
} 
ll ebob(ll a, ll b){
    if(!a)return b;
    return ebob(b%a, a);
} 
ll ekok(ll a, ll b){
    return (a*b)/ebob(a, b);
}
#define pb push_back
int main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL);
	int a, b, c, d; cin>>a>>b>>c>>d;
	c/b + (c%b > 0) <= a/d + (a%d > 0) ? cout<<"Yes" : cout<<"No";
}

Measured memory_bytes: 3612
N, M, C = map(int, input().split())
B = list(map(int, input().split()))
A = [0 for i in range(N)]
for i in range(N):
    A[i] = list(map(int,input().split()))

counter = 0
for i in range(N):
    sum = 0
    for j in range(M):
        sum += A[i][j]*B[j]
    sum += C
    if sum > 0:
        counter += 1

print(counter)

Measured memory_bytes: 3064