akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30
#define pb push_back
#define mp make_pair

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

bool used[10000005];

int main() {
	int w, q;
	while(cin >> w >> q) {
		if(w == 0 && q == 0) break;

		memset(used, 0, sizeof(used));
		map<int, P> m;

		rep(i, q) {
			string s;
			int id, t;

			cin >> s;

			if(s == "s") {
				cin >> id >> t;
				int l = 0, r = 0, cnt = 0;
				rep(i, w) {
					if(used[i]) {
						cnt = 0;
					} else {
						if(cnt == 0) {
							l = i;
						}

						cnt++;
						r = i;

						if(cnt == t) break;
					}
				}

				if(cnt == t) {
					m[id] = mp(l, r);
					REP(i,l, r+1) {
						used[i] = true;
					}
					cout << l << endl;
				} else {
					cout << "impossible" << endl;
				}
			} else {
				cin >> id;
				P p = m[id];

				REP(i,p.first, p.second+1) {
					used[i] = false;
				}

				m.erase(id);
			}
		}

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

Measured memory_bytes: 10976
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

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

struct edge {
	ll ind;
	ll to;
	ll d;
};


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






int main() {

	ll N;
	cin >> N;

	vector<ll> s(N + 1);
	repn(i, N) cin >> s[i];

	ll ans = 0;
	repn(i, N) ans += s[i];

	if (ans % 10 == 0) {
		sort(++s.begin(), s.end());
		repn(i,N){
			if (s[i] % 10 != 0) { ans -= s[i]; break; }
			if (i == N) { ans = 0; }
		}
	}


	cout << ans;
	system("PAUSE");
}


Measured memory_bytes: 504
#include <stdio.h>
#include <string.h>
int main()
{
    int w = 0, i;
    char s[1000], b[10];
    scanf("%s", b);
    for (i = 0; i < 10; i++)
        b[i] = tolower(b[i]);
    while (1)
    {
        scanf("%s", s);
        if (strcmp(s, "END_OF_TEXT") == 0)
            break;
        for (i = 0; i < 1000; i++)
            s[i] = tolower(s[i]);
        if (strcmp(s, b) == 0)
            w++;
    }
    printf("%d\n", w);
    return 0;
}


Measured memory_bytes: 2032
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	private static int N;
	private static int K;
	private static int[] candle;;

	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine());
		N = Integer.parseInt(st.nextToken());
		K = Integer.parseInt(st.nextToken());
		candle = new int[N];
		st = new StringTokenizer(br.readLine());
		int index0 = 0;
		for (int i = 0; i < N; i++) {
			candle[i] = Integer.parseInt(st.nextToken());
			if(Math.abs(candle[i]) < Math.abs(candle[index0])){
				index0 = i;
			}
		}
		int minValue = Integer.MAX_VALUE;
		int begin = index0 - K + 1;
		int end = index0 + K - 1;
		if(candle[index0] < 0){
			end = index0 + K;
		}else{
			begin = index0 - K;
		}
		if(begin >= 0){
			minValue = Math.min(minValue, -candle[begin]);
			begin++;
		}else{
			begin = 0;
		}
		if(end < N){
			minValue = Math.min(minValue, candle[end]);
			end--;
		}else{
			end = N - 1;
		}
		for(int i = begin; i+K-1<=end; i++){
			minValue = Math.min(minValue, candle[i+K-1] - 2*candle[i]);
			minValue = Math.min(minValue, 2*candle[i+K-1] - candle[i]);
		}
		System.out.println(minValue);
	}
}


Measured memory_bytes: 35648
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <tuple>
#include <queue>
#include <bitset>
#include <set>
#include <map>
#include <list>

using ll = long long;
using ld = long double;
using namespace std;
const int INF = 1e9+100;
const ll INF64 = 7e18l;
const int mod = 1000000007;
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(a) (a).begin(), (a).end()
#define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);


int main(){
    FIN;

    int n;
    cin >> n;
    if(n == 2){cout << 2 << endl;  return 0;}
    if(n%2 == 0) n++;

    int flag;
    while(1){
        flag = 0;
        for(int i=3;i<=int(sqrt(n));i++){
            if(n%i == 0){
                flag = 1;
                break;
            }
        }
        if(flag == 0) break;
        n += 2;
    }

    cout << n << endl;
    return 0;
}


Measured memory_bytes: 256
n = int(input())
s = str(input())

r = s.count('R')
g = s.count('G')
b = s.count('B')

ans = r * g * b

for i in range(n):
    for d in range(n):
        j = i + d
        k = j + d
        if k >= n:
            break
        if s[i] != s[j] and s[j] != s[k] and s[k] != s[i]:
            ans -= 1
print(ans)

Measured memory_bytes: 9204
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)

/*
Arguments:
- G   : 隣接リスト {destination edge, cost}
- d   : srtからの距離 <- これを変更する
- srt : 始点
*/

void dijkstra(vector<vector<pair<ll,ll>>> G, vector<ll> &d, ll srt){
    priority_queue<pair<ll,ll>, vector<pair<ll,ll>>, greater<pair<ll,ll>>> que;
    que.push({0, srt});
    d[srt] = 0;
    while(!que.empty()){
        auto q = que.top();
        que.pop();
        if(q.first > d[q.second]) continue;
        for(auto g : G[q.second]){
            if(d[g.first] <= q.first + g.second) continue;
            d[g.first] = q.first + g.second;
            que.push({d[g.first], g.first});
        }
    }
}

int main(){
    ll n, m, s, t;
    cin >> n >> m >> s >> t;
    s--; t--;
    vector<vector<pair<ll,ll>>> Gs(n), Gt(n);
    rep(i, 0, m) {
        ll u, v, a, b;
        cin >> u >> v >> a >> b;
        u--; v--;
        Gs[u].push_back({v, a});
        Gs[v].push_back({u, a});
        Gt[u].push_back({v, b});
        Gt[v].push_back({u, b});
    }
    vector<ll> ds(n, 1e18), dt(n, 1e18);
    dijkstra(Gs, ds, s);
    dijkstra(Gt, dt, t);
    vector<pair<ll,ll>> cands(n);
    rep(i, 0, n) cands[i] = {ds[i] + dt[i], i+1};
    sort(cands.begin(), cands.end());
    ll itr = 0;
    rep(i, 0, n){
        while(cands[itr].second <= i) itr++;
        cout << 1000000000000000 - cands[itr].first << endl;
    }
    return 0;
}

