akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }
#define INF 1LL<<60

int main() {
    ll a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;

    ll ans = INF;
    // i: A, j: Bの枚数
    // for(ll i=0; i<=x; ++i)
    //     for(ll j=0; j<=y; ++j) {
    //         ll k = max(2 * (x - i), 2 * (y - j));
    //         ll tmp = a * i + b * j + c * k;
    //         if(tmp < ans) ans = tmp;
    //     }

    for(ll k = 0; k <= max(2 * x, 2 * y); ++k) {
        ll i = max(x - k / 2, 0ll);
        ll j = max(y - k / 2, 0ll);
        ll tmp = a * i + b * j + c * k;
        if(tmp < ans) ans = tmp;
    }

    cout << ans << endl;
    return 0;
}

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

using namespace std;

int main()
{
    vector<vector<char>> vec;
    vector<char> tmp;
    char in;

    tmp = {};
    for (int i = 0; i < 3; i++)
    {
        cin >> in;
        tmp.push_back(in);
    }
    vec.push_back(tmp);

    tmp = {};
    for (int i = 0; i < 3; i++)
    {
        cin >> in;
        tmp.push_back(in);
    }
    vec.push_back(tmp);

    for (int i = 0; i < 2; i++)
    {
        for (int j = 0; j < 3; j++)
        {
            if (vec[1 - i][2 - j] != vec[i][j])
            {
                cout << "NO" << endl;
                return 0;
            }
        }
    }

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

Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define MAX 2000000

int H,A[MAX+1];

void maxHeapify(int i){
	int l,r,largest;
	l=2*i;
	r=l+1;
	
	if(l<=H&&A[l]>A[i]) largest=l;
	else largest=i;
	if(r<=H&&A[r]>A[largest]) largest=r;
	
	if(largest!=i){
		swap(A[i],A[largest]);
		maxHeapify(largest);
	}
}

int main(){
	cin>>H;
	
	for(int i=1;i<=H;i++) cin>>A[i];
	
	for(int i=H/2;i>=1;i--) maxHeapify(i);
	
	for(int i=1;i<=H;i++) cout<<" "<<A[i];
	cout<<endl;
	
	return 0;
}



Measured memory_bytes: 5060
def line(s):
    ret = [0] * len(s)
    for i in range(len(s)):
        ret[i] = 0 if s[i] == 'W' else 1

    return ret

def count(arr):
    c = 0
    for i in range(len(arr)-1):
        if arr[i+1] != arr[i]:
            c += 1
    return c

if __name__ == '__main__':
    s = raw_input()
    arr = line(s)
    print(count(arr))


Measured memory_bytes: 6660
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)

typedef long long ll;

int vs[110];

int main(void) {
  int n;
  scanf("%d", &n);
  REP(i, n) {
    scanf("%d", &vs[i]);
  }
  int res = -1;
  REP(i, n) {
    REP(j, i) {
      res = max(res, abs(vs[i] - vs[j]));
    }
  }
  cout << res << endl;
  
  return 0;
}


Measured memory_bytes: 256
N = int(input())
a = list(map(int,input().split()))
l = []
sum =0
for i in range(N-1):
    sum += a[i]
sum = sum - a[N-1]
ans = abs(sum)

for i in range(N-2,0,-1):
    sum = sum - 2*a[i]
    ans = min(ans,abs(sum))
print(ans)


Measured memory_bytes: 24832
# coding: utf-8
# Your code here!

#import sys

#def input():
#    return sys.stdin.readline().rstrip()

N, M = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(N)]
a.sort()
price = [a[i][0] for i in range(N)]
stock = [a[i][1] for i in range(N)]
bought = 0
total_price = 0

for i in range(N):
    if bought + stock[i] <= M:
        total_price += price[i] * stock[i]
        bought += stock[i]
    else:
        total_price += price[i] * (M - bought)
        break
print(total_price)

Measured memory_bytes: 67416
#include<iostream>
using namespace std;
 
