akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <iostream>
using namespace std;

typedef long long ll;
const ll inf = 1e15;

int main() {
    int n;
    scanf("%d",&n);
    vector<int> a(n+1,0),b(n+1,0),c(n+2,0);
    for (int i = 1; i <= n; i++) {
        scanf("%d",&a[i]);
        b[i] = max(b[i-1],a[i]);
    }
    for (int i = n; i > 0; i--) {
        c[i] = max(c[i+1],a[i]);
    }
    for (int i = 1; i <= n; i++) {
        int res = max(b[i-1],c[i+1]);
        printf("%d\n",res);
    }
    return 0;
}

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

#include <math.h>
#include <stdlib.h>


#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

template<class T> inline bool chmin(T &a, T b) { if(a > b){ a = b; return true; } return false; }
template<class T> inline bool chmax(T &a, T b) { if(a < b){ a = b; return true; } return false; }

//INT_MAX	2,147,483,647 = 2*1.0e9



int main(){

    string str =  "MARCH";
    int N; cin >> N;

    map<char, ll> mp;

    for(int i = 0; i < N; i++){
        string name; cin >> name;
        mp[name[0]]++;
    }

    ll ans = 0;
    for(int i = 0; i < 3; i++){
        for(int j = i+1; j < 4; j++){
            for(int k = j+1; k < 5; k++){
                ans += mp[str[i]] * mp[str[j]] * mp[str[k]];
            }
        }
    }
    
    cout << ans << endl;

    return 0;
}


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

public class Main {

	static BufferedReader reader;
	//static field here
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		reader = new BufferedReader(new InputStreamReader(System.in));
		//code here
		String[] ND = readLine();
		int N = Integer.parseInt(ND[0]);
		int D = Integer.parseInt(ND[1]);
		int[][] X = new int[N][D];
		for(int i=0;i<N;i++) {
			String[] t = readLine();
			for(int d=0;d<D;d++) {
				X[i][d]=Integer.parseInt(t[d]);
			}
		}
		
		int cnt = 0;
		for(int i=0;i<N;i++) {
			for(int j=i+1;j<N;j++) {
				double a = getDistance(X[i],X[j]);
				if(Math.round(a)==a) {cnt++;}
			}
		}
		
		//String[] s = readLine();
		print(cnt);
	}
	
	//functions here
	//note that all methods should be STATIC
	private static double getDistance(int[] p1,int[] p2) {
		double s = 0;
		for(int i=0;i<p1.length;i++) {
			s+=(p1[i]-p2[i])*(p1[i]-p2[i]);
		}
		return Math.sqrt(s);
	}
	
	private static String[] readLine(){
		try{
			return reader.readLine().split(" ");
		}catch(Exception e){
			e.printStackTrace();
			return new String[]{e.getMessage()};
		}
	}
	private static void print(Object o){
		System.out.println(o);
	}
	private static void print(){
		System.out.println();
	}
}

Measured memory_bytes: 21588
/*
                    author         : TAPAN SAVANI 
                    codeforces     : savanitapan2001
                    codechef       : savanitapan17
*/

/*
------------------------------------------------------------------------

░██╗░░░░░░░██╗░█████╗░██████╗░██╗░░██╗  ██╗░░██╗░█████╗░██████╗░██████╗░
░██║░░██╗░░██║██╔══██╗██╔══██╗██║░██╔╝  ██║░░██║██╔══██╗██╔══██╗██╔══██╗
░╚██╗████╗██╔╝██║░░██║██████╔╝█████═╝░  ███████║███████║██████╔╝██║░░██║
░░████╔═████║░██║░░██║██╔══██╗██╔═██╗░  ██╔══██║██╔══██║██╔══██╗██║░░██║
░░╚██╔╝░╚██╔╝░╚█████╔╝██║░░██║██║░╚██╗  ██║░░██║██║░░██║██║░░██║██████╔╝
░░░╚═╝░░░╚═╝░░░╚════╝░╚═╝░░╚═╝╚═╝░░╚═╝  ╚═╝░░╚═╝╚═╝░░╚═╝╚═╝░░╚═╝╚═════╝░
 
------------------------------------------------------------------------
*/

#include <bits/stdc++.h>
using namespace std;

#define HAPPY_CODING              \
    ios_base::sync_with_stdio(0); \
    cin.tie(NULL);                \
    cout.tie(NULL);
#define pb push_back
#define mp make_pair
#define Debug(x) cout << #x " = " << (x) << endl
#define SORT(a) sort(a.begin(), a.end())
#define SORTR(a) sort(a.rbegin(), a.rend())
#define mod 1000000007
#define pi 3.141592653589793238
#define ll long long int
#define ull unsigned long long
#define be begin()
#define en end()
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define FORI(i, a, b) for (int i = a; i >= b; i--)

typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
typedef pair<ll, ll> PL;
typedef vector<PI> VPI;

int main()
{
    HAPPY_CODING;

    int n, k = 2;
    cin >> n;

    int a[n];
    FOR(i, 0, n)
    cin >> a[i];

    int dp[n];
    dp[0] = 0;
    FOR(i, 1, n)
    {
        int x = min(i, k);
        int y = i - x;
        dp[i] = INT_MAX;

        // while (x--)
        for (int j = i - 1; j >= y; j--)
        {
            dp[i] = min(dp[i], dp[j] + abs(a[i] - a[j]));
        }
    }

    cout << dp[n - 1] << "\n";

    return 0;
}


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

#define REP(i, start, count) for(int i=(start); i<(int)(count); ++i)
#define rep(i, count) REP(i, 0, count)
#define ALLOF(c) (c).begin(), (c).end()

typedef long long ll;
typedef unsigned long long ull;

string S;
int Q;

int main(void) {

    cin >> S >> Q;

    vector<char> ss(100000 * 4 + 2);
    int m = 400000 / 2;
    int l = m - 1;
    int r = m + 1;
    ss[m] = '\0';

    bool rev = false;
    rep(i, Q) {
        int n;

        cin >> n;
        if (n == 1) {
            rev = !rev;
            continue;
        }

        int f; char c;
        cin >> f >> c;
        if (f == 1) {
            if (rev) {ss[r] = c; r++;}
            else {ss[l] = c; l--;}
        }
        else {
            if (rev) {ss[l] = c; l--;}
            else {ss[r] = c; r++;}
        }

    }

    ss[r] = '\0';

    if (rev) {
                // printf("%s\n", &ss[l + 1]);
                //         printf("%s\n", &ss[m + 1]);
        reverse(ss.begin() + l + 1, ss.begin() + m);
        reverse(ss.begin() + m + 1, ss.begin() + r);

                        // printf("%s\n", &ss[l + 1]);
                        // printf("%s\n", &ss[m + 1]);
        reverse(ALLOF(S));

        printf("%s", &ss[m + 1]);
        cout << S;
        printf("%s", &ss[l + 1]);
    }
    else {
        printf("%s", &ss[l + 1]);
        cout << S;
        printf("%s", &ss[m + 1]);
    }

    cout << endl;

    return 0;
}