Measured memory_bytes: 27920
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//


int main() {
	int N;
	cin >> N;
	vector<int> X(N), Y(N);
	REP(i, N) scanf("%d %d", &X[i], &Y[i]);
	
	ll ans = -longINF;
	
	vector<int> Z(N);
	REP(i, N) Z[i] = X[i] - Y[i];
	chmax(ans, *max_element(ALL(Z)) - *min_element(ALL(Z)));
	REP(i, N) Z[i] = X[i] + Y[i];
	chmax(ans, *max_element(ALL(Z)) - *min_element(ALL(Z)));
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 5700
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;

ll INF = 1e9;
ll MOD = 1e9+7;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, K; cin >> N >> K;
  vector<vector<int> > E(N, vector<int>());
  REP(i, N-1){
    int a, b; cin >> a >> b; a--; b--;
    E[a].push_back(b);
    E[b].push_back(a);
  }
  
  vector<ll> dist(N, INF);
  queue<int> q;
  q.push(0);
  dist[0] = 0;
  ll ans = K%MOD;
  while(!q.empty()){
    int cur = q.front(); q.pop();
    ll cnt = 0;
    ll dep = 1;
    for(int i : E[cur]){
      if(dist[i] != INF) continue;
      cnt++;
      dist[i] = dist[cur]+1;
      dep = min(dist[i], 2LL);
      q.push(i);
    }
    for(ll i = 0; i < cnt; i++){
      ans = (ans*(K-dep-i))%MOD;
      if(K-dep-i <= 0){
        cout << 0 << endl;
        return 0;
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 7288
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            var N = cin.ReadInt;
            var K = cin.ReadInt;

            var sunuke = new int[N];

            for (int i = 0; i < K; i++)
            {
                var d = cin.ReadInt;
                for (int j = 0; j < d; j++)
                {
                    var a = cin.ReadInt;
                    sunuke[a - 1] = 1;
                }
            }
            var ans = sunuke.Where(_ => _ == 0).Count();
            WriteLine(ans);
        }

    }


    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }

        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; i++)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }


        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}


Measured memory_bytes: 28408
#include <stdio.h>
int main()
{
    long long int n,k,t;
    scanf("%lld %lld",&n,&k);
    if(n>=k)
    {
        if(n%k==0)
        {
            printf("0");
            return 0;
        }
        t=n%k;
        if(t*2<k)
            printf("%lld",t);
        else
            printf("%lld",k-t);
    }
    else
    {
        if(n*2<k)
            printf("%lld",n);
        else
            printf("%lld",k-n);
    }
    return 0;
}


Measured memory_bytes: 128
/*
ID: amagica1
TASK: ariprog
LANG: C++
*/
#include <bits/stdc++.h>
using namespace std;
#define INF INT_MAX
#define NINF -INF
#define mp make_pair
#define endl '\n'
#define boost() cin.tie(0); cin.sync_with_stdio(0)
#define For(i, a, b) for(int i=a; i<b; i++)
#define FOR(i, a, b) for(int i=a; i<=b; i++)
#define Rev(i, a, b) for(int i=a; i>b; i--)
#define REV(i, a, b) for(int i=a; i>=b; i--)
#define debug(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
typedef long long ll;
typedef long double ld;
typedef int64_t l;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, ll> pll;
const ll MOD = 1e9 + 7;
const int MAXN = 100005;
ll gcd(ll a, ll b){return b == 0 ? a : gcd(b, a % b);}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
ll fpow(ll  b, ll exp, ll mod){if(exp == 0) return 1;ll t = fpow(b,exp/2,mod);if(exp&1) return t*t%mod*b%mod;return t*t%mod;}
ll divmod(ll i, ll j, ll mod){i%=mod,j%=mod;return i*fpow(j,mod-2,mod)%mod;}
mt19937 rng;
int main() {
    //-----------FILE------------//
    //freopen("airprog.in", "r", stdin);
    //freopen("airprog.out", "w", stdout);
    //----------------------------//
    int a, b; cin >> a >> b;
    if(a > b) for(int i=1; i<=a; i++) cout << b;
    else for(int i=1; i<=b; i++) cout << a;
    cout << endl;
    return 0;
}


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

// Shortening code
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef tuple<int, int, int> ti;

// Macros
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define REP(i, a, b) for (int i = a; i < b; i++)
#define RREP(i, a, b) for (int i = a; i >= b; i--)

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    // Your code
    ll n;
    cin >> n;

    map<ll, ll> m;    
    ll cnt = 0;
    REP(i, 0, n){
        int a;
        cin >> a;
        // i - j = a[i] + a[j] --> i - a[i] = a[j] + j
        cnt += m[i - a]; 
        m[a + i]++;
    }
    cout << cnt;
    return 0;
}

Measured memory_bytes: 26288
#include <iostream>
#include <string>
#include <cstdlib>
#include <algorithm>

using namespace std;