int main()
{
  int A,B,C;
  cin >> A >> B >> C ;
  if(A<B){
    if( B<C || A>C){
      cout <<"No"<<endl;
    }else{
      cout<<"Yes"<<endl;
    }
  }else{
    if(B>C||A<C){
      cout <<"No"<<endl;
    }else{
      cout<<"Yes"<<endl;
    }
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#define rep(i,l,r) for(int i = l; i < r; ++i)
#define ll long long
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<bool> d(n, false);
    rep(i, 0, n) {
        int a, b;
        cin >> a >> b;
        if(a==b) d.at(i) = true;
    }

    rep(i, 2, n) {
        if(d[i] && d[i-1] && d[i-2]) {
            cout << "Yes" << endl;
            return 0;
        }
    }

    cout << "No" << endl;
}


Measured memory_bytes: 3628
#include<stdio.h>
main(){
int W,H,x,y,r=0;
scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
if(x-r>=0&&x+r<=W&&y-r>=0&&y+r<=H)
printf("Yes\n");
else 
printf("No\n");
return 0;
}

Measured memory_bytes: 1812
# coding=utf-8


def cross_product(vect1, vect2):
    return vect1[0]*vect2[1] - vect1[1]*vect2[0]


def vector_plus(vect1, vect2):
    return [el1 + el2 for el1, el2 in zip(vect1, vect2)]


def vector_minus(vect1, vect2):
    return [el1 - el2 for el1, el2 in zip(vect1, vect2)]


def vector_product(vect1, vect2):
    return [el1 * el2 for el1, el2 in zip(vect1, vect2)]


def vector_divide(vect1, vect2):
    return [el1 / el2 for el1, el2 in zip(vect1, vect2)]


def which_place(origin, line_to1, line_to2):
    line1 = vector_minus(line_to1, origin)
    line2 = vector_minus(line_to2, origin)
    judge = cross_product(line1, line2)

    if judge > 0:
        return "COUNTER_CLOCKWISE"
    if judge < 0:
        return "CLOCKWISE"
    if judge == 0:
        try:
            judge2 = line2[0]/line1[0]
        except ZeroDivisionError:
            judge2 = line2[1]/line1[1]
        
        if judge2 < 0:
            return "ONLINE_BACK"
        if judge2 > 1:
            return "ONLINE_FRONT"
        else:
            return "ON_SEGMENT"


if __name__ == '__main__':
    xy_list = list(map(int, input().split()))
    p0_list = xy_list[:2]
    p1_list = xy_list[2:]
    Q = int(input())

    for i in range(Q):
        p2_list = list(map(int, input().split()))
        place = which_place(p0_list, p1_list, p2_list)
        print(place)



Measured memory_bytes: 5628
#include <bits/stdc++.h>
#include <cassert>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ok() puts(ok?"Yes":"No");
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using ii = pair<int, int>;
using vvi = vector<vi>;
using vii = vector<ii>;
using gt = greater<int>;
using minq = priority_queue<int, vector<int>, gt>;
using P = pair<ll,ll>;
const ll LINF = 1e18L + 1;
const int INF = 1e9 + 1;
//clang++ -std=c++11 -stdlib=libc++ 

int main() {
  int N; cin >> N;
  vll A(N);
  rep(i,N) cin >> A[i];
  ll sum = 0;
  ll mn=LINF;
  rep(i, N) {
    sum += abs(A[i]);
    chmin(mn, abs(A[i]));
  }
  rep(i,N-1) {
    if (A[i] < 0) {
      A[i] *= -1;
      A[i+1] *= -1;
    }
  }
  if (A[N-1] < 0) {
    sum-=2*abs(mn);
  }
  printf("%lld\n", sum);
  return 0;
}

Measured memory_bytes: 4012
#include <stdio.h>
#include <math.h>

double dis(int x1,int y1,int x2,int y2){
  x1-=x2;
  y1-=y2;
  return sqrt((double)(x1*x1+y1*y1));
}

int main(){
  int N;
  int x[10],y[10];
  double d=0.0;
  scanf("%d",&N);
  for(int i=1;i<=N;i++)
    scanf("%d %d",x+i,y+i);
  for(int i=1;i<=N;i++){
    for(int j=1;j<=N;j++){
      d+=dis(x[i],y[i],x[j],y[j])/N;
    }
  }
  printf("%.8lf",d);
  return 0;
}

Measured memory_bytes: 2200
num = int(input())
ls = [ x for x in map(int, input().split(' ')) ]
answer = -1
for i in range(1, len(ls)):
    left = sum(ls[i:])
    right = sum(ls[:i])
    div = abs(left - right)
    if answer == -1:
        answer = div
    elif answer > div:
        answer = div
print(answer)

Measured memory_bytes: 3060
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception{
		new Main(new Scanner(System.in), System.out, System.err).exec();
	}
	public final Scanner sc;
	public final PrintStream out, err;
	public Main(final Scanner sc, final PrintStream out, final PrintStream err) {
		this.sc = sc;this.out = out;this.err = err;
	}
	static public final long pair(int a, int b) {return (((long)a) << 32) + b;}
	static public final int getPair1(long v) {return (int)(v >> 32);}
	static public final int getPari2(long v) {return (int)(v & 0xFFFFFFFF);}

	static public final long quad(long a, long b, long c, long d) {
		return ((a&0xFFFF)<< 48) + ((b&0xFFFF)<< 32) + ((c&0xFFFF)<< 16) +(d&0xFFFF);}
	static public final int getQuad1(long v) {return (int)( v >> 48          );}
	static public final int getQuad2(long v) {return (int)((v >> 32) & 0xFFFF);}
	static public final int getQuad3(long v) {return (int)((v >> 16) & 0xFFFF);}
	static public final int getQuad4(long v) {return (int)( v        & 0xFFFF);}

	static public final long record(int e, int m, int i) {
		return quad(-1, e, m, i);
	}
	static public final int re(long record) {
		return getQuad2(record);
	}
	static public final int rm(long record) {
		return getQuad3(record);
	}
	static public final int ri(long record) {
		return getQuad4(record);
	}

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

	private int p;
	private int[] inv;
	private int[] fact;
	private int[] finv;
	public final int mod(long v) {
		v %= p;
		return (int)(v < 0 ? v+p : v);
	}
	public final int mul(long a, long b) {
		return mod(a*b);
	}
	public final void initFact(double limit, double p) {
		initFact((int)limit, (int)p);
	}
	public final void initFact(int limit, int p) {
		this.p = p;
		this.inv = new int[limit+1];
		this.fact = new int[limit+1];
		this.finv = new int[limit+1];
		fact[1] = finv[1] = inv[0] = inv[1] = 1;
		for(int i=2;i<=limit;i++) {
			int a = p / i;
			int b = p % i;
			inv[i]  = mul(-a, inv[b]);
			fact[i] = mul(fact[i-1], i);
			finv[i] = mul(finv[i-1], inv[i]);
		}
	}
	public final int comb(int m, int n) {
		return mul(mul(fact[m], finv[n]), finv[m-n]);
	}

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

	public void exec() throws Exception{
		final int X = sc.nextInt();
		final int N = X / 100;
		final int mod = X % 100;

		if(mod <= N * 5) {
			out.println(1);
		}else {
			out.println(0);
		}

	}
}


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