Measured memory_bytes: 1152
#include <iostream>
#include <algorithm>
#include <map>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;
typedef long long int ll;
#define rep(i, n) for(int i=0;i< int (n);i++)

int main(void)
{
    ll N, M, L;    
    ll  A, B;
    string n;
    bool ques = true;
    
    cin >> N >> A >> B;

    if (N <= A)
        cout << N << endl;
    else if(N <= (A+B))
    {
         cout << A << endl;
    }
    else
    {
        M = (N / (A + B))*A;
        L = N % (A + B);
        if (L <= A)
            M += L;
        else
            M += A;  
        cout << M << endl;
    }

}

   

Measured memory_bytes: 256
#include <cstdio>
#include <map>
#define repeat(i, n) for (int i = 0; (i) < int(n); ++(i))
using namespace std;
template <class T> inline void setmax(T & a, T const & b) { a = max(a, b); }

int main() {
    int n; scanf("%d", &n);
    map<int, int> cnt;
    repeat (i, n) {
        int a_i; scanf("%d", &a_i);
        cnt[a_i] += 1;
    }
    int result = 0;
    for (auto it : cnt) {
        for (int x : {
                    it.first - 1,
                    it.first,
                    it.first + 1 }) {
            int acc = 0;
            if (cnt.count(x - 1)) acc += cnt[x - 1];
            if (cnt.count(x    )) acc += cnt[x    ];
            if (cnt.count(x + 1)) acc += cnt[x + 1];
            setmax(result, acc);
        }
    }
    printf("%d\n", result);
    return 0;
}


Measured memory_bytes: 3200
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n; cin>>n;
  set<int> d;
  for(int i=0; i<n; ++i){
    int a; cin>>a;
    d.insert(a);
  }
  cout << d.size()<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include <cmath>
using namespace std;

int main() {
	string s, t;
	cin >> s >> t;
	
	int count = 0;
	for (int i = 0; i < s.size(); i++) {
		if (s.at(i) == t.at(i)) {
			count = ++count;
		}
	}
	cout << count << endl;
}


Measured memory_bytes: 256
N, M = map(int, list(input().split()))
L = []
R = []
for i in range(M):
    l, r = map(int, input().split())
    L.append(l)
    R.append(r)
if max(L) <= min(R):
    print(min(R) - max(L)+1)
else:
    print(0)

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


int main(){
  
  int N, i;
  cin >> N;
  vector<int> d(N);
  
  for(i = 0; i < N; i++) cin >> d.at(i);
  sort(d.begin(), d.end());
    
  cout << d.at(N / 2) - d.at(N / 2 - 1) << endl;
  return 0;
}

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

int main() {
  ll n, k, ans = 0;
  cin >> n >> k;
  vector<ll> h(n);
  rep(i, n) cin >> h[i];
  sort(h.begin(), h.end());
  rep(i, n - k) ans += h[i];
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4788
/*Lucky_Glass*/
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
int n,A[105];
int F(int x)
{
	int tot=0;
	for(int i=0;i<n;i++)
		tot+=(A[i]-x)*(A[i]-x);
	return tot;
}
int main()
{
	scanf("%d",&n);
	int MAX=-1e8,MIN=1e8;
	for(int i=0;i<n;i++)
		scanf("%d",&A[i]),MIN=min(MIN,A[i]),MAX=max(MAX,A[i]);
	int ans=1e8;
	for(int i=MIN;i<=MAX;i++)
		ans=min(ans,F(i));
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 256
/*Coded by::
    **Avinash Tiwary**
    **BE/10298/2015**
    **Production Engineer**
    **Producing <code>**
*/
#include<bits/stdc++.h>
#define bf ios_base::sync_with_stdio (0), cin.tie (0)
typedef long long ll;
typedef double d;
#define MAX 1000009
#define MIN -1
#define M 1000000007
#define INF 5e17
using namespace std;
typedef vector<ll> Vector;
typedef queue<ll > Queue;
typedef stack<ll> Stack;
typedef pair<ll,ll> Pair;
#define mp make_pair
#define pb push_back
bool desc(ll i, ll j) { return i > j; }
ll x[MAX],y[MAX],xc[MAX],yc[MAX],vis[MAX];
int main(){
    bf;
    ll i=0,j=1,t,k,n,l=0,a=0,m,b=0,ans=0; string s;
    cin>>n>>m;
    for(i=1;i<=n;i++) cin>>x[i]>>y[i];
    for(i=1;i<=m;i++) cin>>xc[i]>>yc[i];
    for(i=1;i<=n;i++){
        ll dis=1e9,ldis,z;
        for(j=1;j<=m;j++){
            ldis=abs(xc[j]-x[i])+abs(yc[j]-y[i]);
            //cout<<ldis<<" ";
            if(dis>ldis&&vis[j]==0){
                dis=ldis;
                z=j; 
            }
        }
        cout<<z<<endl; //vis[z]=1;
    }
    return 0;
}  

Measured memory_bytes: 8448
from itertools import permutations

n = int(input())
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))

for i, x in enumerate(permutations([i+1 for i in range(n)])):
    if x == p:
        a = i
    if x == q:
        b = i
print(abs(a-b))




Measured memory_bytes: 3060
#include <stdio.h>

void trace(int A[], int n){
	int i;
	for ( i = 0; i < n; i++ ){
	  if ( i > 0 ) printf(" ");
	  printf("%d", A[i]);
	}
	printf("\n");
}

void bubbleSort(int A[], int N){
	bool flag = 1;
	int j, v, count=0;
	for(int i =0; flag; i++){
		flag = 0;
		for(j=N-1; j >=i+1; j--){
			if (A[j] < A[j-1]){
				v = A[j];
				A[j] = A[j-1];
				A[j-1] = v;
				flag = 1;
				count++;
			}
		}
	}
	trace(A, N);
	printf("%d\n", count);
}