int main(void) {
	string str;
	string res = "";
	for (int i = 0; i < 3; ++i) {
		cin >> str;
		res += str[0];
	}
	transform(res.begin(),res.end(),res.begin(),::toupper);
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 256
import Control.Monad

main :: IO ()
main = do
  s <- getLine

  when (s /= "-") $ do
    m <- readLn
    hs <- replicateM m readLn
    putStrLn $ foldl (\acc h -> rotate h acc) s hs
    main

rotate :: Int -> String -> String
rotate n xs = drop n xs ++ take n xs

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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007


int main(){

  int a,b,c,k;
  cin >> a >> b >> c >> k;
  ll res = 0;
  res += min(a,k);
  k -= min(a,k);
  res += min(b,k)*0;
  k -= min(b,k);
  res += min(c,k)*(-1);
  k -= min(c,k);
  cout << res << endl;
  





  

  return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <sstream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <assert.h>
#include <deque>
using namespace std;

typedef unsigned long long UL;
typedef long long LL;
typedef long double LD;
#define LP(i, a, b) for (LL i = int(a); i < int(b); i++)
#define LPE(i, a, b) for (LL i = int(a); i <= int(b); i++)
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef vector<vector<PII> > WAL;
typedef vector<vector<int> > SAL;
#define Ep 1e-8
#define INF 1e9
#define LINF 1e18

LL const MOD = 1e9 + 7;
LL const MaxSize = 2e5 + 5;
//LL const MOD = 998244353;

/*

 https://atcoder.jp/contests/abc132/tasks/abc132_d
 D - Blue and Red Balls

 Easy problem, but python version gives TLE in the last two cases
 */

//NOTE WORKS ONLY WHEN MOD IS PRIME
int N, Q, ps[MaxSize];
LL xs[MaxSize];

//test case, either = 1 or all = 1

SAL tree;
queue<int> q;

int main() {
	ios_base::sync_with_stdio(false);
	//freopen("/Users/georgeli/A_1.in", "r", stdin);

	cin >> N >> Q;
	tree = SAL(MaxSize);

	LP(i, 0, N - 1)
	{
		int a, b;
		cin >> a >> b;
		tree.at(a).push_back(b);
		tree.at(b).push_back(a);
	}

	LP(i, 0, Q)
	{
		LL p, x;
		cin >> p >> x;
		xs[p] += x;
	}

	q.push(1);

	while (q.size()) {
		int v = q.front();
		q.pop();
		LP(i, 0, tree.at(v).size())
		{
			int u = tree.at(v)[i];
			if (u == ps[v])
				continue;
			ps[u] = v;
			xs[u] += xs[v];
			q.push(u);
		}

	}
	LPE(i, 1, N)
	{
		cout << xs[i] << " ";
	}

	return 0;
}


Measured memory_bytes: 17012
#include <algorithm>
#include <iostream>

using namespace std;
typedef long long ll;

int main() {
    int N; cin >> N;
    ll A[N]; for (int i = 0; i < N; i++) cin >> A[i];

    sort(A, A + N, greater<ll>());

    ll h = 0, w = 0;
    int pos = 1;
    while (pos < N) {
        if (A[pos] == A[pos - 1]) {
            h = A[pos];
            pos += 2; break;
        }
        pos++;
    }
    while (pos < N) {
        if (A[pos] == A[pos - 1]) {
            w = A[pos];
            break;
        }
        pos++;
    }

    cout << h*w << endl;
    return 0;
}

Measured memory_bytes: 1024
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_10_A
// Dynamic Programming - Fibonacci Number

#define SUBMIT

#include <utility>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <vector>
#include <limits>
#include <numeric>
#include <functional>
#include <set>
#include <cmath>
#include <cstring>
#include <climits>
#include <memory>

using namespace std;
using ui64 = unsigned long long;
using i64 = long long;

const ui64 MAX_N = 44;
int dp[MAX_N + 1];

int main() {
    // initialize
    memset(dp, 0, sizeof(dp));
    dp[0] = 1, dp[1] = 1;

    for (int i = 2; i <= MAX_N; ++i) dp[i] = dp[i - 1] + dp[i - 2];

    int n;
    cin >> n;

    cout << dp[n] << endl;
    return 0;
}


Measured memory_bytes: 3096
import java.util.Scanner;
public class Main{

private static Scanner scanner;

public static void main(String args[])
{
	scanner = new Scanner(System.in);
	int a = scanner.nextInt();
	int[] b = new int[a];
	for(int i = 0;i < a;i++) {
		b[i] = scanner.nextInt();

	}
	for(int i = 0;i < a;i++) {
		int v = b[i];
		int j = i-1;
		while(j >= 0 && b[j] > v) {
			b[j+1] = b[j];
			j--;
			b[j+1] = v;
		}
		for(int c = 0;c < a;c++)
		{
			System.out.print(b[c]);
			if(c == a-1) {}
			else {
			System.out.print(" ");
			}
		}
		System.out.println("");
		}

	}
}



Measured memory_bytes: 34208
#include <bits/stdc++.h>
using namespace std;
const int N=200005;
int n,a[N],ans,f=0;
map <int,int> mp;
bool check(int x){
	mp.clear();
	for (int i=2;i<=n;i++)
		if (a[i-1]>=a[i]){
			while (!mp.empty()){
				int t=mp.rbegin()->first;
				if (t>a[i]) mp.erase(t); 
				else break;
			}
			int j=a[i];
			while (mp[j]+1==x) mp.erase(j),j--;
			if (j==0) return false;
			mp[j]++;
		}
	return true;
}
int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;i++) {
		scanf("%d",&a[i]);
		if (a[i]<=a[i-1]) f=1;
	}
	if (!f) {puts("1");return 0;}
	int l=2,r=n;
	while (l<=r){
		int mid=(l+r)>>1;
		if (check(mid)){
			ans=mid;
			r=mid-1;
		}else l=mid+1;
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <string.h>
const int N = 1300;

int main()
{
    char str[N];
    while(fgets(str, 1300, stdin))
    {
        for(int i = 0; i < strlen(str); i++)
        {
            if(str[i] >= 'A' && str[i] <='Z')
            {
                printf("%c", str[i] + 32);
            }
            else if(str[i] >= 'a' && str[i] <='z')
            {
                printf("%c", str[i] - 32);
            }
            else
                printf("%c",str[i]);
        }
    }
    return 0;
}



Measured memory_bytes: 2628
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(b);i>(a);--i)
#define eper(i,a,b) for(int i=((int)(a));i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF 2000000000
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

int n;
int main() {
 ios::sync_with_stdio ( false );
 cin.tie ( 0 );
    string s; 
    cin >> s;
    rep(i, 0, 4) {
        if (s[i] == '+') n++;
        else n--;
    }
    cout << n << endl;
    return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
# ----------------------------------------------------------------
# Use Solve Function

def solve(lines):
    N,Q = map(int, lines.pop(0).split(' '))
    S = lines.pop(0)
    NLIST = []
    for i in range(Q):
        a,b = map(int, lines.pop(0).split(' '))
        NLIST.append((a,b))
    sums = [0]
    res = 0
    for i in range(N-1):
        if S[i:i+2] == 'AC':
            res += 1
        sums.append(res)
    for k in NLIST:
        i = max( k[0] - 1, 0)
        j = k[1] - 1
        print(sums[j] - sums[i])
lines = [x.strip() for x in sys.stdin.readlines()]

#
# solve !!
#
solve(lines)


Measured memory_bytes: 19780
#include <iostream>
#include <vector>
#include <string.h>

using namespace std;

char field[18][18];
int dp[18][18][18];
int X, Y;

int DFS(int x, int y, int prex)
{
	if ((x < 0 || x >= X) || field[y][x] == '1' || (field[y][x] == '2' && x != prex))
	{
		return(0);
	}
	if (y >= Y - 1)
	{
		return(1);
	}
	if (dp[x][y][prex] != -1)
	{
		return(dp[x][y][prex]);
	}
	int ans = 0;
	if (field[y][x] == '2')
	{
		ans += DFS(x, y + 2, x);
	}
	else
	{
		ans += DFS(x - 1, y + 1, x);
		ans += DFS(x, y + 1, x);
		ans += DFS(x + 1, y + 1, x);
	}
	return(dp[x][y][prex] = ans);
}

void solve()
{
	while (cin >> X >> Y, X || Y)
	{
		for (int i = 0; i < Y; ++i)
		{
			for (int j = 0; j < X; ++j)
			{
				cin >> field[i][j];
			}
		}
		int ans = 0;
		memset(dp, -1, sizeof(dp));
		for (int i = 0; i < X; ++i)
		{
			ans += DFS(i, 0, 0);
		}
		cout << ans << endl;
	}
}

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

Measured memory_bytes: 1192
#include <bits/stdc++.h>
#include <cctype>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
using ll = long long;
using p = pair<int,int>;
using Graph = vector<vector<int>>;
int main(int argc, const char * argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int a,b;
    cin>>a>>b;
    string s;
    cin>>s;
    bool flag=true;
    rep(i,a){
        if(s[i]=='-')flag=false;
    }
    if(s[a]!='-')flag=false;
    for(int i=a+1;i<(a+b+1);i++){
        if(s[i]<'0'||s[i]>'9')flag=false;
    }
    if(flag)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

    return 0;
}

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

using namespace std;
using vi = vector<int>;

#define rep(i,n) for(int i=0;i<(n);++i)
#define in(v) cin>>v;
#define out(v) cout<<v<<"\n"

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

  vi B(N-1);
  rep(i, N-1) {
    in(B[i]);
  }
  int sum = B[0];
  rep(i, N-2) {
    sum += min(B[i], B[i+1]);
  }
  sum += B[N-2];
  out(sum);

  return 0;
}


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

bool isprime(long long int val) {
    if (val <= 1)return false;
    for (long long int i = 2; i*i <= val; i++) {
        if (val%i == 0LL)return false;
    }
    return true;
}

int main(){
    long long a,d,n;
    while(cin>>a>>d>>n){
        if(a==0 && d==0 && n==0){
            break;
        }
        long long ans=0;
        int cnt=0;
        if(isprime(a)) cnt++;
        while(cnt!=n){
            a+=d;
            if(isprime(a)) cnt++;
        }
        cout<<a<<endl;

    }
    
}


Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
void __print(int x) {cout << x;}
void __print(long x) {cout << x;}
void __print(long long x) {cout << x;}
void __print(unsigned x) {cout << x;}
void __print(unsigned long x) {cout << x;}
void __print(unsigned long long x) {cout << x;}
void __print(float x) {cout << x;}
void __print(double x) {cout << x;}
void __print(long double x) {cout << x;}
void __print(char x) {cout << '\'' << x << '\'';}
void __print(const char *x) {cout << '\"' << x << '\"';}
void __print(const string &x) {cout << '\"' << x << '\"';}
void __print(bool x) {cout << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __print(i); cout << "}";}
void _print() {cout << "\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}
#define debug(x...) cout << #x << " = "; _print(x)
typedef long long ll; typedef vector<int> vi; typedef vector<ll> vll;
#define rep(i,a,b) for (ll i = (a); i < (b); ++i)
#define per(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define all(x) begin(x), end(x)
#define mp make_pair 
#define pb push_back
#define ff first
#define ss second
#define fast ios_base::sync_with_stdio(NULL);cin.tie(NULL);cout.tie(NULL) 
const int mod = 1e9 + 7, mxn = 2e5 + 1;
vi v[mxn], vis(mxn);
int cnt = 0;

void dfs(int cur){
    cnt++;
    vis[cur] = 1;
    for(auto child: v[cur])
        if(vis[child] == 0)
            dfs(child);
}

int solve(){
    int n, m, ans = -1;
    cin>> n>> m;
    map<pair<int, int>, int> seen;
    rep(i, 0, m){
        int x, y;
        cin>> x>> y;
        if(x > y)
            swap(x, y);
        if(seen[mp(x, y)])
            continue;
        seen[mp(x, y)] = 1;
        v[x].pb(y);
        v[y].pb(x);
    }
    rep(i, 1, n + 1){
        if(vis[i])
            continue;
        cnt = 0;
        dfs(i);
        ans = max(ans, cnt);
    }
    cout<< ans<< "\n";
    return 0;   
}
//Counting problems: Sometimes easier to find complement of the answer
 
int main()
{
    fast;
    int t = 1;
    //cin>> t;
    while(t--){  
        solve();
    }
    return 0;
}
//v.clear(), vis.clear(); vis.resize(n + 1, 0), v.resize(n + 1);
 
/*  inv[1] = 1; // inv is ll
    for(int i=2; i<=mxn; ++i)
        inv[i]=mod-mod/i*inv[mod%i]%mod;*/
        
// lower bound   >=  
// upper bound   >
// vector<int>().swap(vec); //free memory from vec


Measured memory_bytes: 33788
n=int(input())
a=list(map(int,input().split()))
q=int(input())
b,c=[],[]
for _ in range(q):
  bi,ci=map(int,input().split())
  b.append(bi)
  c.append(ci)
number=[0 for i in range(10**5+1)]
for i in range(n):
  number[a[i]]+=1
s=sum(a)
for i in range(q):
  s+=(c[i]-b[i])*number[b[i]]
  number[c[i]]+=number[b[i]]
  number[b[i]]=0
  print(s)

Measured memory_bytes: 22504
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>

using namespace std;
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define reppe(i,a,b) for(int i = (int)(a) ; i <= (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)
#define repme(i,a,b) for(int i = (int)(a) ; i >= (int)(b) ; --i)

typedef long long ll;

long long GCD(long long a, long long b){if(b==0)return a;return GCD(b,a%b);}

int main() {
    int H, A; cin >> H >> A;
    cout << (H + (A-1)) / A << endl;
}


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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  
  int wLeft = a + b;
  int wRight = c + d;
  
  if(wLeft > wRight){
    cout << "Left" << endl;
  }
  else if(wLeft == wRight){
    cout << "Balanced" << endl;
  }
  else{
    cout << "Right" << endl;
  }
}

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

using namespace std;
int main()
{
	int x, y = 0;

	cin >> x;
	cin >> y;

	if (x == 1 || x == 3 || x == 5 || x == 7 || x == 8 || x == 10 || x == 12) {
		if (y == 1 || y == 3 || y == 5 || y == 7 || y == 8 || y == 10 || y == 12) {
			cout << "Yes";
		}
		else {
			cout << "No";
		}
	}
	else {
		if (x == 2) {
			if (y == 2) {
				cout << "Yes";
			}
			else {
				cout << "No";
			}
		}
		else {
			if (y == 4 || y == 6 || y == 9 || y == 11) {
				cout << "Yes";
			}
			else {
				cout << "No";
			}
		}
	}
	
	cin >> x;

	return 0;
}

Measured memory_bytes: 256
H, W = map(int, input().split())
m = [list(map(int, list(input()))) for _ in range(H)]

dp = [[-1 for j in range(W)] for i in range(H)]

for i in range(H):
    for j in range(W):
        if i == 0 and j == 0:
            dp[i][j] = 0
        elif i == 0:
            dp[i][j] = dp[i][j-1] + m[i][j]
        elif j == 0:
            dp[i][j] = dp[i-1][j] + m[i][j]
        else:
            dp[i][j] = min(dp[i-1][j], dp[i][j-1]) + m[i][j]

print(dp[H-1][W-1])

Measured memory_bytes: 7784
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <numeric>
#include <queue>
#include <string>
#include <utility>
#include <vector>

using namespace std;
#define ALL(a) (a).begin(), (a).end()
#define REP(i, n) for (size_t i = 0; i < (n); i++)
#define nvec(T, v, n) vector<T> v(n); REP(i, n) {cin>>(v)[i];}
#define npairs(T1, T2, v, n) vector<pair<T1, T2>> v(n); REP(i, n){cin>>v[i].first>>v[i].second;}
#define ntuples(T1, T2, T3, v, n) vector<tuple<T1, T2, T3>> v(n); REP(i, n){cin>>get<0>(v[i])>>get<1>(v[i])>>get<2>(v[i]);}
#define vec2d(T, v, m, n) vector<vector<T>> (v)(m, vector<T>(n))
#define nvec2d(T, v, m, n) vec2d(T, v, m, n); REP(j, m){REP(i, n) {cin>>(v[j])[i];}}

#define min_index(v) size_t( min_element(all(v)) - (v).begin() )
#define max_index(v) size_t( max_element(all(v)) - (v).begin() )
#define min_e(v) *min_element(ALL(v))
#define max_e(v) *max_element(ALL(v))

#define count_le(v, a) size_t( upper_bound(ALL(v), a) - (v).begin() )
#define count_lt(v, a) size_t( lower_bound(ALL(v), a) - (v).begin() )
#define count_ge(v, a) size_t( (v).end() - lower_bound(ALL(v), a) )
#define count_gt(v, a) size_t( (v).end() - upper_bound(ALL(v), a) )

#define order(neq_sl) [](const auto s, const auto l){return neq_sl;}
#define make_lr(v,type,l,r) vector<type> l(n+1),r(n+1);FOR(i,n){l[i+1]=l[i]+v[i];r[i+1]=r[i]+v[n-1-i];}

#define acm accumulate
#define SUM(v) accumulate(ALL(v), 0l)
#define SORT(v) sort(ALL(v))

#define GCD(v) gcd(ALL(v), 0l)

/*template <typename T>
T gcd(T a, T b) {
    if (a > b) swap(a, b);
    if (a == 0) return b;
    return gcd(b%a, a);
}
template <typename InputItr, typename T>
T gcd(InputItr first, InputItr last, T init) {
    for (; first != last; ++first) init = gcd(init, *first);
    return init;
}*/

template <typename T>
using vec =vector<T>;

template <typename T>
using vvec =vector<vector<T>>;

int main(){
  int h, w;
  cin>>h>>w;
  vvec<int> a(h,vec<int>(w));
  queue<pair<int,int>> q;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      char c;
      cin>>c;
      if(c=='#'){
        a[i][j]=0;
        q.push(make_pair(i,j));
      }else{
        a[i][j]=-1;
      }
    }
  }
  int h1, w1;
  while(!q.empty()){
    h1 = q.front().first; w1 = q.front().second;
    q.pop();
    for (int h2: {h1-1, h1+1}){
      int w2=w1;
      if(0<=h2&&h2<h && a[h2][w2]==-1){
          
          a[h2][w2]=a[h1][w1]+1;
     //     cout<<a[h2][w2]<<endl;
          q.push(make_pair(h2,w2));
          
      }
    }
    for (int w2: {w1-1, w1+1}){
      int h2=h1;
      if(0<=w2&&w2<w && a[h2][w2]==-1){
          
          a[h2][w2]=a[h1][w1]+1;
  //        cout<<a[h2][w2]<<endl;
          q.push(make_pair(h2,w2));
          
      }
    }
  }
  cout<<a[h1][w1];
}