#define rep(i,a,n)     for(int i=a;i<n;i++)
#define rep3(n)        for(int i=0;i<n;i++)
#define ll             long long
#define int            long long
#define pb             push_back
#define all(v)         v.begin(),v.end()
#define endl           "\n"
#define eb             emplace_back
#define x              first
#define y              second
#define gcd(a,b)       __gcd(a,b)
#define mem1(a)        memset(a,-1,sizeof(a))
#define mem0(a)        memset(a,0,sizeof(a))
#define pres(a,x)      a.find(x)!=a.end()
#define sz(a)          (int)a.size()
#define pii            pair<int,int>
#define hell           1000000007
#define elasped_time   1.0 * clock() / CLOCKS_PER_SEC
using namespace std;


template<typename T1,typename T2>istream& operator>>(istream& in,pair<T1,T2> &a){in>>a.x>>a.y;return in;}
template<typename T1,typename T2>ostream& operator<<(ostream& out,pair<T1,T2> a){out<<a.x<<" "<<a.y;return out;}
template<typename T,typename T1>T maxs(T &a,T1 b){if(b>a)a=b;return a;}
template<typename T,typename T1>T mins(T &a,T1 b){if(b<a)a=b;return a;}


int solve(){
 	int l,r,d;cin>>l>>r>>d;
 	cout<<r/d-(l-1)/d<<endl;
 return 0;
}
signed main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    #ifdef SIEVE
    sieve();
    #endif
    #ifdef NCR
    init();
    #endif
    int t=1;//cin>>t;
    while(t--){
        solve();
    }
    return 0;
}
 

Measured memory_bytes: 3576
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int, int> pr;
typedef vector<ll> vll;
typedef vector<vector<int>> vv;
typedef vector<vector<ll>> vvll;
const ll inf = 1e16;
const ll md = 1000000007;