int main(){
	int n, i;
	int A[100];
	scanf("%d", &n);
	for ( i = 0; i < n; i++ ) scanf("%d", &A[i]);
	
	bubbleSort(A, n);

	return 0;
}


Measured memory_bytes: 2744
import java.util.Scanner;

/**
 * Shuffle
 */
public class Main {

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

        String str;
        int m,n = 0;
        while (scan.hasNext()) {
            str = scan.next();
            if (str.equals("-")) {
                return;
            }
            m = scan.nextInt();
            for (int i = 0; i < m; i++) {
                n = scan.nextInt();
                str = str.substring(n, str.length())
                        + str.substring(0, n);
            }
            System.out.println(str);
        }
    }
}

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

namespace abc081_b
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var a = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();

            var i = 0;
            var len = a.Length;
            while(true){
                a = a.Where(x => x % 2 == 0).Select(x => x / 2).ToArray();
                if(len == a.Length){
                    i += 1;
                }else{
                    break;
                }
            }
            Console.WriteLine(i);
        }
    }
}


Measured memory_bytes: 13396
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include<vector>
#include<iomanip>
#include<map>
#include <queue>
#include<cmath>
#include<cstdio>
#include<iomanip>

using namespace std;
using ll = long long int; 

void prime(vector<int> &num, int n){
    for(int i=0;i<=n;i++){
        num[i] = 1;
    }
    num[0] = 0;
    num[1] = 0;
    num[2] = 1;

    for(int i=2;i<=sqrt(n);i++){
        if(num[i] == 1){
            for(int j=2;j<=n/i;j++){
                num[i*j] = 0;
            }
        }
    }
}


ll gcd(ll a, ll b) {
  ll tmp;
  if ( b > a) {
    tmp = a;
    a = b;
    b = tmp;
  }
  while (a % b !=0) {
    tmp = b;
    b = a % b;
    a = tmp;
  }
  return b;
}
 
ll lcm(ll a, ll b) {
  return a * b / gcd(a, b);
}

ll keta(ll a){
  ll ans = 1;
  while(1){
    if(a/10 > 0){
      ans++;
      a = a/10;
    }
    if(a<10) break;
  }
  return ans;
}

const int MAX = 50;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(void){

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

    if(sum==0){
        cout<<"-1"<<endl;
    }else{
        cout<<n-sum<<endl;
    }
}

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

int main(){
   int n; cin >> n;
	map<P,int> fr;
  int ans=0;
    for(int i=1; i<=n; i++){
        int ma=i%10;
        int se; int x=i;
        while(x){
            se=x;
            x/=10;
        }
        P p(ma,se);
        fr[p]++;
    }
  for(int i=1; i<=n; i++){
    	int maa=i%10;
        int see; int xx=i;
        while(xx){
            see=xx;
            xx/=10;
        }
      	P q(see,maa);
  	    ans+=fr[q];
    }
    cout << ans << endl;
return 0;
}


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

int main()
{
	int N;
	cin >> N;
	
	char* S = new char[N];
	S[N] = '\0';
	for (int i = 0; i < N; i++) {
		cin >> S[i];
	}
	
	if (N % 2 != 0) {
		cout << "No" << endl;
		return 0;
	}
	for (int i = 0; i < (N / 2); i++) {
		if (S[i] != S[(N / 2)+i]) {
			cout << "No" << endl;
			return 0;
		}
	}

	cout << "Yes" << endl;
	return 0;
}

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

using i64 = int64_t;

i64 gcd(i64 m, i64 n) {
    return (n == 0 ? m : gcd(n, m % n));
}

i64 lcm(i64 m, i64 n) {
    return m / gcd(m, n) * n;
}

int main(){
    i64 a, b, c, d;
    cin >> a >> b >> c >> d;
    i64 n = b - a + 1;
    i64 e = lcm(c, d);
    i64 ans1 = b / c - (a-1) / c;
    i64 ans2 = b / d - (a-1) / d;
    i64 ans3 = b / e - (a-1) / e;
    cout << n - (ans1 + ans2 - ans3) << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#if ONLINE_JUDGE
#define DEBUG false
#else
#define DEBUG true
#endif
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, k, n) for (int i = (int)(k); i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define rREP(i, k, n) for (int i = (int)(n)-1; i >= k; i--)
#define foreach(i, vec) for(auto &&i : vec)
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort(all(x))
#define REV(x) reverse(all(x))
#define MAX(x) *max_element(all(x))
#define MIN(x) *min_element(all(x))
#define LOWitr(x, n) lower_bound(all(x), n)
#define UPRitr(x, n) upper_bound(all(x), n)
#define cii(x) int x;cin >> x
#define cill(x) LL x;cin >> x
#define cis(x) string x;cin >> x
#define co(x) cout << x << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define truecheck assert
#define dump(x) cerr << #x << ": " << (x) << endl
using namespace std;
typedef long long LL;
typedef long long int64;
typedef std::vector<int> VI;
typedef std::vector<VI> VVI;
typedef std::vector<LL> VL;
typedef std::vector<VL> VVL;
typedef std::vector<string> VS;
typedef std::pair<int, int> PII;
typedef std::pair<int64, int64> PLL;
typedef std::queue<int> QI;
typedef std::priority_queue<int> PQI;
template<class T,class U>inline bool chmax(T &a, const U &b){if (a<b){a=b;return true;}return false;}
template<class T,class U>inline bool chmin(T &a, const U &b){if (b<a){a=b;return true;}return false;}
template<class T,class U>inline void vcin(T &v, U n){rep(i, n){typename T::value_type a;cin >> a;v.pb(a);}}

const int INF = 1e9, MOD = 1e9 + 7;
const LL LLINF = 1e16;
// M_PI 3.1415...

int main() {
    fastcin();
    cout << fixed << setprecision(10);
    cis(s);
    VI mod(2019);
    LL pre = 0, temp = 1;
    mod[0]++;
    rrep(i, s.length()){
        LL sum = (s[i]-'0') * temp + pre;
        sum %= 2019;
        mod[sum]++;
        temp = temp * 10 % 2019;
        pre = sum;
    }
    LL ans = 0;
    rep(i, 2019){
        ans += mod[i] * (mod[i]-1) / 2;
    }
    co(ans);
    return 0;
}

Measured memory_bytes: 3740
n = int(input())
t, a = map(int, input().split())
t_mean_list = list(map(int, input().split()))
t_diff_list = list(map(lambda x: abs(t - x * 0.006 - a), t_mean_list))
 
print(t_diff_list.index(min(t_diff_list)) + 1)

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

const int N = 2005, mod = 1000 * 1000 * 1000 + 7;


long long fac[N * N];
long long facp[N * N];
long long dp[N][N];
long long ps[N][N];

int po(int x, int y) {
	if (y == 0) {
		return 1;
	}
	long long ans = po(x, y / 2);
	ans *= ans;
	ans %= mod;
	if (y % 2) {
		ans *= x;
		ans %= mod;
	}
	return ans;
}
int chs(int x, int y) {
	long long ans = fac[x];
	ans *= facp[y];
	ans %= mod;
	ans *= facp[x - y];
	ans %= mod;
	return ans;
}
int main() {
	int n, k;
	cin >> n >> k;
	if (k == 1) {
		cout << 1;
		return 0;
	}
	fac[0] = 1;
	for (int i = 1; i <= n * k; i++) {
		fac[i] = fac[i - 1] * i;
		fac[i] %= mod;
	}
	facp[n * k] = po(fac[n * k], mod - 2);
	facp[0] = 1;
	for (int i = n * k - 1; i; i--) {
		facp[i] = facp[i + 1] * (i + 1);
		facp[i] %= mod;
	}
	dp[1][1] = 1;
	ps[1][1] = 1;
//	cout << chs(4, 2) << endl;
	for (int i = 2; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			dp[i][j] = ps[i - 1][i - 1];
			if (j - 2 >= 0) {
				dp[i][j] -= ps[i - 1][j - 2] - mod;
				dp[i][j] %= mod;
			}
			dp[i][j] *= i;
			dp[i][j] %= mod;
			dp[i][j] *= chs(i * k - j - 1, k - 2);
			dp[i][j] %= mod;
		//	cout << i << " " << j << " " << dp[i][j] << endl;
			ps[i][j] = ps[i][j - 1] + dp[i][j];
			ps[i][j] %= mod;
		}
	}
	cout << ps[n][n];
	return 0;
}


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