/* きょむ〜 */


Measured memory_bytes: 12432
#include <iostream>
#include<stdio.h>
#include<stack>

#define MAX 100
#define WHITE 1
#define GRAY 2
#define BLACK 3

using namespace std;

int color[MAX], d[MAX], f[MAX];
int n, A[MAX][MAX];
int tt;

void dfs_visit_1(int u) { //???????????°
    color[u] = GRAY;
    d[u] = ++tt;
    for(int v = 0; v < n; v++) {
        if(A[u][v] == 0) continue;
        if(color[v] == WHITE) dfs_visit_1(v);
    }
    color[u] = BLACK;
    f[u] = ++tt;
}

void dfs_1() { // ???????????°
    for(int i = 0; i < n; i++) {
        color[i] = WHITE;
    }
    tt = 0;
    for(int i = 0; i < n; i++) {
        if(color[i] == WHITE) dfs_visit_1(i);
    }

    for(int i = 0; i < n; i++) {
        printf("%d %d %d\n", i+1, d[i], f[i]);
    }

}

int next(int u) {
    for(int v = 0; v < n; v++) {
        if(A[u][v] == 1) {
            /*
            if(color[v] == WHITE) return v;
            else if(color[v] == BLACK) return -1;
            else if(color[v] == GRAY) continue;
            */
            return v;
        }
    }
    return -1;
}