int main() {
  int n,x,mn=10000;
  cin>>n>>x;
  rep(i,n){
    int m;
    cin>>m;
    x-=m;
    mn=min(mn,m);
  }
  n+=x/mn;
  cout<<n<<endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Map.Entry;
import java.io.*;
import java.util.*;

public class Main {
	static String p = "AKIHABARA";
	static String S = "";
	static String ans = "NO";
	
	public static void main(String[] args) throws IOException {
		FastScanner sc = new FastScanner(System.in);
		
		S = sc.next();
		dfs(0, "");
		System.out.println(ans);
	}
	
	static void dfs(int index, String s){
		if(index == p.length()){
			if(s.equals(S)) ans = "YES";
		}else{
			if(p.charAt(index) == 'A') dfs(index+1, s);
			dfs(index+1, s + p.charAt(index));
		}
	}
}

class FastScanner {
    private InputStream in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    public FastScanner(InputStream in) {
		this.in = in;
	}
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() {
    	if (hasNextByte()) return buffer[ptr++];
    	else return -1;
    }
    private static boolean isPrintableChar(int c){
    	return 33 <= c && c <= 126;
    }
    public boolean hasNext() {
    	while(hasNextByte() && !isPrintableChar(buffer[ptr]))
    		ptr++; return hasNextByte();
    }
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() {
    	return Double.parseDouble(next());
    }
}


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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define TR(X) ({ if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	deque<char> res;
	bool flip = false;

	string s; cin >> s;
	for (char c: s) res.push_back(c);
	
	ll q; cin >> q;
	while (q--) {
		ll t; cin >> t;
		if (t == 1) {
			flip = !flip;
		} else {
			ll f; cin >> f;
			char c; cin >> c;
			if ((f == 2) != flip) res.push_back(c);
			else res.push_front(c);
		}
	}
	
	if (flip) reverse(all(res));
	for (char c: res) cout << c;
	cout << endl;

}



Measured memory_bytes: 976
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<map>
#include<set>
#include<functional>
#include<queue>
#define int long long
using namespace std;

signed main() {
	int a; cin >> a;
	string b; cin >> b;
	int c = 0, d = 0;
	int sum = 0;
	for (char S : b) {
		if (S == '(') {
			sum++;
		}
		else {
			if (sum) {
				sum--;
			}
			else {
				c++;
			}
		}
	}
	sum = 0;
	reverse(b.begin(), b.end());
	for (char S : b) {
		if (S == ')') {
			sum++;
		}
		else {
			if (sum) {
				sum--;
			}
			else {
				d++;
			}
		}
	}
	reverse(b.begin(), b.end());
	for (int i = 0; i < c; i++) {
		cout << '(';
	}
	cout << b;
	for (int i = 0; i < d; i++) {
		cout << ')';
	}
	cout << endl;
}

Measured memory_bytes: 256
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;

int main(){
	int wan, n, winner;
	while(cin>>n>>wan, wan||n){
		int cnd[50]={0};
		for(int i = 0;;i=(i+1)%n){
			if(wan>0){
				wan--,cnd[i]++;
				if(wan==0){
					bool win=1;
					rep(j, n){
						if(i==j)continue;
						if(cnd[j]>0)win=0;
					}
					if(win){
						winner = i; break;
					}
				}
			}else wan+=cnd[i], cnd[i]=0;
		}
		cout<<winner<<endl;
	}
}

Measured memory_bytes: 868
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>

using namespace std;

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(v) v.begin(), v.end()
int main(){
  int N; cin >> N;
  string S; cin >> S;
  vector<int> turn(N, 0);
  int ans = N;
  rep(i, N) {
    if(S.at(i) == 'E'){
      turn.at(0)++;
    }
  }
  if(S.at(0) == 'E'){
    turn.at(0)--;
  } else {
    turn.at(1)++;
  }
  ans = turn.at(0);
  for(int i = 1; i < N-1; i++){
    if(S.at(i) == 'E'){
      turn.at(i) += turn.at(i-1)-1;
    } else {
      turn.at(i) += turn.at(i-1);
      turn.at(i+1)++;
    }
    ans = min(ans, turn.at(i));
  }
  if(S.at(N-1) == 'E') {
    turn.at(N-1) += turn.at(N-2)-1;
  } else {
    turn.at(N-1) += turn.at(N-2);
  }
  ans = min(ans, turn.at(N-1));
  cout << ans << endl;
 // rep(i, N) cout << turn.at(i) << endl;
  return 0;
}


Measured memory_bytes: 4796
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace AtCoder
{
    class Program
    {
        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

        static bool Solve(int N, string[] W)
        {
            var set = new HashSet<string>();
            char tail = W[0][0];
            foreach (string w in W)
            {
                if (set.Contains(w) || w[0] != tail) { return false; }
                set.Add(w);
                tail = w.Last();
            }
            return true;
        }
        static void Main(string[] args)
        {
            int N = ReadInt();
            var W = new string[N];
            for (int i = 0; i < N; ++i) { W[i] = Read(); }
            Console.WriteLine(Solve(N, W) ? "Yes" : "No");
        }
    }
}


Measured memory_bytes: 13280
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
using namespace std;

int main(){
    int N, X;
    cin >> N >> X;
    int m[N];
    int min_m = 1001;
    for(int i = 0; i < N; i++){
        cin >> m[i];
        X -= m[i];
        min_m = min(min_m, m[i]);
    }
    cout << N + X/min_m << endl;
    return 0;
}

Measured memory_bytes: 256
def d_water_bottle():
    import math
    A, B, X = [int(i) for i in input().split()]

    rad = 2 * (A**2 * B - X) / A**3 if X >= A**2 * B / 2 else A * B**2 / (2 * X)
    ans = math.atan(rad)
    return round(math.degrees(ans), 10)

print(d_water_bottle())

Measured memory_bytes: 3060
#pragma region Include/Defines
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <limits.h>
#include <vector>
#include <stdlib.h>
#include <algorithm>
#include <memory.h>
#include <string.h>
#include <math.h>
#include <string>
#include <algorithm>
#include <functional>
#include <cassert>
#include <map>
#include <set>
#include <iostream>
#include <queue>
#include <time.h>

using namespace std;
typedef long long lli;
typedef vector<int> vi;
typedef vector<lli> vli;
typedef pair<int, int> pii;
typedef pair<lli, lli> pll;
typedef vector<pii> vpii;
typedef vector <pll> vpll;
typedef long double ld;
#define all(a) std::begin(a), std::end(a)

const int INF = 0x3f3f3f3f;
const lli LINF = 0x3f3f3f3f3f3f3f3f;

template<typename T, typename T2> inline void _max(T &a, T2 b) { a = max((T)a, (T)b); }
template<typename T, typename T2> inline void _min(T &a, T2 b) { a = min((T)a, (T)b); }

#ifdef _DEBUG
#define epr(...) fprintf(stderr,__VA_ARGS__)
#else
#define epr(...) 
#endif
#pragma endregion

const int MAX = 55;
lli a[MAX], n;

void clear() {
}

void read() {
	for (int i = 0; i < n; i++) scanf("%lld", &a[i]);
}

void solve() {
	multiset<lli, greater<lli>> s;
	for (int i = 0; i < n; i++) s.insert(a[i]);
	lli k = 0;
	while (*s.begin() >= n) {
		lli t = *s.begin();
		multiset<lli, greater<lli>> ns;
		lli kol = t / n, rem = t % n;
		k += kol;
		ns.insert(rem);
		for (auto it = next(s.begin()); it != s.end(); it++)
			ns.insert(*it + kol);
		s = ns;
	}
	printf("%lld\n", k);
}

int main() {
#ifdef _LOCAL_VAN
	freopen("in.txt", "r", stdin);
#endif
	while (scanf("%d", &n) == 1) {
		clear();
		read();
		solve();
#ifndef _LOCAL_VAN
		return 0;
#endif
	}
	return 0;
}

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

int main() {
	// your code goes here
	string s;
	cin>>s;
	int m=1000000;
	for(int i=0;i<s.size()-2;i++)
	{
	    int k=(int )s[i]-48;
	    int k2=(int)s[i+1]-48;
	    int k3=(int)s[i+2]-48;
	    if(abs(k*100+k2*10+k3-753)<m)
	    {
	        m=abs(k*100+k2*10+k3-753);
	    }
	} 
	cout<<m<<endl;
	return 0;
}


Measured memory_bytes: 3580
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <functional>
#include <iostream>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <stack>
#include <string>
#include <vector>
 
using namespace std;
typedef long long ll;
using gra = vector<vector<ll>>;
using gram = vector<unordered_map<ll,ll>>;
 
typedef unsigned long long ull;
 
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; }
 
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template <class T> T dup(T a, T b) { return (a + b - 1) / b; }
template <class T> T modpow(T x, T p, T m) { T a=1; while(p){ if(p%2)a =a*x%m; x = x+x%m; p/=2; } return a; }
// template <class T> void prim(T a) { for(ll i=0;i<a.size();++i) { cout << a[i]; } cout << "\n"; }
 
#define mod 1000000007LL
#define INF 10000000000000000LL
 
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep1(i, n) for (ll i = 1; i <= n; ++i)
#define rrep(i, n) for (int i = (n - 1); i >= 0; --i)
#define rrep1(i, n) for (int i = n; i > 0; --i)
 
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
//#define modpow(x, p, m) { ll a=1; while(p){ if(p%2)a =a*x%m; x = x+x%m; p/=2; } return a; }
 
#define m0(h) memset(h, 0, sizeof(h))
#define m1(h) memset(h, 1, sizeof(h))
#define m(h, n) memset(h, (n), sizeof(h))
#define all(n) (n).begin(),(n).end()
#define bit(n) (1LL << (n))
#define pb push_back
 
//#ifdef LOCAL
//
//#define dpri(...) fprintf(stderr, __VA_ARGS__)
//#define pria(g) rep(i,g.size()){ cout << i << "{"; rep(j,g[i].size()) cout << g[i][j] << " "; cout << "}" << "\n"; }
//#else
//#define dpri(...) 42
//#define pria(g) 42
//#endif
 
 
 
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  // ---------------------
  // コーディング開始
  // ---------------------
  ll n,h;
  cin >> n;
  ll a=0;
  ll co =0;
  rep(i,n){
    cin >> h;
    if(a<=h){
      a=h;
      co++;
    }
  }
  pri(co);



  return 0;
}