int main(){
  int n;
  cin >> n;
  int s[n],sum=0;
  bool b[n];
  for(int i=0;i<n;i++){
    cin >>s[i];
    sum+=s[i];
  }
  sort(s,s+n);
  for(int i=0;i<n;i++){
    if(s[i]%10==0)b[i]=true;
    else b[i]=false;
  }
  bool ten=true;
   for(int i=0;i<n;i++)if(!b[i])ten=false;
  if(sum%10!=0)cout << sum <<endl;
  else if(ten)cout << 0 <<endl;
  else for(int i=0;i<n;i++){
    if(b[i]==false){
      cout << sum-s[i] <<endl;
      break;
    }
  }
}

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;
using P = pair<int, int>;

int n, m, q;
vector<int> a, b, c, d;
int ans;

void dfs(vector<int> A)
{
    cout << endl;
    if (A.size() == n + 1)
    {
        int now = 0;
        rep(i, q)
        {
            if (A[b[i]] - A[a[i]] == c[i])
                now += d[i];
        }
        ans = max(now, ans);
        return;
    }
    A.push_back(A.back());
    while (A.back() <= m)
    {
        dfs(A);
        A.back()++;
    }
}
int main()
{
    cin >> n >> m >> q;
    a = b = c = d = vector<int>(q);
    rep(i, q) cin >> a[i] >> b[i] >> c[i] >> d[i];
    dfs(vector<int>(1, 1));
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
#define all(c)  c.begin(), c.end()
#define mp make_pair
#define endl "\n"
#define N 998244353
#define INF 1e9

 
ll power(ll x, ll y, ll m) { 
    if (y == 0) return 1; 
    ll p = power(x, y/2, m) % m; 
    p = (p * p) % m; 
    return (y%2 == 0)? p : (x * p) % m; 
} 
int main(){
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    // #endif
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
    
    string s ;
    cin >> s ;
    if(s[2]==s[3] && s[4]==s[5])cout << "Yes" << endl ;
    else cout << "No" << endl ;


    return 0 ;
    
}


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

using namespace std;

int a[1000];

int main()
{
    int n;
    while(cin>>n)
    {
        int i;
        for(i=0;i<n;i++)
            scanf("%d",&a[i]);
        sort(a,a+n);
        int ma=a[n-1],mi=a[0];
        int num=100000000;
        int x=(ma+mi)/2;
        for(i=x-20;i<x+20;i++)
        {
            int y=0;
            for(int j=0;j<n;j++)
                y+=(a[j]-i)*(a[j]-i);
            num=min(num,y);
        }
        printf("%d\n",num);
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<queue>
#include<vector>
using namespace std;
//queue?????\???£???????????????????????????pop?????????
queue<std::vector<int> > cubes;
vector<int> puzzle;
vector<int> tmppuzzle;
namespace my{
int top,left,right,up,down,back;
}
 
void clear(){
  for(int i=0;i<31;i++){
    tmppuzzle[i] = puzzle[i];
  }
}
 
int  BFS(){
 
  while(!cubes.empty()){
    cubes.pop();
  }
 
  bool flag = true;
  puzzle[30] = 0;
  cubes.push(puzzle);
 
  while(1){
 
 
 
 
 
    flag = true;
    puzzle = cubes.front();
    cubes.pop();
    if(puzzle[30] == 8){
      return 8;
    }
    my::top = puzzle[0];
    my::left = puzzle[15];
    my::right = puzzle[12];
    my::up = puzzle[18];
    my::down = puzzle[9];
    my::back = puzzle[21];
 
 
    if(flag){
      for(int i=1;i<9;i++)
        if(my::top != puzzle[i]){
          flag = false;
          break;
        }
    }
 
    if(flag){
      for(int i=16;i<18;i++){
        if(my::left != puzzle[i]){
          flag = false;
          break;
        }
      }
    }
 
    if(flag){
      for(int i=13;i<15;i++){
        if(my::right != puzzle[i]){
          flag = false;
          break;
        }
      }
    }
 
    if(flag){
      for(int i=19;i<21;i++){
        if(my::up != puzzle[i]){
          flag = false;
          break;
        }
      }
    }
 
    if(flag){
      for(int i=9;i<12;i++){
        if(my::down != puzzle[i]){
          flag = false;
          break;
        }
      }
    }
 
    if(flag){
      for(int i=22;i<30;i++){
        if(my::back != puzzle[i]){
          flag = false;
          break;
        }
      }
    }
 
    if(flag){
      return puzzle[30];
    }
 
 
    puzzle[30] += 1;
    clear();
    swap(tmppuzzle[17],tmppuzzle[12]);
    swap(tmppuzzle[7],tmppuzzle[22]);
    swap(tmppuzzle[6],tmppuzzle[21]);
    swap(tmppuzzle[8],tmppuzzle[23]);
    swap(tmppuzzle[9],tmppuzzle[11]);//???´???¢
    cubes.push(tmppuzzle);
 
    clear();
    swap(tmppuzzle[0],tmppuzzle[27]);
    swap(tmppuzzle[1],tmppuzzle[28]);
    swap(tmppuzzle[2],tmppuzzle[29]);
    swap(tmppuzzle[14],tmppuzzle[15]);
    swap(tmppuzzle[18],tmppuzzle[20]);//???´???¢
    cubes.push(tmppuzzle);
 
    clear();
    swap(tmppuzzle[0],tmppuzzle[23]);
    swap(tmppuzzle[3],tmppuzzle[26]);
    swap(tmppuzzle[6],tmppuzzle[29]);
    swap(tmppuzzle[9],tmppuzzle[20]);
    swap(tmppuzzle[15],tmppuzzle[17]);//???´???¢
    cubes.push(tmppuzzle);
 
    clear();
    swap(tmppuzzle[2],tmppuzzle[21]);
    swap(tmppuzzle[5],tmppuzzle[24]);
    swap(tmppuzzle[8],tmppuzzle[27]);
    swap(tmppuzzle[11],tmppuzzle[18]);
    swap(tmppuzzle[12],tmppuzzle[14]);//???´???¢
    cubes.push(tmppuzzle);
  }
 
  return -1;
}
 
int main(){
 
  int n;
  cin >> n;
 
  puzzle.resize(31);
  tmppuzzle.resize(31);
 
  for(int i=0;i<n;i++){
    for(int i=0;i<30;i++){
      cin >> puzzle[i];
    }
    cout << BFS() << endl;
  }
 
  return 0;
}

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

signed main() {
	int N, Q; cin >> N >> Q;
	dsu d(N);
	for (int _ = 0; _ < Q; _++) {
		int t, u, v; cin >> t >> u >> v;
		if (t == 0) {
			d.merge(u, v);
		}
		else {
			if (d.same(u, v)) {
				cout << 1 << endl;
			}
			else {
				cout << 0 << endl;
			}
		}
	}
	return 0;
}


Measured memory_bytes: 4056
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>

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

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;

const int INF = 1 << 30;
const long long INFL = 1LL << 60;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100;

int main() {
	int n;cin>>n;
	int ans=0;
	rep(i,n) {
		int l,r;cin>>l>>r;
		ans+=r-l+1;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
 
using namespace std;
 
#define PB push_back
#define MP make_pairA
#define REP(i,n) for(int i=0;i<(n);i++)
int main()
{
    int a,b;
    cin>>a>>b;
    cout<<max(a+b,max(a-b,a*b))<<endl;
}

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

using namespace std;

const int MX = 100000;

vector<int> G[MX];
int vis[MX];

int dfs(int v, int p = -1) {
	vis[v] = 1;
	int cnt = 0;
	for (int u : G[v]) {
		if (u == p) continue;
		if (vis[u] == 1) {
			printf("%d %d\n", v + 1, u + 1);
			cnt ^= 1;
		}
		else if (vis[u] == 0) {
			cnt ^= dfs(u, v);
		}
	}
	
	vis[v] = 2;
	
	if (cnt == 0) {
		if (p != -1) printf("%d %d\n", p + 1, v + 1);
		return 1;
	}
	else {
		if (p != -1) printf("%d %d\n", v + 1, p + 1);
		return 0;
	}
}

int main() {
	int n, m;
	ignore = scanf("%d %d", &n, &m);
	
	if (m % 2 == 1) {
		printf("%d\n", -1);
		return 0;
	}
	
	for (int i = 0, u, v; i < m; i++) {
		ignore = scanf("%d %d", &u, &v);
		u--; v--;
		G[u].emplace_back(v);
		G[v].emplace_back(u);
	}
	
	dfs(0);
	
	return 0;
}


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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<ll, ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;

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

	double w,h,x,y;
	cin >> w >> h >> x >> y;
	cout << w * h / 2 << " ";
	if(w/2==x && h/2==y){
		cout << 1 << endl;
	} else cout << 0 << endl;
	return 0;
}


Measured memory_bytes: 3816
#include <iostream>
#include <cmath>
#include <stack>
using namespace std;

int main() {
	int n;
	while (cin >> n) {
		stack<int> s;
		for (int i = 9; i >= 0; i--) {
			if (n >= pow(2, i)) {
				n -= pow(2, i);
				s.push(pow(2, i));
			}
		}

		while (!s.empty()) {
			cout << s.top();
			s.pop();

			if (s.size() != 0) {
				cout << " ";
				continue;
			}
			cout << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3124
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			// 整数の入力
			long n = sc.nextLong();
			// 文字列の入力
			String s = sc.next();
			String t = sc.next();

			StringBuilder sb = new StringBuilder();
			for (int i = 0; i < n; i++) {
				sb.append(s.charAt(i));
				sb.append(t.charAt(i));
			}

			// 出力(整数)
			System.out.println(sb);
		}
	}
}


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int H,W;
int A[80][80];

bitset<160*176> B[80][80];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>H>>W;
	FOR(y,H) FOR(x,W) cin>>A[y][x];
	FOR(y,H) FOR(x,W) {
		cin>>r;
		A[y][x]=abs(A[y][x]-r);
	}
	B[0][0][80*165+A[0][0]]=1;
	FOR(y,H) FOR(x,W) {
		if(y+1<H) {
			B[y+1][x] |= B[y][x]<<A[y+1][x];
			B[y+1][x] |= B[y][x]>>A[y+1][x];
		}
		if(x+1<W) {
			B[y][x+1] |= B[y][x]<<A[y][x+1];
			B[y][x+1] |= B[y][x]>>A[y][x+1];
		}
	}
	
	int mi=101010;
	FOR(i,160*176) if(B[H-1][W-1][i]) mi=min(mi,abs(i-80*165));
	cout<<mi<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 22272
N,A,B = map(int, input().split())

X = list(map(int, input().split()))

ans = 0
for i in range(1,N):
    if (X[i] - X[i-1]) * A <= B:
        ans += (X[i] - X[i-1]) * A
    else:
        ans += B
print(ans)

Measured memory_bytes: 15020
// -----------------------------------
// Author     : MatsuTaku
// Country    : Japan
// Created    : 05/10/20 23:28:18
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

  string s,t; cin>>s>>t;
  cout << (s == t.substr(0, t.size()-1) ? "Yes" : "No") << endl;

  return 0;
}


Measured memory_bytes: 3616
#include <cstdio>
#include <iostream>
#include <utility>
#include <algorithm>
#include <vector>

using namespace std;

int main(void) {
  int n;
  scanf("%d", &n);
  int t[n + 1];

  for(int i = 1; i <= n; i++) {
    scanf("%d", &t[i]);
  }

  int m;
  scanf("%d", &m);
  vector< pair <int, int> > px;
  px.push_back(pair<int, int>(0, 0));

  for(int i = 0; i < m; i++) {
    int p, x;
    scanf("%d %d", &p, &x);
    px.push_back(pair<int, int>(p, x));
  }

  for(int i = 1; i <= m; i++) {
    int sum = 0;
    for(int j = 1; j <= n; j++) {
      if(j == px[i].first) {
	sum += px[i].second;
      }
      else {
	sum += t[j];
      }
    }
    printf("%d\n", sum);
  }
}

Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let v = read_vec::<i64>();
    let (x, a, b) = (v[0], v[1], v[2]);
    if b <= a {
        println!("delicious");
        return;
    }
    if b > a + x {
        println!("dangerous");
    } else {
        println!("safe");
    }
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 4352
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <functional>
#include <climits>
#include <cstring>
#include <cmath>

using namespace std;

#define int long long
#define rep(i, n) for (int i=0;i<(int)n;++i)
#define rep1(i, n) for (int i=1;i<=(int)n;++i)
#define unless(a) if(!(a))
#define all(a) begin(a),end(a)
#define fst first
#define scd second
#define PB emplace_back
#define PPB pop_back

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

constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }
bool chmin(int&a,int b){return a>b?(a=b,true):false;}
bool chmax(int&a,int b){return a<b?(a=b,true):false;}
ll read(){ll a;scanf("%lld",&a);return a;}

const int inf = TEN(9) + 10;
const int mod = TEN(9) + 7;

int N;
int a[100010];
int cnt[100010];

ll inv[200010];
ll fac[200010], fac_inv[200010];

ll C(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return ((fac[n] * fac_inv[k] % mod) * fac_inv[n - k]) % mod;
}

void comb_init()
{
	int N = 200005;
	inv[1] = 1;

	for (int i = 2; i <= N; ++i) {
		inv[i] = mod - (mod / i) * inv[mod % i] % mod;
	}

	fac[0] = fac_inv[0] = 1;

	for (int i = 1; i <= N; ++i) {
		fac[i] = (fac[i - 1] * i) % mod;
		fac_inv[i] = (fac_inv[i - 1] * inv[i]) % mod;
	}
}


signed main()
{
	cin >> N;
	int L, R;
	rep(i, N + 1) {
		cin >> a[i];
		if (cnt[a[i]] != 0) {
			L = cnt[a[i]];
			R = i + 1;
		}
		cnt[a[i]] = i + 1;;
	}

	int M = R - L - 1;

	comb_init();

	rep1(K, N + 1) {
		int ans = 0;

		if (N - 1 >= K) {
			ans += C(N - 1, K);
			ans %= mod;
		}

		if (N - 1 >= K - 1) {
			ans += 2 * C(N - 1, K - 1);
			ans %= mod;
		}

		if (N - 1 - M >= K - 1) {
			ans += mod - C(N - 1 - M, K - 1);
			ans %= mod;
		}

		if (K - 2 >= 0) {
			ans += C(N - 1, K - 2);
			ans %= mod;
		}

		printf("%lld\n", ans);
	}
}




Measured memory_bytes: 7424
A = int(input())
B = int(input())
C = int(input())
X = int(input())
count = 0

for i in range(min(int(X/500)+1, A+1)):
    for n in range(min(int((X-500*i)/100)+1, B+1)):
        if C >= int((X-500*i-100*n)/50):
            count += 1
    

print(count)

Measured memory_bytes: 3064
<?php
fscanf(STDIN, "%s", $str);

$len = strlen($str);
$a_count = substr_count($str, 'a');
$b_count = substr_count($str, 'b');
$c_count = substr_count($str, 'c');

$arr = [$a_count, $b_count, $c_count];
sort($arr);

$max = sprintf("%d", $len / 3);
$mid = sprintf("%d", $len / 3);
$min = sprintf("%d", $len / 3);

if (0 == $len % 3) {
} elseif ($len % 3 == 1) {
	$max++;
} else {
	$max++;
	$mid ++;
}

if ($arr[2] <= $max
	and $arr[1] <= $mid
	and $arr[0] <= $min) {
	echo 'YES';
} else {
	echo 'NO';
}

Measured memory_bytes: 4604
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define pll pair<ll,ll>
#define pii pair<int,int>
#define rep(i,n) for(int i=0;i<n;i++)
#define For(i,a,b) for(int i=a;i<b;i++)
#define sz(x) ((ll)(x).size())
#define pb push_back
#define mp make_pair
#define bit(n) (1LL<<(n))
#define F first
#define S second
#define debug(x) cerr << x << endl
#define Complex complex<double>
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const ll INF = 1LL<<60;
const ll mod = (int)1e9 + 7;

int main() {
    ll x,y,a,b,c;
    cin >> x >> y >> a >> b >> c;
    vector<ll> p(a);
    vector<ll> q(b);
    vector<ll> r(c);
    rep(i,a)cin >> p[i];
    rep(i,b)cin >> q[i];
    rep(i,c)cin >> r[i];
    sort(all(p));
    sort(all(q));
    sort(all(r));
    ll sum=0;
    priority_queue<ll,vector<ll>,greater<ll>> que;
    rep(i,x){
        sum+=p[a-i-1];
        que.push(p[a-i-1]);
    }
    rep(i,y){
        sum+=q[b-i-1];
        que.push(q[b-i-1]);
    }
    int now=c-1;
    while(now>=0){
        if(r[now]<=que.top())break;
        else{
            sum+=r[now]-que.top();
            que.pop();
            now--;
        }
    }
	cout << sum;


}

/*



 */



Measured memory_bytes: 4724
#include<iostream>
#include<algorithm>
using namespace std;
#define null (-1)
#define Max 25
struct binary_tree{int parent;int left;int right;};
void pre_tree_walk(binary_tree a[],int i){

	if(i==null)
	return ;
	printf(" %d",i);
	pre_tree_walk(a,a[i].left);
	pre_tree_walk(a,a[i].right);
}
void in_tree_walk(binary_tree a[],int i){
if(i==null)
	return ;
	in_tree_walk(a,a[i].left);
	printf(" %d",i);
	in_tree_walk(a,a[i].right);
}
void po_tree_walk(binary_tree a[],int i){

	if(i==null)
	 return ;
	po_tree_walk(a,a[i].left);
	po_tree_walk(a,a[i].right);
	printf(" %d",i);
}
main(){
	int id, lf,ri,i,n;
	binary_tree a[Max];
	scanf("%d",&n);
	for(i=0;i<n;i++)
	a[i].parent=null;
	for(i=0;i<n;i++){  
		scanf("%d %d %d",&id,&lf,&ri);
		a[id].left=lf; a[id].right=ri;
		a[lf].parent=id; a[ri].parent=id;
	}
	for(i=0;i<n;i++){
		if(a[i].parent==null)
		id=i;
	}
	
	printf("Preorder\n");
	pre_tree_walk(a,id);
	printf("\n");
	printf("Inorder\n");
	in_tree_walk(a,id);
	printf("\n");
	printf("Postorder\n");
	po_tree_walk(a,id);
	printf("\n");
	return 0;
}



Measured memory_bytes: 3228
#include <bits/stdc++.h>
#define maxN 100005
 
long dp[maxN] = {INT_MAX};
long input[maxN] = {0};
 
int main() {
  int n;
  std::cin>>n;
  for(int i =0; i < n;i++) {
  	std::cin>>input[i];
  	dp[i] = INT_MAX;
  }
  dp[0] = 0;
  for(int i = 0; i < n; i++) {
    for(int j =1; j <=2;j++) {
      dp[i + j] = std::min(dp[i] + std::abs(input[i] - input[i+j]), dp[i+j]);
    }
  }
  std::cout << dp[n-1] << std::endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int N,ans,i,j,k;
typedef pair<long,long> P;
vector<P> l;

signed main(){
    cin>>N;
    map<long,long> m;
    while(N--){cin>>i;m[i]++;}
    for(auto p:m)l.push_back(p);
    for(i=0;i<l.size();i++){
        ans += l[i].second*(l[i].second-1)*(l[i].second-2)/6;
        for(j=0;j<i;j++){
            if(l[j].first * 2 > l[i].first)ans += l[i].second*l[j].second*(l[j].second-1)/2;
            ans += l[j].second*l[i].second*(l[i].second-1)/2;
            for(k=0;k<j;k++){
                if(l[j].first+l[k].first>l[i].first)ans+=l[i].second*l[j].second*l[k].second;
            }
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>

#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef long long int lli;
using namespace std;

signed main() {
    int N, Q;
    cin >> N >> Q;
    string S;
    cin >> S;

    vector<int> sumAC(N, 0);
    for (int i = 1; i < N; i++) {
        sumAC[i] += sumAC[i - 1];
        if (S[i - 1] == 'A' && S[i] == 'C') {
            sumAC[i] += 1;
        }
    }

    while(Q > 0) {
        int l, r;
        cin >> l >> r;
        cout << sumAC[r - 1] - sumAC[l - 1] << endl;
        Q--;
    }
}


Measured memory_bytes: 1472
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <iomanip>

#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
const int inf = 1e9;
const ll linf = 1LL << 50;

int d, n;
int t[201];
int a[201], b[201], c[201];
int dp[201][201];

int main(int argc, char const* argv[])
{
	cin >> d >> n;
	for(int i = 0; i < d; i++)cin >> t[i];
	for(int i = 0; i < n; i++)cin >> a[i] >> b[i] >> c[i];
	for(int i = 0; i < d - 1; i++){
			for(int j = 0; j < n; j++){
					if(a[j] > t[i] || b[j] < t[i])continue;
					for(int k = 0; k < n; k++){
							if(a[k] > t[i+1] || b[k] < t[i+1])continue;
							dp[i+1][k] = max(dp[i+1][k], dp[i][j] + abs(c[j] - c[k]));
					}
			}
	}
	int res = 0;
	for(int i = 0; i < n; i++){
			res = max(res, dp[d-1][i]);
	}
	cout << res << endl;
	return 0;
}



Measured memory_bytes: 3256
/*
   AOJ 2400
   Your Are the Judge
   2015/7/14
*/

#include<stdio.h>
#define TEAM_MAX 51

struct team
{
  int correct, penalty, tid;
  int wrong_prob[11];
};

int team_num, prob_num, log_num;


void sort(struct team *table)
{
  int i, j;
  struct team tmp;
  for(i = 1; i <= team_num; i++)
    {
      for(j = team_num; j > i; j--)
	{
	  if(table[j - 1].correct < table[j].correct)
	    {
	      tmp = table[j - 1];
	      table[j - 1] = table[j];
	      table[j] = tmp;
	    }
	  if(table[j - 1].correct == table[j].correct)
	    {
	      if(table[j - 1].penalty > table[j].penalty)
		{
		  tmp = table[j - 1];
		  table[j - 1] = table[j];
		  table[j] = tmp;
		}
	      if(table[j - 1].penalty == table[j].penalty)
		{
		  if(table[j - 1].tid > table[j].tid)
		    {
		      tmp = table[j - 1];
		      table[j - 1] = table[j];
		      table[j] = tmp;
		    }
		}
	    }
	}
    }
}

void print_ans()
{
  int tid, pid, time, i, j, max = -1, max_team = 0;
  char message[10];

  struct team table[51];

  for(i = 1; i <= team_num; i++)
    {
      table[i].correct = 0;
      table[i].penalty = 0;
      table[i].tid = i;
      for(j = 1; j <= prob_num; j++)
	{
	  table[i].wrong_prob[j] = 0;
	}
    }
  //input---------------------------------------
  for(i = 0; i < log_num; i++)
    {
      scanf("%d %d %d %s", &tid, &pid, &time, message);
      if(message[0] == 'C')
	{
	  table[tid].correct++;
	  table[tid].penalty += table[tid].wrong_prob[pid] * 1200 + time;
	  table[tid].wrong_prob[pid] = 0;
	}
      else
	{
	  table[tid].wrong_prob[pid]++;
	}
    }
  //for a debug---------------------------------
  /* for(i = 1; i <= team_num; i++) */
  /*   { */
  /*     printf("%3d", table[i].tid); */
  /*   } */
  /* printf("\n"); */
  //--------------------------------------------
  sort(table);

  for(i = 1; i <= team_num; i++)
    {
      printf("%d %d %d\n", table[i].tid, table[i].correct, table[i].penalty);
    }
}

int main(void)
{
  int tid, pid, time, i;
  char message[10];
  while(1)
    {
      scanf("%d %d %d", &team_num, &prob_num, &log_num);
      if(team_num == 0 && prob_num == 0 && log_num == 0)
	{
	  break;
	}
      
      print_ans();
    }
  return 0;
}

Measured memory_bytes: 608
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>

using namespace std;

struct Edge {
    int source, to, cost;
    bool operator<(const Edge& o) const {
        return cost < o.cost;
    }
};

const int SIZE = 100000;

struct UnionFind {
    int gid[SIZE], rank[SIZE];
    int groups;

    void init(int n) {
        for (int i = 0; i < n; ++i) {
            gid[i] = i;
            rank[i] = 0;
        }
        groups = n;
    }

    int find(int x) {
        if (gid[x] == x) {
            return x;
        }
        return gid[x] = find(gid[x]);
    }

    bool equals(int a, int b) {
        return find(a) == find(b);
    }

    int merge(int x, int y) {
        int rx = find(x);
        int ry = find(y);
        if (rx != ry) {
            if (rank[rx] < rank[ry]) {
                gid[rx] = ry;
            } else {
                gid[ry] = rx;
            }
            groups--;
        }
        return groups;
    }
};

const int MAX_V = 10000;
const int INF = 1 << 28;

int V, E;
bool done[MAX_V];

int main() {
    cin >> V >> E;
    Edge edges[E];
    for (int i = 0; i < E; ++i) {
        int s, t, w;
        cin >> s >> t >> w;
        edges[i] = (Edge) { s, t, w };
    }
    sort(edges, edges + E);
    UnionFind uf = UnionFind();
    uf.init(V);
    int costSum = 0;
    for (Edge e: edges) {
        if (uf.equals(e.source, e.to)) {
            continue;
        }
        costSum += e.cost;
        if (uf.merge(e.source, e.to) == 1) {
            break;
        }
    }

    cout << costSum << endl;
}

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

typedef long long ll;
ll a, b, c, d, ans;

ll f(ll p, ll q) {
	if (q == 0) return p;
	return f(q, p % q);
}

int main()
{
	ll t;
	cin >> a >> b >> c >> d;
	a--;
	ans = b / c - a / c + b / d - a / d;
	t = f(c, d);
	t = c / t * d;
	ans -= b / t - a / t;
    cout << b - a - ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <deque>
#include <algorithm>

using namespace std;

typedef long long ll;

ll N,W;
deque<ll> values[4];
ll w[100];
ll v[100];

int main(){
    ll max_v = 0;
    cin >> N >> W;
    ll min_w;
    min_w = 1e10;
    for(int i=0;i<N;i++){
        cin >> w[i] >> v[i];
        min_w = min(min_w,w[i]);
    }
    for(int i=0;i<N;i++){
        values[w[i]-min_w].push_back(v[i]);
    }
    for(int i=0;i<4;i++){
        sort(values[i].begin(),values[i].end(),greater<ll>());
        values[i].push_front(0);
        for(int j=1;j<values[i].size();j++) values[i][j] += values[i][j-1];
    }
    for(int a=0;a<values[0].size();a++){
        for(int b=0;b<values[1].size();b++){
            for(int c=0;c<values[2].size();c++){
                for(int d=0;d<values[3].size();d++){
                    ll sum_v = values[0][a] + values[1][b] + values[2][c] + values[3][d];
                    ll sum_w = a*min_w + b*(min_w+1) + c*(min_w+2) + d*(min_w+3);
                    if(W < sum_w) break;
                    max_v = max(max_v,sum_v);
                }
            }
        }
    }
    cout << max_v << endl;
    return 0;
}

Measured memory_bytes: 256
while 1:
    n=int(input())
    if n==0:break
    s=list(input())
    c=[list(map(int,input().split())) for _ in range(n)]
    for i,j in c[::-1]:
        d,i,j=j-i,i-1,j-1
        s[i],s[j]=chr((ord(s[j])-97+d)%26+97),chr((ord(s[i])-97+d)%26+97)
    print("".join(s))

Measured memory_bytes: 7676
#include<algorithm>
#include<iostream>
#include<string>
#include<cmath>
using namespace std;
int main()
{
	int n,m,ans=0;
	char a[2001][2001],b;
	cin>>n>>m;
	for(int i=0;i<n;i++)for(int j=0;j<m;j++)cin>>a[i][j];
	for(int i=0;i<n;i++)for(int j=0;j<m;j++)
	{
		cin>>b;
		if(a[i][j]!=b)ans++;
	}
	cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 7012
/*
 * Author   :   jignesh16
 * College  :   SVNIT
 */


#include<bits/stdc++.h>
using namespace std;
#define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

#define pb push_back
#define sz size()
#define ff first
#define ss second
#define ll long long int
#define ld long double
#define bp __builtin_popcountll
#define FOR(i,a,b) for(i=a;i<b;i++)
#define ROR(i,a,b) for(i=a;i>b;i--)
#define FORE(i,a,b) for(i=a;i<=b;i++)
#define RORE(i,a,b) for(i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
const int M=1e9+7;

int main()
{
    FAST;
    int n,i,j,k;
    cin>>n;
    int a[n];
    long long int c=0;
    for(i=0;i<n;i++)    cin>>a[i];
    sort(a , a+n);
    for(i=0;i<n;i++)
    {
        for(j=i+1;j<n;j++)
        {
            for(k=j+1;k<n;k++)
            {
                if(a[i]+a[j]>a[k])
                    c++;
                else
                    break;
            }
        }
    }
    cout<<c<<"\n";
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using System.Runtime.CompilerServices;
using static MyUtil;

class MyUtil
{
    public static int[] ReadIntArray()
    {
        return ReadLine().Split().Select(x => int.Parse(x)).ToArray();
    }
}

class Program
{
    public static void Main()
    {
        var tmp = ReadIntArray();
        int a = tmp[0], b = tmp[1], c = tmp[2], d = tmp[3];

        int ab = Math.Abs(b - a);
        int bc = Math.Abs(c - b);
        int ac = Math.Abs(c - a);

        if ((ac <= d) || (ab <= d && bc <= d))
        {
            WriteLine("Yes");
        }
        else
        {
            WriteLine("No");
        }
    }
}


Measured memory_bytes: 13268