void dfs_visit_2(int u) {
    color[u] = GRAY;
    d[u] = ++tt;
    stack<int> S;
    S.push(u);

    while(!S.empty()) {
        int u = S.top();
        int v = next(u);
        if(v != -1) {
            if(color[v] == WHITE) {
                color[v] = GRAY;
                d[v] = ++tt;
                S.push(v);
            }
        }else {
            S.pop();
            color[u] = BLACK;
            f[u] = ++tt;
        }
    }
}


int main()
{
    int u, k, v;
    scanf("%d",&n);

    for(int i = 0; i < n; i++) {
        scanf("%d%d", &u, &k);
        for(int j = 0; j < k; j++) {
            scanf("%d", &v);
            A[u-1][v-1] = 1;
        }
    }


    /*
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < n; j++) {
            printf("%d", A[i][j]);
            if(j != n-1) printf(" ");
        }
        printf("\n");
    }
    */

    dfs_1();

    return 0;
}

Measured memory_bytes: 3220
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <numeric>
using namespace std;
typedef long long ll;

int main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    cout.precision(20);
    int n;cin>>n;
    cout<<double(2.0*M_PI*n);
    
}

Measured memory_bytes: 3792
#include<stdio.h>

int F[50];

int fibonacci(int n){
    if(n==0 || n==1) return F[n] =1;
    if(F[n] != -1) return F[n];
    return F[n] = fibonacci(n-2) + fibonacci(n-1);
}