Measured memory_bytes: 256
import functools

import os
import sys

sys.setrecursionlimit(10000)
INF = float('inf')


def inp():
    return int(input())


def inpf():
    return float(input())


def inps():
    return input()


def inl():
    return list(map(int, input().split()))


def inlf():
    return list(map(float, input().split()))


def inls():
    return input().split()


def inpm(line):
    return [inp() for _ in range(line)]


def inpfm(line):
    return [inpf() for _ in range(line)]


def inpsm(line):
    return [inps() for _ in range(line)]


def inlm(line):
    return [inl() for _ in range(line)]


def inlfm(line):
    return [inlf() for _ in range(line)]


def inlsm(line):
    return [inls() for _ in range(line)]


def Yesif(cond):
    print('Yes' if cond else 'No')


def YESIF(cond):
    print('YES' if cond else 'NO')


def yesif(cond):
    print('yes' if cond else 'no')


a, b, c = inpm(3)

print(int((a + b) / 2 * c))


Measured memory_bytes: 3572
/*
                   _ooOoo_
                  o8888888o
                  88" . "88　AC!AC!
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         pass System Test!
*/
#include <iostream>
#include <queue>
#include <vector>
#include <iostream>
#include <vector>
#include <string>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
#include <iomanip>
#include <utility>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rep3(var, min, max) for (ul (var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ul (var) = (max) - 1; (var) + 1 > (min); --(var))
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll MOD = 1e9 + 7;
//vector<ld> vec;
int main(){
    cin.tie(0);
   	ios::sync_with_stdio(false);
   	int n,k;
   	cin>>n>>k;
   	VV vec(n+1);
   	VP reg(k);
   	rep(i,k){
   	    int x,y;cin>>x>>y;
   	    vec[x].push_back(y);
   	    reg[i]=make_pair(x,y);
   	}
   	rep(i,n+1){
   	    sort(all(vec[i]));
   	}
   	rep(i,k){
   	    int x=lower_bound(all(vec[reg[i].first]),reg[i].second)-vec[reg[i].first].begin();
   	    x++;
   	    string s1=to_string(reg[i].first);
   	    string s2=to_string(x);
   	    rep(i,6-s1.size()){
   	        cout<<'0';
   	    }
   	    cout<<s1;
   	    rep(i,6-s2.size()){
   	        cout<<'0';
   	    }
   	    cout<<s2<<endl;
   	}
}
    