int main(){
    int n,i;
    for(i=0; i<50; i++) F[i]=-1;
    
    scanf("%d",&n);
    printf("%d\n",fibonacci(n));
    
    return 0;
}


Measured memory_bytes: 2104
#include <iostream>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <functional>
#include <iterator>
#include <bitset>
#include <string>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>

typedef   signed long long int slli;
typedef unsigned long long int ulli;
const slli MAX_SLLI = 0x7FFFFFFFFFFFFFFF;
const slli MIN_SLLI = 0x8000000000000000;
const ulli MAX_ULLI = 0xFFFFFFFFFFFFFFFF;
const ulli MIN_ULLI = 0x0000000000000000;

#define N_TIMES(i, n)     for (ulli i = 0;     i <  n; ++i)
#define N_TIMES_REV(i, n) for (slli i = n - 1; i >= 0; --i)

#ifdef __DEBUG__
template<typename T>
std::ostream& operator<<(std::ostream &os, const std::list<T> &list)
{
  const std::string delim = ", ";
  typename std::list<T>::const_iterator itr = list.begin();
  while (itr != list.end()) {
    os << *itr;
    ++itr;
    if(itr != list.end()) os << delim;
  }
  return os;
}

template<typename T>
std::ostream& operator<<(std::ostream &os, const std::vector<T> &v)
{
  const std::string delim = ", ";
  for (typename std::vector<T>::size_type n = 0; n < v.size(); ++n) {
    os << v[n];
    if((n + 1) < v.size()) os << delim;
  }
  return os;
}
#endif /* __DEBUG__ */

int main(int argc, char **argv)
{
  unsigned N;
  std::cin >> N;
  
  std::vector<int64_t> A(N);
  N_TIMES(n, N) { std::cin >> A[n]; }
  
  std::vector<int64_t> S(N + 1, 0);
  N_TIMES(n, N) { S[n + 1] = A[n] + S[n]; }
  
  uint64_t count = 0;
  
  std::map<int64_t, uint64_t> cache;
  cache.emplace(0, 1);
  
  for (unsigned n = 1; n <= N; ++n) {
    auto itr = cache.find(S[n]);
    if (itr != cache.end()) {
      count += itr->second;
      ++itr->second;
    } else {
      cache.emplace(S[n], static_cast<uint64_t>(1));
    }
  }
  
  std::cout << count << std::endl;
  
  return 0;
}

Measured memory_bytes: 15872
#include <bits/stdc++.h>
using namespace std;
#define INF 2147483647
#define INFF 9223372036854775807
#define ll long long
#define pb push_back
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,m,n) for(int i=m;i<n;i++)
#define ALL(N) (N.begin(),N.end())

int main() {
  int A, P, sum;
  cin >> A >> P;
  sum=A*3+P;
  cout << sum/2 << endl;
}

Measured memory_bytes: 256
# AGC 015: A – A+...+B Problem
from itertools import combinations_with_replacement

n, a, b = [int(s) for s in input().split()]


if a == b:
    print(1)
elif a > b or n <= 2:
    print(0)