Measured memory_bytes: 8576
#include <bits/stdc++.h>
#define exrep(i, a, b) for(long long i = a; i <= b; i++)
#define rep(i,n)for(long long i=0;i<(long long)(n);i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
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; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const int MAX=510000;
const double pi=acos(-1);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
ll modpow(ll a, ll n){
  if(n==0)return 1;
  if(n%2==0){
    ll t=modpow(a,n/2);
    return t*t%MOD;
  }
  return a*modpow(a,n-1)%MOD;
}
ll modinv(ll a){
  return modpow(a,MOD-2);
}
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;
}
struct UnionFind {
    vector<int> par; // 親ノード
    vector<int> rank; // ランク
 
    UnionFind(int n = 1) {
        init(n);
    }
 
    void init(int n = 1) {
        par.resize(n); rank.resize(n);
        for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0;
    }
 
    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            return par[x] = r;
        }
    }
 
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
 
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y);
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        return true;
    }
};

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
  COMinit();
  
  ll n;
  cin >> n;
  vl a(n);
  rep(i,n)cin >> a[i];
  
  vvl cnt(n,vector<ll>(60,0));
  for(ll i=0;i<n-1;i++){
    rep(j,60){
      if(a[n-1-i]&(1ll<<j)){
        cnt[i+1][j]=cnt[i][j]+1;
        cnt[i+1][j]%=MOD;
      }
      else{
        cnt[i+1][j]=cnt[i][j];
        cnt[i+1][j]%=MOD;
      }
    }
  }
  ll ans=0;
  rep(i,n-1){
    rep(j,60){
        if(!((a[i]&(1ll<<j)))){
          ans+=((1ll<<j)%MOD)*cnt[n-1-i][j];
          ans%=MOD;
        }
        else{
          ans+=((1ll<<j)%MOD)*(n-1-i-cnt[n-1-i][j]);
          ans%=MOD;
        }
    }
  }
  
  cout << ans<< endl;
        
  
}


Measured memory_bytes: 166912
import sys
from itertools import combinations
from collections import defaultdict

sys.setrecursionlimit(100000000)

class UnionFind(object):
    def __init__(self, N):
        self._parent = list(range(N))
        self.__num_components = [1] * N

    def root(self, x):
        if self._parent[x] == x:
            return x
        else:
            # root abbreviation
            self._parent[x] = self.root(self._parent[x])
            return self._parent[x]

    def same(self, x, y):
        return self.root(x) == self.root(y)

    def num_connected(self, x):
        return self.__num_components[self.root(x)]

    def unite(self, x, y):
        x = self.root(x)
        y = self.root(y)
        if (x == y):
            return
        rank_x = self.__num_components[x]
        rank_y = self.__num_components[y]
        if rank_x < rank_y:
            self._parent[x] = y
            self.__num_components[y] += rank_x
        else:
            self._parent[y] = x
            self.__num_components[x] += rank_y
        return


fin = sys.stdin.readline

N = int(fin())
coordinates = [[int(elem) for elem in fin().split()] + [i] for i in range(N)]

# p, qのペアを計算
all_dists = defaultdict(list)
for each_pair in combinations(coordinates, 2):
    each_p = each_pair[0][0]-each_pair[1][0]
    each_q = each_pair[0][1] - each_pair[1][1]
    if each_p < 0:
        each_p = -each_p
        each_q = -each_q
    if each_p * each_q == 0:
        each_p = abs(each_p)
        each_q = abs(each_q)
    each_pq = (each_p, each_q)
    all_dists[each_pq].append([each_pair[0][2], each_pair[1][2]])

# 適当にスタート，探索を行う
count_list = []
for each_pq in all_dists:
    uf = UnionFind(N)
    for x, y in all_dists[each_pq]:
        uf.unite(x, y)
    num_distinct_components = 0
    for i in range(N):
        if uf.root(i) == i:
            num_distinct_components += 1
    count_list.append(num_distinct_components)

if len(count_list) == 0:
    print(1)
else:
    print(max(min(count_list), 1))


Measured memory_bytes: 43104
/*"Success isn't permanent, failure isn't fatal,
                                      it's the courage to continue that counts"*/
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define ll long long 
#define scn(n) scanf("%d",&n)
#define lscn(n) scanf("%lld",&n)
#define lpri(n) printf("%lld",n)
#define pri(n) printf("%d",n)
#define pln() printf("\n")
#define priln(n) printf("%d\n",n)
#define lpriln(n) printf("%lld\n",n)
#define rep(i,init,n) for(int i=init;i<n;i++)
#define pb push_back     
#define mp make_pair
#define F first
#define S second
#define gcd __gcd
#define inf INT_MAX
#define ninf INT_MIN
const int mod=1e9+7;         
const int N=5e5+4;