else:
    print((b - a) * (n - 2) + 1)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define MOD 1000000007
#define MOD2 998244353
#define pb emplace_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define sz(x) (ll)x.size()
#define F first
#define S second
#define FOR(i,a,b) for(ll i=a;i<=b;++i)
#define ROF(i,a,b) for(ll i=a;i>=b;--i)
#define trace(x) cerr<<#x<<": "<<x<<'\n';
typedef long long ll;
using namespace std;
using namespace __gnu_pbds;
#define T int
#define ordered_set tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>

ll mexp(ll a, ll b, ll m){
    ll ans=1;
    a%=m;
    while(b){
        if(b&1) ans=ans*a%m;
        b>>=1;
        a=a*a%m;
    }
    return ans;
}

const int N = (1<<18) + 1;

ll a[N];
ll dp1[N], dp2[N];

int main(){
    IOS
	int n;
	cin >> n;
	FOR(i,0,(1<<n)-1){
		cin >> a[i];
		dp1[i] = a[i];
	}
	FOR(i,0,n-1){
		FOR(mask,0,(1<<n)-1){
			if(mask & (1<<i)){
				if(dp1[mask ^ (1<<i)] > dp1[mask]){
					dp2[mask] = dp1[mask];
					dp1[mask] = dp1[mask ^ (1<<i)];
				}
				else if(dp1[mask ^ (1<<i)]  > dp2[mask]){
					dp2[mask] = dp1[mask ^ (1<<i)];
				}
				if(dp2[mask ^ (1<<i)] > dp2[mask]){
					dp2[mask] = dp2[mask ^ (1<<i)];
				}
			}
		}
	}
	ll ans = 0;
	FOR(i,1,(1<<n)-1){
		ans = max(ans, dp1[i] + dp2[i]);
		cout << ans << endl;
	}


    return 0;
}

Measured memory_bytes: 9216
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> V;
#define rep(i,e) for(ll i=0;i<e;i++ )
typedef pair<ll,ll> P;
const ll mod = 1e9+7;
const ll INF = INT64_MAX;


ll i;





int main(){
    ll N;
    cin>>N;
    V A(N);
    rep(i,N)cin>>A.at(i);
    V ans;
    V haiti(N);
    
    for(ll j=N-1;j>=0;j--){
        ll jud=0;
        for(ll k=j;k<N;k+=j+1){
            
            if(k==j)jud=jud^A.at(k);
            else jud=jud^haiti.at(k);
        }
        if(jud){
            ans.push_back(j+1);
            haiti.at(j)=1;
        }
        else{
            haiti.at(j)=0;
        }
    }
    cout<<ans.size()<<endl;
    for(ll j=ans.size()-1;j>=0;j--)cout<<ans.at(j)<<endl;


}


Measured memory_bytes: 4980
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>
#include <deque>
#include <iomanip>
#include <cstdio>

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf  1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)

int main(){
    int n,m;
    cin >> n >> m;
    vector<vector<int> > v(n+1);
    vector<pair<int,int> > p;
    rep(i,m){
        int a,b;
        cin >> a >> b;
        v[a].push_back(b);
        p.PB(MP(a,b));
    }

    vector<vector<int> > b = v;
    rep(i,n+1){
        sort(b[i].begin(),b[i].end());        
    }

    vector<map<int,int> > c(n+1);
    for(int i=0;i<n+1;i++){
        for(int j=0;j<b[i].size();j++){
            c[i][b[i][j]] = j+1;
        }
    }
    for(int i=0;i<m;i++){
        int s = p[i].first;
        int t = c[p[i].first][p[i].second];
        string p,q;
        p = to_string(s);
        q = to_string(t);
        for(int j=0;j<6-p.size();j++){
            cout << 0;
        }
        cout << p;
        for(int j=0;j<6-q.size();j++){
            cout << 0;
        }
        cout << q << endl;
    }
    return 0;
}

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

using namespace std;

int N, x[100009];
const int mod = 1e9 + 7;

int mul (int x, int y) {return 1LL * x * y % mod;}

int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

scanf ("%d", &N), x[0] = -1;
for (int i=1; i<=N; i++)
    scanf ("%d", &x[i]), x[i] = min (x[i], x[i - 1] + 2);
int i = 1;
int sz = 1, ans = 1;
while (sz)
{
    while (i <= N && x[i] >= x[i - 1] + 2)
        x[i] = x[i - 1] + 2, i ++, sz ++;
    i --, sz --;
    if (i == N)
    {
        while (sz)
            ans = mul (ans, sz), sz --;
        break;
    }
    else
    {
        ans = mul (ans, sz + 1);
        x[i + 1] = x[i], x[i] -= 2, i ++;
    }
}
printf ("%d\n", ans);
return 0;
}


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

int main(){
 string s;
 cin >> s;
 s.erase(s.begin()+4);//スラッシュを削除
 s.erase(s.begin()+6);
 int num = atoi(s.c_str());
 if(num <= 20190430){
  cout << "Heisei\n";
 }else{
  cout << "TBD\n";
 }
 
}


Measured memory_bytes: 256
INF = 10**10
N,M = map(int,input().split())
Coins = list(map(int,input().split()))
Coins.sort()
# DP[x種類目までのコイン][n円を支払う]
# index1 0,1(1種類め),...(n種類め)
# index2 0円,1円,2円... 
# DP[m+1][n+1]で作成
DP = [ [INF]*(N+1) for _ in range(M+1) ]

# 0円の場合の支払いに必要な枚数は 0
for i in range(1,M+1):
    DP[i][0] = 0

# 1円のみで支払う場合
for i in range(1,N+1):
    DP[1][i] = i
# 2種類め以降を使う場合
for m in range(2,M+1):
    for n in range(1,N+1):
        # 支払うのは n円
        # 1枚 c円
        c = Coins[m-1]
        if n >= c:
            DP[m][n] = min(DP[m][n],DP[m][n-c] + 1)
        DP[m][n] = min(DP[m][n],DP[m-1][n])

print(DP[M][N])


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

#define pb         push_back

typedef long long ll;
const ll INF = 1000000000ll;
const ll MOD = 1000000007ll;
const double EPS = 1e-8;

int main(void) {
	//ios_base::sync_with_stdio(false);
	//cin.tie(0);
	
	int a, b;
	char op;
	cin >> a >> op >> b;

	if(op == '+') cout << a + b << endl;
	else if(op == '-') cout << a - b << endl;
	
	return 0;
}


Measured memory_bytes: 256
x,n=map(int,input().split(" "))
if n==0:
  print(x)
  exit()

p=[int(_) for _ in input().split(" ")]

s=0
t=0
u=0
w=0
ans=0
flgs=0
flgt=0


for i in range(100):
  s = x + i
  t = x - i
  for j in range(n):
    if s==p[j]:
      flgs=1
  for k in range(n):
    if t==p[k]:
      flgt=1
  if flgs==1 and flgt==1:
    flgs=0
    flgt=0
  else:
    a = i
    break

if flgt == 0:
  ans = x - a
else:
  ans = x + a
  
print(ans)

Measured memory_bytes: 9176
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iterator>
using namespace std;

int main() {
	int N;
	cin >> N;
	vector<pair<pair<string, int>, int>> R;
	for (int i = 0; i < N; ++i) {
		string s;
		int p;
		cin >> s >> p;
		R.push_back({ {s, -p}, i + 1 });
	}
	sort(begin(R), end(R));
	for (auto t : R) {
		cout << t.second << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int a;
    cin >> a;
    cout << (1 << (31 - __builtin_clz(a)));
}


Measured memory_bytes: 256
from itertools import combinations_with_replacement as cwr
n,m,q=map(int,input().split())
abcd = [list(map(int,input().split())) for _ in range(q)]

def calscore(A):
    score = 0
    for a,b,c,d in abcd:
        if A[b-1] -A[a-1] ==c:
            score += d
    return score

ans =0
for A in cwr(range(1,m+1),n):
    ans = max(ans, calscore(A))
print(ans)

Measured memory_bytes: 73740
N = int(input())
info = []
for i in range(N):
  list = []
  S_i,P_i=input().split()
  list.append(S_i)
  list.append(100-int(P_i))
  list.append(i)
  info.append(list)
info.sort()
for i in range(N):
  print(info[i][2]+1)

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


int main()
{
    ll n; cin>>n;
   map<string,ll>mp;
   for(ll i=0;i<n;i++)
   {
       string s; cin>>s;
       mp[s]++;
   }
   cout<<"AC x "<<mp["AC"]<<endl;
   cout<<"WA x "<<mp["WA"]<<endl;
   cout<<"TLE x "<<mp["TLE"]<<endl;
   cout<<"RE x "<<mp["RE"]<<endl;
}


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

int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	for (int& i : a) cin >> i;
	int q;
	cin >> q;
	for (int i = 0; i < q; ++i) {
		int k;
		cin >> k;
		cout << lower_bound(a.begin(), a.end(), k) - a.begin() << ' ' << upper_bound(a.begin(), a.end(), k) - a.begin() << endl;
	}
}


Measured memory_bytes: 3084
# writer解(c++)を写経した．answerのfor文のところ何やってるかさっぱりわかりませんが…
# https://atcoder.jp/contests/m-solutions2020/submissions/15122924
import sys
input = sys.stdin.readline
INF = 10**13


def main():
    N = int(input())
    X = []
    Y = []
    P = []
    for _ in range(N):
        a, b, c = (int(i) for i in input().split())
        X.append(a)
        Y.append(b)
        P.append(c)
    X_dist = [[0]*N for _ in range(1 << N)]
    Y_dist = [[0]*N for _ in range(1 << N)]

    # bitという道路群を建設したときの，各集落の評価距離
    # bit 001001 とかの1が立っている集落に道を作る
    for bit in range(1 << N):
        for i in range(N):
            X_dist[bit][i] = P[i]*abs(X[i])
            Y_dist[bit][i] = P[i]*abs(Y[i])
            for k in range(N):
                if bit & (1 << k):
                    X_dist[bit][i] = \
                        min(X_dist[bit][i], P[i]*abs(X[i] - X[k]))
                    Y_dist[bit][i] = \
                        min(Y_dist[bit][i], P[i]*abs(Y[i] - Y[k]))

    # これはなに？
    answer = [INF] * (N+1)
    for i in range(1 << N):
        cnt = 0
        for j in range(N):
            if (i >> j) & 1:
                cnt += 1
        j = i
        while j >= 0:
            j &= i
            cost = 0
            for k in range(N):
                if not((i >> k) & 1):
                    cost += min(X_dist[j][k], Y_dist[i - j][k])
            answer[cnt] = min(answer[cnt], cost)
            j -= 1

    for ans in answer:
        print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 88732
using System;
using System.Collections.Generic;
using System.Linq;
 
class DDiceinLine {
    static void Main(string[] args) {
        int[] nk = Console.ReadLine().Trim().Split(' ').Select(a => int.Parse(a)).ToArray();
        double[] plist = Console.ReadLine().Trim().Split(' ').Select(a => double.Parse(a)).ToArray();
        double w_rtn = 0;
        int wk_i = 0;
        double wk = 0;
        for (int i = 0; i < nk[0] - (nk[1] - 1); i++){
            if (i == 0) {
                for (int j = 0; j < nk[1]; j++) {
                    w_rtn += plist[i + j];
                    wk_i = i;
                }
                wk = w_rtn;
            } else {
                if (w_rtn < (wk - plist[i - 1] + plist[i + nk[1] - 1])) {
                    w_rtn = wk - plist[i - 1] + plist[i + nk[1] - 1];
                    wk_i = i;
                }
                wk = wk - plist[i - 1] + plist[i + nk[1] - 1];
            }
        }
        double rtn = 0;
        for (int i = 0; i < nk[1]; i++) {
            rtn += (plist[wk_i + i] + 1) / 2;
        }
        System.Console.WriteLine(String.Format("{0:0.000000000000}", rtn));
    }
}

Measured memory_bytes: 36316