int main()
{
	int a,b,c,d;

	cin>>a>>b>>c>>d;

	int flag=0;

	while(1)
	{
		if(flag==0)
		c-=b;
		else
		a-=d;

		if(a<=0)
		{
			printf("No"); return 0;
		}
		else if(c<=0)
		{
			printf("Yes"); return 0;
		}

		flag^=1;
	}

    return 0; 
}

Measured memory_bytes: 3680
n,a,b=[int(k) for k in input().strip().split(" ")]
mod=10**9+7
tp=pow(2,n,mod)-1
tpa=1
tpb=1
while a:
    a-=1
    tpa*=(n-a)*pow(a+1,mod-2,mod)
    tpa%=mod
while b:
    b-=1
    tpb*=(n-b)*pow(b+1,mod-2,mod)
    tpb%=mod

res = (tp - tpa - tpb)%mod
print(res)

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

int count(int a, int b, int c) {
    int ret[] = {1, 3, 6};
    vector<int> v = {a, b, c};
    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()), v.end());
    return ret[v.size()-1];
}

int main() {
    int K, S, ans = 0;
    cin >> K >> S;
    for (int x = 0; x <= S / 3; x++) {
        for (int z = ceil(S / 3); z <= K; z++) {
            int y = S - x - z;
            if (x > y || y > z) continue;
            ans += count(x, y, z);
        }
    }
    cout << ans << endl;
}

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

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<unordered_set>
#include<bitset>
#include<complex>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD =  (int)1e9 + 7;
const double EPS = 1e-9;

signed main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int A, B;
	char c;
	cin >> A >> c >> B;

	if (c == '+')
	{
		cout << A + B << endl;
	}
	else
	{
		cout << A - B << endl;
	}

	return 0;
}

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

resx, resy, resz = (-1, -1, -1)
xmax = min(N, Y//10000)
for x in range(xmax+1):
    for y in range(N-x+1):
        z = N - x - y
        total = 10000*x + 5000*y + 1000*z

        if total == Y:
            resx, resy, resz = (x, y, z)
            break

print(resx, resy, resz)

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

using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
typedef long long ll;
//typedef pair<int, int> P;
typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = 10e10;
const ll MINF = -10e10;
//const int INF = INT_MAX;
#define mins(x, y) x = min(x, y)
#define maxs(x, y) x = max(x, y)

typedef priority_queue<P, vector<P>, greater<P> > PQ_ASK;
const int mod = 1000000007;
//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;

int factorize(int n) {
    int count = 0;
    for (int i = 1; i <= n; i++) {
        if (n % i == 0) {
            count++;
        }
    }
    return count;
}

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

    int count = 0;
    for (int i = 1; i <= n; i++) {
        if (i % 2 == 0)continue;
        if(factorize(i) == 8) {
            count ++;
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {
		new Main().run();
	}

	private void run() throws IOException {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			int w = scanner.nextInt();
			int h = scanner.nextInt();
			if ((w | h) == 0)
				break;
			int xs = scanner.nextInt();
			int ys = scanner.nextInt();
			xg = scanner.nextInt();
			yg = scanner.nextInt();
			int n = scanner.nextInt();
			map = new int[h + 2][w + 2];

			for (int i = 0; i < n; i++) {
				int c = scanner.nextInt();
				int d = scanner.nextInt();
				int x = scanner.nextInt();
				int y = scanner.nextInt();
				if (d == 0) {
					for (int j = 0; j < 2; j++) {
						for (int k = 0; k < 4; k++) {
							map[j + y][k + x] = c;

						}
					}
				} else {
					for (int j = 0; j < 4; j++) {
						for (int k = 0; k < 2; k++) {
							map[j + y][k + x] = c;
						}
					}
				}
			}
			color = map[ys][xs];
			b = new boolean[h + 2][w + 2];
			if (color == 0)
				System.out.println("NG");
			else
				System.out.println(slove(xs, ys) ? "OK" : "NG");
		}

	}

	private boolean slove(int x, int y) {
		b[y][x] = true;
		if (map[y][x] != color)
			return false;
		if (y == yg && x == xg)
			return true;
		for (int[] a : dxy) {
			int dx = a[1] + x;
			int dy = a[0] + y;
			if (b[dy][dx])
				continue;
			if (slove(dx, dy))
				return true;
		}
		return false;
	}

	int[][] dxy = { { -1, 0 }, { 0, -1 }, { 0, 1 }, { 1, 0 } };
	boolean[][] b;
	int[][] map;
	int xg;
	int yg;
	int color;
}

Measured memory_bytes: 24080
import java.util.*

fun main(args: Array<String>) {

    val sc = Scanner(System.`in`)
    val N = sc.nextInt()

    fun abs(dp:Pair<Int,Int>,h:Int) = Math.abs(dp.second - h)

    val DP = Array(N){0 to 0}
    DP[0] = 0 to sc.nextInt()
    val h = sc.nextInt()
    DP[1] = abs(DP[0],h) to h
    for (i in 2 until N) {
        val h = sc.nextInt()
        val min = Math.min(DP[i-1].first+abs(DP[i-1], h), DP[i-2].first+abs(DP[i-2], h))
        DP[i] = min to h
    }
    //for ((n,h) in DP) print("$n ")
    println(DP[N-1].first)
}

Measured memory_bytes: 68472
using System;
using System.Collections.Generic;

namespace _3_B
{
    class Program
    {
        static void Main(string[] args)
        {
            var li = new List<int>();
            while(true)
            {
                var x = int.Parse(Console.ReadLine());
                if (x == 0) break;
                li.Add(x);
            }
            for(var i=0;i<li.Count;i++)
            {
                Console.WriteLine("Case {0}: {1}", i + 1, li[i]);
            }
        }
    }
}



Measured memory_bytes: 20024
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e17)
#define PI (acos(-1))
//const double PI = acos(-1);
//const double EPS = 1e-15;
//long long INF=(long long)1E17;
#define i_7 (long long)(1e9+7)
//#define i_7 998'244'353
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;

bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd_(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}
  
int main(){
  
  int n;
  cin>>n;
  string s;
  cin>>s;
  int q;
  cin>>q;
  int k[q];
  REP(i,q){
    cin>>k[i];
  }
  long long dsum[n] = {};
  long long msum[n] = {};
  REP(i,n){
    if(i==0){
      if(s[i] == 'D'){
        dsum[i]++;
      }else if(s[i] == 'M'){
        msum[i]++;
      }else{
        ;
      }
    }else{
      if(s[i] == 'D'){
        dsum[i] = dsum[i-1] + 1;
        msum[i] = msum[i-1];
      }else if(s[i] == 'M'){
        dsum[i] = dsum[i-1];
        msum[i] = msum[i-1] + 1;
      }else{
        dsum[i] = dsum[i-1];
        msum[i] = msum[i-1];
      }
    } 
  }
  REP(i,q){
    long long dmnum[n] = {};
    REP(j,k[i]-2){
      if(s[j+1] == 'M'){
        dmnum[j+1] = dmnum[j] + dsum[j];
      }else{
        dmnum[j+1] = dmnum[j];
      }
    }
    for(int j = k[i]-2; j < n-1; j++){
      if(s[j+1] == 'M'){
        if(j-(k[i]-2) >= 1){
          dmnum[j+1] = dmnum[j] + dsum[j] - dsum[j-(k[i]-2)-1];
        }else{
          dmnum[j+1] = dmnum[j] + dsum[j];
        }
      }else{
        dmnum[j+1] = dmnum[j];
      }
      if(s[j-(k[i]-2)] == 'D'){
        dmnum[j+1] -= msum[j+1] - msum[j-(k[i]-2)];
      }else{
        ;
      }
    }
    long long res = 0;
    REP(j,n){
      if(s[j] == 'C'){
        if(j==0)continue;
        res += dmnum[j-1];
      }else{
        continue;
      }
    }
    cout<<res<<endl;
  }
  return 0; 
}

Measured memory_bytes: 24836
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;
int main() {
  int N, M, k[10], s[10][10], p[10];
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    cin >> k[i];
    for (int j = 0; j < k[i]; j++) cin >> s[i][j];
  }
  for (int i = 0; i < M; i++) cin >> p[i];
  
  int ans = 0;
  for (int a = 0; a < pow(2, N); a++) {
    int tmp = 0;
    for (int b = 0; b < M; b++) {
      int cnt = 0;
      for (int c = 0; c < k[b]; c++)
        if (a & (1 << (s[b][c] - 1))) cnt++;
      if (cnt % 2 == p[b]) tmp++;
    }
    if (tmp == M) ans++;
  }
  cout << ans << endl;
}

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

int main() {

    int count = 0;
    int p,N;
    cin >> N;


    for (int i=0; i<N; i++){
        cin >> p;
        if(p!=(i+1))    count++;
    }
    if(count<=2)    cout << "YES" << endl;
    else            cout << "NO" << endl;

    return 0;
}

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

using namespace std;

int main()
{
int N ;
cin >> N;
int c=0 , c1 =0;
for (int i=1 ; i<=N; i++)
{    c1=0;
    if (i%2 !=0)
       {
    for (int j=1; j<=i ; j++)
        if(i%j==0)
        c1++;}
        if(c1==8)
        c++;


}
cout << c ;

    return 0;
}


Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.util.*;

public class Main {
	
    public static void main(String[] args) {
    	FastScanner sc = new FastScanner();
    	
    	int N = sc.nextInt();
    	
        int[] t = new int[N+1];
        int[] x = new int[N+1];
        int[] y = new int[N+1];
        	
        t[0] = 0;
        x[0] = 0;
        y[0] = 0;
        	
        for(int i=1;i<=N;i++){
        	t[i] = sc.nextInt();
        	x[i] = sc.nextInt();
        	y[i] = sc.nextInt();
        }
        	
        for(int i=0;i<N;i++){
        	int time = t[i+1] - t[i];
        	int dx = Math.abs(x[i+1]-x[i]);
        	int dy = Math.abs(y[i+1]-y[i]);
        	int d = dx + dy;
        		
        	if(time < d){
        		System.out.println("No");
        		break;
        	}
        	else if(d%2 == time%2){
        		if(i==N-1){
        			System.out.println("Yes");
        		}
        	}
        	else{
        		System.out.println("No");
        		break;
        	}
        }	
    }


    }
    

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}

Measured memory_bytes: 25988