akhauriyash/Code-Regression huggingface dataset:
n, m = map(int, input().split())
a = list(map(int, input().split()))
bc = []
for _ in range(m):
    b, c = map(int, input().split())
    bc.append([b, c])
a.sort()
bc.sort(reverse=True, key=lambda x: x[1])
cnt = 0
for i in range(m):
    for j in range(bc[i][0]):
        if bc[i][1] > a[cnt]:
            a[cnt] = bc[i][1]
            if cnt == n - 1:
                break
            cnt += 1
        else:
            break
print(sum(a))


Measured memory_bytes: 25548
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <ctime>
#include <map>
#include <stack>
#include <sstream>
#include <set>
#include <cmath>
#include <functional>
#include <numeric>

using namespace std;

int main(void)
{
	int a, n;

	cin >> n;
	cin >> a;

	cout << n*n - a << endl;

	return 0;

}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    void run() {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] aArr = new int[n];

        for (int i = 0; i < n; i++) {
            aArr[i] = sc.nextInt();
        }

        long[][][] dp = new long[n + 1][3][2];
        for (long[][] x : dp) {
            for (long[] x2 : x) {
                Arrays.fill(x2, Long.MIN_VALUE);
            }
        }
        dp[1][0][1] = aArr[0];
        dp[1][1][0] = 0;

        // dp[i][j][k] ... i番目までの整数列で、ひとつおきじゃないやつj個、(直前の数を使っていなければk = 0)の最大値
//        debug(dp);
        for (int i = 1; i < n; i++) {
            dp[i + 1][0][1] = dp[i][0][0] + hoge(dp[i][0][0], aArr[i]);
            dp[i + 1][1][1] = dp[i][1][0] + hoge(dp[i][1][0], aArr[i]);
            dp[i + 1][2][1] = dp[i][2][0] + hoge(dp[i][2][0], aArr[i]);
            dp[i + 1][0][0] = dp[i][0][1];
            dp[i + 1][1][0] = Math.max(dp[i][0][0], dp[i][1][1]);
            dp[i + 1][2][0] = Math.max(dp[i][1][0], dp[i][2][1]);
        }

        List<Long> list;
        if (n % 2 == 0) {
            // o x o x o x
            // x o x o x o
            // o x x o x o
            list = Arrays.asList(dp[n][0][0], dp[n][1][0],
                    dp[n][0][1], dp[n][1][1]);
        } else {
            // x o x o x o x
            // o x x x o x o
            // x x o x o x o
            list = Arrays.asList(dp[n][0][0], dp[n][1][0], dp[n][2][0],
                    dp[n][0][1], dp[n][1][1], dp[n][2][1]);

        }
        System.out.println(Collections.max(list));
    }

    long hoge(long i, long j) {
        return i == Long.MIN_VALUE ? 0 : j;
    }

    void debug(Object... os) {
        System.err.println(Arrays.deepToString(os));
    }

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


Measured memory_bytes: 84560
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <iomanip>
#include <climits>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<PII> VPI;
typedef vector<PLL> VPL;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define pf push_front
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ub upper_bound
#define lb lower_bound

int main(){
  string T;
  cin>>T;
  rep(i,T.size()){
    if(T[i]=='?') cout<<'D';
    else cout<<T[i];
  }
  cout<<endl;
}


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

using namespace std;

typedef long long ll;
typedef vector <int> vi;
typedef vector <ll> vl;
typedef pair <ll, ll> dl;
typedef pair <int, int> ii;
typedef vector <ii> vii;
typedef vector <vi> graph;

int n;
ll mat[100010][3];
ll dp[100010][3];

ll solve(int r, int c) {
	if (r == n - 1) {
		return mat[r][c];
	}
	if (dp[r][c] != -1) return dp[r][c];
	ll temp, mayor = -1;
	for (int i = 0; i < 3; ++i)
	{
		if (i == c) continue;
		temp = solve(r + 1, i);
		mayor = temp > mayor ? temp : mayor;
	}
	return dp[r][c] = mat[r][c] + mayor;
}

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

	cin >> n;
	for (int i = 0; i < n; ++i)
	{
		for (int j = 0; j < 3; ++j)
		{
			cin >> mat[i][j];
		}
	}
	for (int i = 0; i < 100010; ++i)
	{
		for (int j = 0; j < 3; ++j)
		{
			dp[i][j] = -1;
		}
	}
	ll temp, mayor = -1;
	for (int i = 0; i < 3; ++i)
	{
		temp = solve(0, i);
		mayor = temp > mayor ? temp : mayor;
	}
	cout << mayor << "\n";
    return 0;
}


Measured memory_bytes: 11136
#include "bits/stdc++.h"
using namespace std;
int main() {
	long long N, M, bx, x, by, y, XCount = 0, YCount = 0;
	const long long MOD = 1e9 + 7;
	cin >> N >> M >> bx;
	for (int i = 1; i < N; i++) {
		cin >> x;
		XCount += i * (N - i) * (x - bx);
		XCount = XCount % MOD;
		bx = x;
	}
	cin >> by;
	for (int i = 1; i < M; i++) {
		cin >> y;
		YCount += i * (M - i) * (y - by);
		YCount = YCount % MOD;
		by = y;
	}
	cout << (XCount * YCount) % MOD;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define mod 1000000007
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
ll k,fact[3000001],inv[3000001],rez;
string s;
ll pw(ll a, ll b)
{
    ll rez=1;
    while(b)
    {
        if(b%2)
            rez=(rez*a)%mod;
        a=(a*a)%mod;
        b/=2;
    }
    return rez;
}
ll combi(ll a, ll b)
{
    if(a<b)
        return 0;
    ll r=(fact[a]*inv[b])%mod;
    r=(r*inv[a-b])%mod;
    return r;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>k>>s;
    fact[0]=1;
    inv[0]=pw(1,mod-2);
    for(ll i=1;i<=3000000;i++)
    {
        fact[i]=(fact[i-1]*i)%mod;
        inv[i]=pw(fact[i],mod-2)%mod;
    }
    ll n=k+s.size();
    ll nrelem=s.size();
    for(ll i=0;i<=n-nrelem;i++)
    {
        ll ans=pw(26,i)%mod;
        ans=(ans*combi(n-i-1,nrelem-1))%mod;
        ans=(ans*pw(25,n-i-nrelem))%mod;
        rez=(rez+ans)%mod;
    }
    cout<<rez;
    return 0;
}


Measured memory_bytes: 51216
#include <bits/stdc++.h>
#include <cmath>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define been(ix) (ix).begin(),(ix).end()
using namespace std;
typedef long long ll; 
typedef vector<int> vi;
typedef vector<long long> vl;
const ll INF = 1e18;
typedef pair<int,int> P;
#define foreach(ix,i) for(auto& (ix) : (i))
typedef long double ld;
int main(){
  ll n;
  cin>>n;
  vi a(n);
  vl cnt(n+1,0);
  rep(i,n){
    cin>>a[i];
    cnt[a[i]]++;
  }
  ll ans =0;
  rep(i,n+1){
    ll x = cnt[i];
    if(x>0){
    ans+=(x*(x-1))/2;
    }
  }
  rep(i,n){
    ll x = cnt[a[i]];
    ll res=ans-(x*(x-1))/2;
    res +=((x-1)*(x-2))/2;
    cout<<res<<endl;
  }

}

Measured memory_bytes: 4992
from collections import defaultdict

D,G=map( int, raw_input().split() )
P=[ map( int, raw_input().split() ) for i in range(D) ] 

N=10**6
dp= [   [ float("inf") for i in range(N+1)] for idx in range(D+1)  ]
dp[0][0]=0

for idx, x  in enumerate(P):
	m=idx+1	#money
	p,c=x[0], x[1]/100
	for i in range(N,-1,-1):
		if dp[idx][i]!=float("inf"):
			for j in range(p,-1,-1):	# j= problems count   , idx = score of a problem
				if j==p:
					dp[idx+1][i+m*j+c]=min( dp[idx+1][i+m*j+c] , dp[idx][i]+j )
				else:
					dp[idx+1][i+m*j]=min( dp[idx+1][i+m*j] , dp[idx][i]+j )


ans=float("inf")

for i in range(G/100,N):
	ans=min(ans, dp[-1][i])

print ans
	




Measured memory_bytes: 182036
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define MAX 2000000
#define I (1<<30)

int H, A[MAX+1];

void maxH(int i){int l, r, largest;
  l = 2*i;
  r = 2 * i +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]);
    maxH(largest);
  }
}

int extract(){
  int max;
  if(H < 1) return -I;
  max = A[1];
  A[1] = A[H--];
  maxH(1);
  return max;
}

void inc(int i, int key){
  if(key < A[i]) return;
  A[i] = key;
  while(i > 1 && A[i/2] < A[i]){
    swap(A[i], A[i/2]);
    i = i/2;
  }
}

void insert(int key){
  H++;
  A[H] = -I;
  inc(H, key);
}

int main(){
  int key;
  char com[10];

  while(1){
    scanf("%s", com);
    if(com[0] == 'e' && com[1] == 'n') break;
    if(com[0] == 'i'){
      scanf("%d", &key);
      insert(key);
    }
    else{
      printf("%d\n", extract());
    }
  }

  return 0;
}



Measured memory_bytes: 6600
def gcd(a,b)
	if(a>b)
		return gcd(b,a)
	end
	if(b%a == 0)
		return a
	else
		return gcd(a,b%a)
	end
end
N,X=gets.chomp.split(' ').map{|n| n.to_i}
A=gets.chomp.split(' ').map{|n| (n.to_i-X).abs}
puts A.inject(A[0]){|g,a| gcd(g,a)}


Measured memory_bytes: 9476
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define MT make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define RT return
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;

template<int MOD>
class ModInt {
public:
    ModInt() :value(0) {}
    ModInt(long long val) :value((int)(val<0 ? MOD + val%MOD : val%MOD)) { }

    ModInt& operator+=(ModInt that) {
        value = value + that.value;
        if (value >= MOD)value -= MOD;
        return *this;
    }
    ModInt& operator-=(ModInt that) {
        value -= that.value;
        if (value<0)value += MOD;
        return *this;
    }
    ModInt& operator*=(ModInt that) {
        value = (int)((long long)value * that.value % MOD);
        return *this;
    }
    ModInt &operator/=(ModInt that) {
        return *this *= that.inverse();
    }
    ModInt operator+(ModInt that) const {
        return ModInt(*this) += that;
    }
    ModInt operator-(ModInt that) const {
        return ModInt(*this) -= that;
    }
    ModInt operator*(ModInt that) const {
        return ModInt(*this) *= that;
    }
    ModInt operator/(ModInt that) const {
        return ModInt(*this) /= that;
    }
    ModInt pow(long long k) const {
        ModInt n = *this, res = 1;
        while (k) {
            if (k & 1)res *= n;
            n *= n;
            k >>= 1;
        }
        return res;
    }
    ModInt inverse() const {
        long long a = value, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b;
            swap(a, b);
            u -= t * v;
            swap(u, v);
        }
        return ModInt(u);
    }
    int toi() const { return value; }

private:
    int value;
};
typedef ModInt<1000000007> mint;
ostream& operator<<(ostream& os, const mint& x) {
    os << x.toi();
    return os;
}
void solve() {
    int N, M;
    cin >> N >> M;
    vi X(N*M + 1, -1), Y(N*M + 1, -1);

    auto f = [&](int n, vi &x) {
        rep(i, n) {
            int a;
            cin >> a;
            if (x[a] != -1) {
                cout << 0 << endl;
                exit(0);
            }
            x[a] = i;
        }
    };
    f(N, X);
    f(M, Y);

    mint ans = 1;
    int row = 0, col = 0;
    for (int i = N * M; i >= 1; --i) {
        if (X[i] != -1 && Y[i] != -1) {
            row++;
            col++;
        } else if (X[i] != -1) {
            ans *= col;
            row++;
        } else if (Y[i] != -1) {
            ans *= row;
            col++;
        } else {
            ans *= row * col - (N*M - i);
        }
    }
    cout << ans << endl;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}

Measured memory_bytes: 8064
package main

import (
	"fmt"
)

func main() {
	var a, b, c int
	fmt.Scan(&a)
	fmt.Scan(&b)
	fmt.Scan(&c)

	fmt.Println(check(a, b, c))
}

func check(a, b, c int) string {
	if c-a-b > 0 && 4*a*b < (c-a-b)*(c-a-b) {
		return "Yes"
	} else {
		return "No"
	}
}


Measured memory_bytes: 512
import sys
array_abc = list(map(int,input().split()))
K = int(input())

if not ( 1 <= min(array_abc),max(array_abc) <= 50 ):
    sys.exit()
if not ( 1 <= K <= 10 ):
    sys.exit()

option = max(array_abc)
for I in range(K):
    option = option * 2

print(sum(array_abc) + option - max(array_abc))

Measured memory_bytes: 9116
import java.io.IOException;
import java.io.InputStream;
import java.util.*;
import java.lang.Math;

public class Main {
    public static void main(String[] args) {
        FS reader = new FS();
        // write reader
        int N = reader.nextInt();
        System.out.println((double)((N+1)/2)/(double)N);
    }

    // Read Class
    static class FS {
        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() { return hasNextByte() ? buffer[ptr++] : -1;}
        private boolean isPrintableChar(int c) {return 33 <= c && c <= 126;}
        private void skipUnprintable() {while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
    
        public boolean hasNext() { skipUnprintable(); 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 int nextInt() {
            return (int)nextLong();
        }
        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();
            }
        }
    }
}



Measured memory_bytes: 23124
#include <iostream>
#include <string>

using namespace std;

int main(void) {

	string word;
	int count = 0;

	cin >> word;

	while (1) {
		string sent;

		cin >> sent;
		if (sent == "END_OF_TEXT") break;

                for(int i=0; i<sent.length(); i++){
                   if(sent[i] >= 'A' && sent[i] <= 'Z')
                      sent[i] = sent[i]  + 32;
                }
		if (sent == word) count++;


		
	}

	cout << count << endl;

	return 0;
}

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

#define FOR(i, j, k) for (int i = j; i < k; i++)
#define REP(i, j) FOR(i, 0, j)
#define fst first
#define snd second
#define pb push_back
#define eb emplace_back
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;

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;
}

template <typename T> istream &operator>>(istream &is, vector<T> &vec) {
  for (T &x : vec)
    is >> x;
  return is;
}

int main() {

  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(10);
  cout << fixed;

  int n, m;
  cin >> n >> m;
  vi a(n);
  cin >> a;

  sort(all(a));

  vector<pair<int, int>> p(m);
  REP(i, m) cin >> p[i].second >> p[i].first;

  sort(rall(p));

  int idx = 0;
  bool isover = false;
  REP(i, m) {
    auto bc = p[i];

    // cout << "pair: " << bc.first << " " << bc.second << endl;

    REP(j, bc.second) {
      if (bc.first > a[idx]) {
        a[idx++] = bc.first;
      } else {
        isover = true;
        break;
      }
    }

    if (isover)
      break;
  }

  ll ans = 0;
  REP(i, n) ans += a[i];

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1408
import math
def S(a,b,c):
	s = (a+b+c)/2
	return math.sqrt(s*(s-a)*(s-b)*(s-c))
	
while True:
	try:
		x1,y1,x2,y2,x3,y3,xp,yp = map(float, raw_input().split())
		a = math.sqrt((x1-x2)**2+(y1-y2)**2)
		b = math.sqrt((x1-x3)**2+(y1-y3)**2)
		c = math.sqrt((x2-x3)**2+(y2-y3)**2)
		xa = math.sqrt((x3-xp)**2+(y3-yp)**2)
		xb = math.sqrt((x2-xp)**2+(y2-yp)**2)
		xc = math.sqrt((x1-xp)**2+(y1-yp)**2)
		if S(a,xb,xc)+S(b,xc,xa)+S(c,xa,xb)-S(a,b,c) > 0.0000001:
			print "NO"
		else:
			print "YES"
	except:
		break

Measured memory_bytes: 4448
X, Y, A, B, C = map(int, input().split())
p = sorted(map(int, input().split()), reverse=True)[:X]
q = sorted(map(int, input().split()), reverse=True)[:Y]
r = list(map(int, input().split()))

ans = sum(sorted(p+q+r, reverse=True)[:X+Y])
print(ans)

Measured memory_bytes: 107980
#include<stdio.h>
int main(void){
int N, sum=0;
scanf("%d",&N);
/*while(N){
    dig= N%10;
    sum+=dig;
    N/=10;
}*/
for(int i=0;i<=N;i++){
if(i>=1 && i<=9){
     sum++;
}else if(i>=100 && i<=999) {
    sum++;
}else if  (i>=10000 && i<=99999) {
    sum++;
}
}
printf("%d\n",sum);
return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        System.out.print(a*b+ " ");
        System.out.println(2*(a+b));
    }
}



Measured memory_bytes: 25964
#include <bits/stdc++.h>
#include <complex>
#include <queue>
#include <set>
#include <list>
#include <chrono>
#include <random>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <stack>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> p32;
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<vector<ll> > vv64;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
ll MOD = 1e9+7;
#define forn(i,e) for(ll i = 0; i < e; i++)
#define forsn(i,s,e) for(ll i = s; i < e; i++)
#define rforn(i,s) for(ll i = s; i >= 0; i--)
#define rforsn(i,s,e) for(ll i = s; i >= e; i--)
#define ln "\n"
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define INF LLONG_MAX

ll mpow(ll a, ll b){
	if(b==0) return 1;
	ll t1 = mpow(a,b/2);
	t1 *= t1;
	t1 %= MOD;
	if(b%2) t1 *= a;
	t1 %= MOD;
	return t1;
}

void solve(){
	ll n,a,b,c,d;
	cin >> n >> a >> b >> c >> d;
	string s;
	cin >> s;
	bool b1 = true,b2 = true, b3=false;
	forsn(i,a+1,c+1) {
		if(s[i-2]=='#' && s[i-1]=='#') b1 = false;
	}
	forsn(i,b+1,d+1) {
		if(s[i-2]=='#' && s[i-1]=='#') b2 = false;
	}
	if(c<d) b3 = true;
	else{
		// ll st = -1;
		// ll e = -1;
		// ll prev = 0;
		// rforn(i,a-1){
		// 	if(prev && s[i]=='#'){
		// 		st = i+2;
		// 		break;
		// 	}
		// 	else{
		// 		if(s[i]=='#') prev = 1;
		// 		else prev = 0;
		// 	}
		// }
		// if(st==-1) st = 0;
		// prev = 0;
		// forn(i,c-1){
		// 	if(prev && s[i]=='#'){
		// 		e = i-2;
		// 		break;
		// 	}
		// 	else{
		// 		if(s[i]=='#') prev = 1;
		// 		else prev = 0;
		// 	}
		// }
		// if(e==-1) e = (ll)s.size();
		forsn(i,b-2,d-1){
			if(s[i]=='.' && s[i+1]=='.' && s[i+2]=='.'){
				b3 = true;
				break;
			}
		}
	}
	if(b1 && b2 && b3) cout << "Yes" << ln;
	else cout << "No" << ln;
}


int main()
{
	ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll t=1;
    // cin >> t;
    forn(i,t) solve();
    return 0;
}

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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a < b) ? (a = b, 1) : 0;}
template<class T>bool chmin(T &a, const T &b) { return (b < a) ? (a = b, 1) : 0;}

using ll = long long;
using R = long double;
const R EPS = 1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r) {return (r > EPS) - (r < -EPS);}
inline R sq(R x) {return sqrt(max(x, 0.0L));}

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

// Problem Specific Parameter:

int main(void) {
	int q;
	cin >> q;

	rep(loop, q) {
		ll a, b, c, d;
		cin >> a >> b >> c >> d;
		c--, d--;

		const ll total = a + b;
		const ll num = max(a, b);
		const ll den = min(a, b) + 1;
		const ll k = (num + den - 1) / den;

		ll low = 0, high = a + 1;
		while (high - low > 1) {
			const ll mid = (low + high) / 2;
			const ll na = a - mid;
			const ll nb = b - (mid - 1) / k;

			if (na >= 0 and nb >= 0 and nb <= (na + 1) * k)
				low = mid;
			else
				high = mid;
		}

		const ll border = low + (low - 1) / k;
		//cerr << low << endl;

		string ans = "";
		rep(i, c, d + 1) {
			if (i < border) {
				if (i % (k + 1) != k)
					ans += 'A';
				else
					ans += 'B';
			} else {
				if ((total - 1 - i) % (k + 1) != k)
					ans += 'B';
				else
					ans += 'A';
			}
		}
		cout << ans << endl;
	}

	return 0;
}

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

typedef long long ll;

int n;
double dp[20][3][3];
int dx[] = {-1,1,0,0};
int dy[] = {0,0,1,-1};

int main(){
  while(cin>>n,n){
    char a,b,c;
    cin>>a>>b>>c;
    int sx = (a - 'A') % 3;
    int sy = (a - 'A') / 3;
    int gx = (b - 'A') % 3;
    int gy = (b - 'A') / 3;
    int tx = (c - 'A') % 3;
    int ty = (c - 'A') / 3;

    memset(dp,0,sizeof(dp));
    dp[0][sx][sy] = 1;

    rep(i,n){
      rep(j,3){
        rep(k,3){
          if(dp[i][j][k] == 0) continue;
          rep(d,4){
            int nx = j + dx[d];
            int ny = k + dy[d];
            if(3>nx && nx>=0 && 3>ny && ny>=0 && (nx!=tx || ny!=ty)){
              dp[i+1][nx][ny] += dp[i][j][k] / 4;
            }
            else{
              dp[i+1][j][k] += dp[i][j][k] / 4;
            }
          }
        }
      }
    }

    printf("%.8f\n",dp[n][gx][gy]);
  }
}

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

// input
int N, T;
vector<int> t;


void input() {
    cin >> N >> T;
    t = vector<int>(N);
    rep(i, N) cin >> t[i];
}


int main() {
    input();
    ll ans = 0;
    rep(i, N - 1) {
        int x = min(T, t[i + 1] - t[i]);
        ans += x;
    }
    ans += T;
    cout << ans << endl;
}


Measured memory_bytes: 3932
(let ((a (read))
      (b (read))
      (c (read))
      (k (read)))
  (declare (ignore c))
  (cond ((<= k a)
         (format t "~A~%" k))
        ((<= k (+ a b))
         (format t "~A~%" a))
        (t
         (format t "~A~%" (- a (- k a b))))))


Measured memory_bytes: 24288
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }

int N, P;
int cnt_odd = 0;
int cnt_even= 0;

ll solve() {
  if (cnt_odd == 0) {
    if (P == 0) return pow(2, cnt_even);
    if (P == 1) return 0;
  }
  return pow(2, N-1);
}

void _main() {
  cin >> N >> P;
  rep(i, 0, N) {
    int t; cin >> t;
    if (t % 2 == 0) cnt_even++;
  }
  cnt_odd = N - cnt_even;
  cout << solve() << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef pair<ll,ll> P;
#define rep(i,n) for(ll i = 0; i < ll(n); i++)
#define all(v) v.begin() , v.end()
#define inputv(v,n) rep(i,n){\
    ll x;\
    cin>>x;\
    v.push_back(x);\
    }
const ll INF=99999999999999;
const ll MOD=1000000007;
ll c,d,e,f,p,t,ans=0;
 
 
ll n,m,r;
vector<P> gragh[3000];
vl A,B,C;
vl cost(3000,INF);
 
void input(void){
    cin>>n>>m>>r;
    rep(i,m){
        cin>>c>>d>>e;
        gragh[c].push_back(make_pair(d,e));
    }
}
 
ll solve(void){
    cost[r]=0;
    vl renewed(3000,0);
    rep(k,n){
    rep(i,n){
        rep(j,gragh[i].size()){
            cost[gragh[i][j].first]=min(cost[i]+gragh[i][j].second,cost[gragh[i][j].first]);
        }
    }
    }
 
    rep(i,n){
        rep(j,gragh[i].size()){
            if(cost[i]+gragh[i][j].second<cost[gragh[i][j].first]&&cost[i]+gragh[i][j].second<INF/2){
                cout<<"NEGATIVE CYCLE"<<endl;
                return 0;
            }
        }
    }
 
    rep(i,n){
    	if(cost[i]>INF/2)cout<<"INF"<<endl;
        else cout<<cost[i]<<endl;
    }
    return 0;
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    input();
    solve();
}


Measured memory_bytes: 3352
#include <bits/stdc++.h>
using namespace std;
int main()
 
{
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	int a,b;
	cin>> a>>b;
	if(a==1&&b!=1)
		{
           cout<<"Alice"<<"\n";

		}
	else if(b==1 && a!=1)

	{
		cout <<"Bob"<<"\n";

	}
	else if(a==b)
	{
		cout<<"Draw"<<"\n";
	}
	else if (a>b)
	{
		cout<<"Alice"<<"\n";
	}
	else 
	{
		cout <<"Bob"<<"\n";
	}
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {

	private static final char BORDER = '#';

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int h = scanner.nextInt();
			int w = scanner.nextInt();
			String[] a = new String[h];
			IntStream.range(0, h).forEach(i -> a[i] = scanner.next());
			char[] border = new char[w + 2];
			Arrays.fill(border, BORDER);
			System.out.println(border);
			IntStream.range(0, h).forEach(i -> System.out.println(BORDER + a[i] + BORDER));
			System.out.println(border);
		}
	}
}


Measured memory_bytes: 26836
S = input()
T = input()

n = len(S)
m = len(T)

ans = m

for i in range(n-m+1):
    xs = S[i:i+m]
    cnt = 0
    for j in range(m):
        if xs[j] != T[j] :
            cnt += 1
    ans = min(ans, cnt)
    
print(ans)
    
    

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

#define fi first
#define se second
#define U unsigned
#define P std::pair<int,int>
#define LL long long
#define pb push_back
#define MP std::make_pair
#define all(x) x.begin(),x.end()
#define CLR(i,a) memset(i,a,sizeof(i))
#define FOR(i,a,b) for(int i = a;i <= b;++i)
#define ROF(i,a,b) for(int i = a;i >= b;--i)
#define DEBUG(x) std::cerr << #x << '=' << x << std::endl

const int MAXN = 2e6 + 5;
char S[MAXN],T[MAXN];
int n;std::queue<int> q;

int main(){
    scanf("%d",&n);
    scanf("%s",S+1);scanf("%s",T+1);
    bool flag = 1;
    FOR(i,1,n) flag &= (S[i]==T[i]);
    if(flag){
        puts("0");
        return 0;
    }
    int up = n,down = n;
    int tag = 0,ans = 0;
    while(down){
        while(down && T[down-1] == T[down]) down--;
        while(up && (up > down || S[up] != T[down])) up--;
        if(up == 0){
            puts("-1");
            return 0;
        }
        while(!q.empty() && q.front()+tag >= down) q.pop();
        if(up != down) q.push(up-tag);
        ans = std::max(ans,(int)q.size()+1);
        tag--;--down;
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 6272
#include <cstdio>
#include <vector>
#include <cstring>
#include <algorithm>

using namespace std;

typedef long long lli;
typedef pair<int, int> pii;

#define fi first
#define se second

const int maxn = 6;
const int maxc = 50;
const int maxs = 1 << maxn - 1;

int L[maxn];
lli f[252][maxn * maxc + 1];
vector<int> state[maxn];
int cnt[maxs], id[maxs][maxs], tot;
pii Map[252];

int main()
{
	int n, c;
	scanf("%d%d", &n, &c);
	int nc = n * c;
	for (int i = 0; i < n; ++ i) scanf("%d", L + i);
	sort(L, L + n);
	int all = (1 << n - 1) - 1;
	for (int i = 0; i <= all; ++ i)
	{
		cnt[i] = cnt[i >> 1] + (i & 1);
		state[cnt[i]].push_back(i);
	}
	for (int i = 0; i < n; ++ i)
	{
		vector<int> &cur = state[i];
		int size = cur.size();
		for (int j = 0; j < size; ++ j)
			for (int k = 0; k < size; ++ k)
			{
				Map[tot].fi = cur[j];
				Map[tot].se = cur[k];
				id[cur[j]][cur[k]] = tot ++;
			}
	}
	f[0][L[n - 1] * n] = 1;
	for (int i = 0; i < nc; ++ i)
	{
		int pos = i % n;
		if (!pos) continue;
		-- pos;
		for (int j = 0; j < tot; ++ j)
		{
			int cur0 = Map[j].fi, cur1 = Map[j].se;
			if (cur1 >> pos & 1) continue;
			int nxt1 = cur1 | (1 << pos);
			for (int r = i; r <= nc; ++ r)
			{
				int w = f[j][r];
				if (!w) continue;
				for (int k = 0; k < n - 1; ++ k)
				{
					if (cur0 >> k & 1) continue;
					int nxt0 = cur0 | (1 << k);
					f[id[nxt0][nxt1]][min(nc, max(r, i + L[k] * n))] += w;
				}
			}
		}
	}
	double ans = f[tot - 1][nc];
	for (int i = 0; i < n - 1; ++ i) ans /= c;
	for (int i = 1; i < n; ++ i) ans /= i;
	printf("%.19lf\n", ans);
	return 0;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin >> s;
    int ans = INT_MAX;
    for(int i = 0; i < s.length()-2; i++){
        int tmp = (s[i]-'0')*100+(s[i+1]-'0')*10+(s[i+2]-'0');
        //cout << tmp << " ";
        tmp = abs(753-tmp);
        //cout << tmp << endl;
        ans = min(ans,tmp);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3608
import sys
from itertools import product

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    ABCD = list(input())

    for pattern in product(["+", "-"], repeat=3):
        pattern = list(pattern) + [" "]
        fomula = []
        for op, num in zip(pattern, ABCD):
            fomula.append(num)
            fomula.append(op)
        fomula = "".join(fomula).rstrip()
        if eval(fomula) == 7:
            print(fomula + "=" + "7")
            break
        else:
            continue
        break


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 3064
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int INF = 1LL << 30;
int MOD = 1e9+7;
main(){
    int N;
    cin >> N;
    vector<int> A(N),B(N),C(N);
    for(int i = 0;i < N;i++)cin >> A[i];
    for(int i = 0;i < N;i++)cin >> B[i];
    for(int i = 0;i < N;i++)cin >> C[i];
    sort(A.begin(),A.end());
    sort(C.begin(),C.end());
    ll cnt = 0;
    for(int i = 0;i < N;i++){
        auto itr_a = lower_bound(A.begin(),A.end(),B[i]);
        auto itr_c = upper_bound(C.begin(),C.end(),B[i]);
        cnt += distance(A.begin(),itr_a) * distance(itr_c,C.end()); 
    }
    cout << cnt << endl;
}

Measured memory_bytes: 1536
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<algorithm> // sort
#include<map> // pair
#include<cmath>
#include<cstring>
#include<set>
using namespace std;
typedef long long ll;
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 (a>b) { a=b; return 1; } return 0; }
#define rep(i, n) REP(i, 0, n)
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define all(x) (x).begin(),(x).end()
const ll mod = 1e9+7;
const int INF = 1e9;
const ll INFLONG = 1e18;
ll tmp1,tmp2;
int main(){
  ll n;
  cin >> n;
  vector<ll> vec(n);
  ll mini = INFLONG;
  ll ans = -INFLONG;
  rep(i,n){
    cin >> vec[i];
    chmax(ans,vec[i]-mini);
    chmin(mini,vec[i]);
  }
  cout << ans << endl;

}



Measured memory_bytes: 4408
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author yassin
 */

#include <bits/stdc++.h>

using namespace std;

class dwacon5_c {
public:
    void solve(istream& in, ostream& out) {
        int N, Q;
        string S;
        in >> N >> S >> Q;
        for (int i = 0; i < Q; ++i) {
            int k;
            in >> k;
            long long res = 0;
            long long d = 0, m = 0, dm = 0;
            for (int i = 0; i < N; ++i) {
                if (S[i] == 'D') {
                    d += 1;
                } else if (S[i] == 'M') {
                    m += 1;
                    dm += d;
                } else if (S[i] == 'C') {
                    res += dm;
                }
                if (i >= k - 1) {
                    int j = i - (k - 1);
                    if (S[j] == 'D') {
                        dm -= m;
                        d -= 1;
                    } else if (S[j] == 'M') {
                        m -= 1;
                    }
                }
            }
            out << res << "\n";
        }
    }
};

int main() {
	std::ios::sync_with_stdio(false); cin.tie(nullptr);
	dwacon5_c solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 1948
#include<bits/stdc++.h> 
//#define <- プログラムの文字列を置換する
//typedef <- 新しい型に名前を付けるためのキーワード

using namespace std;

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

const long long MOD = 1e9 + 7;
const long long INF = 1e15;
const int INF_INT = 1e9;

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 TYPE>
struct edge{
    TYPE to,cost; 
    edge(TYPE t,TYPE c){
        to = t;
        cost = c;
    }
};


int main(){
    int K;
    cin >> K;
    int even = 0;
    int odd = 0;
    for(int i = 1; i <= K; i++){
        if(i % 2 == 0) even++;
        else odd++;
    }
    cout << even * odd << endl;
    return 0;
}


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

int main()
{
    int H1, M1, H2, M2, K;
    cin >> H1 >> M1 >> H2 >> M2 >> K;
    int M_diff = M2 - M1;
    if (M_diff < 0)
    {
        --H2;
        M_diff += 60;
    }
    int H_diff = H2 - H1;
    if (H_diff < 0)
        H_diff += 24;

    cout << H_diff * 60 + M_diff - K << endl;
}

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

using namespace std;

#define int long long
#define all(v) begin(v), end(v)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for(int i = (int)(s); i < (int)(n); i++)
#define min(...) min({__VA_ARGS__})
#define max(...) max({__VA_ARGS__})

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int n;
  cin >> n;
  char d[1010];
  int l[1010];
  vector< pair<int, int> > yes;
  rep(i, n) {
    cin >> d[i] >> l[i];
    if(d[i] == 'y') yes.push_back(make_pair(l[i], i));
  }
  sort(all(yes));
  bool used[1010] = {};
  int cnt = 0;
  rep(i, yes.size()) {
    int len, idx;
    tie(len, idx) = yes[i];
    if(used[idx]++) continue;
    int j = idx-1;
    while(j >= 0) {
      if(d[j] == 'n' && l[j] >= len) break;
      used[j]++; j--;
    }
    j = idx+1;
    while(j < n) {
      if(d[j] == 'n' && l[j] >= len) break;
      used[j]++; j++;
    }
    cnt++;
  }
  cout << cnt << endl;

  return 0;
}

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

int main() {
 char c;
  cin >> c;
  if (c == 'a'|| c == 'e'|| c == 'i'|| c =='o' || c =='u' ){
    cout << "vowel";
  }
  else{
    cout << "consonant";
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<int, int>;
using VI = vector<int>;
const int mod = 1e9 + 7;
int add(int u, int v) {
  return (u + v) % mod;
}
int sub(int u, int v) {
  return add(u, mod - v);
}
int mul(int u, int v) {
  return u * 1ll * v % mod;
}
int pwr(int a, int n) {
  int r = 1;
  for (; n > 0; n >>= 1) {
    if (n & 1) r = mul(r, a);
    a = mul(a, a);
  }
  return r;
}
int inv(int a) {
  return pwr(a, mod - 2);
}

const int N = 4e5 + 10;
int fact[N], invf[N];
void prec() {
  fact[0] = invf[0] = 1;
  for (int i = 1; i < N; i++) {
    fact[i] = mul(fact[i - 1], i);
    invf[i] = inv(fact[i]);
  }
}
int choose(int n, int r) {
  if (n < r) return 0;
  return mul(fact[n], mul(invf[r], invf[n - r]));
}

int main() {
#ifdef LOCAL_EXEC
//	freopen("sample.in", "r", stdin);
//	freopen("sample.out", "w", stdout);
#else
  ios_base::sync_with_stdio(false); cin.tie(NULL);
#endif
  prec();
  
  int n, k; cin >> n >> k;
  if (k >= n - 1) {
    cout << choose(2 * n - 1, n - 1) << endl;
    return 0;
  }
  if (k == 1) {
    cout << choose(n, 2) << endl;
    return 0;
  }
  
  int ans = 0;
  for (int e = 0; e <= k; e++) {
    int cur = mul(choose(n, e), choose(n - 1, e));
    ans = add(ans, cur);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3456
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; ++i)
#define REPP(i, n) for(int i = 1; i <= n; ++i)
#define REPR(i, n) for(int i = n-1; i >= 0; --i)
#define FOR(i, m, n) for(int i = m; i < n; ++i)
#define ALL(v) v.begin(), v.end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1000000007;
const ll INF = 1000000000;

int main() {
    vector<int> ab(4, 0);
    REP(i,6) {
        int tmp;cin >> tmp;tmp --;
        ab[tmp] ++;
    }
    sort(ALL(ab));
    bool ans = (ab[0]==1 && ab[1]==1 && ab[2]==2 && ab[3]==2);
    cout << (ans ? "YES" : "NO") << endl;
    return 0;
}

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

const int MAX = 1000001; 

struct Query 
{ 
	int l, r, idx; 
}; 

bool cmp(Query x, Query y) 
{ 
	return x.r < y.r; 
} 

void update(int idx, int val, int bit[], int n) 
{ 
	for (; idx <= n; idx += idx&-idx) 
		bit[idx] += val; 
} 

int query(int idx, int bit[], int n) 
{ 
	int sum = 0; 
	for (; idx>0; idx-=idx&-idx) 
		sum += bit[idx]; 
	return sum; 
} 

void answeringQueries(int arr[], int n, Query queries[], int q) 
{ 
	int bit[n+1]; 
	memset(bit, 0, sizeof(bit)); 

	int last_visit[MAX]; 
	memset(last_visit, -1, sizeof(last_visit)); 

	int ans[q]; 
	int query_counter = 0; 
	for (int i=0; i<n; i++) 
	{ 
		if (last_visit[arr[i]] !=-1) 
			update (last_visit[arr[i]] + 1, -1, bit, n); 

		last_visit[arr[i]] = i; 
		update(i + 1, 1, bit, n); 

		while (query_counter < q && queries[query_counter].r == i) 
		{ 
			ans[queries[query_counter].idx] = 
					query(queries[query_counter].r + 1, bit, n)- 
					query(queries[query_counter].l, bit, n); 
			query_counter++; 
		} 
	} 

	for (int i=0; i<q; i++) 
		cout << ans[i] << endl; 
} 

int main() 
{ 
	int n,q;
	cin>>n>>q;
	int a[n];
	for(int i=0;i<n;i++)
	cin>>a[i];
	Query queries[q];
	for(int i=0;i<q;i++){
		int left,right;
		cin>>left>>right;
		queries[i].l=(left-1);
		queries[i].r=(right-1);
		queries[i].idx=i;
	} 
	//int q = sizeof(queries)/sizeof(queries[0]); 
	sort(queries, queries+q, cmp); 
	answeringQueries(a, n, queries, q); 
	return 0; 
} 


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

using namespace std;

int main() {
	vector<int> furui(300000, 0);
	furui[0] = furui[1] = 1;
	for (long long int i = 2; i*i <= 300000; i++) {
		if (furui[i] == 0) {
			for (long long int j = 2; i*j < 300000; j++) {
				furui[i*j] = 1;
			}
		}
	}
	vector<long long int> sosu(300000, 0);
	for (long long int i = 2; i < 300000; i++) {
		sosu[i] = sosu[i - 1];
		if (furui[i] == 0) {
			sosu[i]++;
		}
	}
	long long int n;
	while (cin >> n) {
		if (n == 0) {
			break;
		}
		cout << sosu[2 * n] - sosu[n] << endl;
	}
	return 0;
}


Measured memory_bytes: 6096
// AOJ 1286: Expected Allowance
// 2017.10.13 bal4u@uu

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

int m, k;

int combi(int n, int s)
{
	int i, t;

	if (n == 0)	return s-k > 0 ? s-k : 1;
	for (t = 0, i = 1; i <= m; i++) t += combi(n-1, s+i);
	return t;
}

int main()
{
	int n;

	while (scanf("%d%d%d", &n, &m, &k) && n > 0)
		printf("%.8lf\n", combi(n, 0) / pow(m, n));
	return 0;
}

Measured memory_bytes: 1832
#include <iostream>
#include <cstdio>
#include <queue>
using namespace std;
int main(){
  queue<int>que;

  int n,m;
  while( cin >> n >> m,n + m){
    while(!que.empty())que.pop();
    for(int i = 1 ; i <= n ; i++ )que.push(i);
    int cnt = 0;
    while(que.size() != 1){
      cnt++;
      if(cnt == m){
	cnt = 0;
	que.pop();
      } else {
	que.push(que.front());
	que.pop();
      }
    }
  cout << que.front() << endl;
  }
  return 0;
}

Measured memory_bytes: 1224
#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>
#include<complex>
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 = 4000001;
const long double eps = 1E-14;

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 fr;
	ll to;
	ll d;
};

class mint {
	long long x;
public:
	mint(long long x = 0) : x((x% MOD + MOD) % MOD) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint& a) {
		if ((x += a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator-=(const mint& a) {
		if ((x += MOD - a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator*=(const  mint& a) {
		(x *= a.x) %= MOD;
		return *this;
	}
	mint operator+(const mint& a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint& a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint& a) const {
		mint res(*this);
		return res *= a;
	}

	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime MOD
	mint inv() const {
		return pow(MOD - 2);
	}
	mint& operator/=(const mint& a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint& a) const {
		mint res(*this);
		return res /= a;
	}

	friend ostream& operator<<(ostream& os, const mint& m) {
		os << m.x;
		return os;
	}
};

mint pw(mint a, ll b) {
	if (b == 0) { return 1; }
	mint ret = pw(a, b >> 1);
	ret *= ret;
	if (b & 1) { ret *= a; }
	return ret;
}

typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;

typedef vector<mint> vmint;
typedef vector<vector<mint>> vvmint;
typedef vector<vector<vector<mint>>> vvvmint;

//////////////////////////////////////
ll D = 365;
ll T = 26;//タイプ数
vll c(T + 1);
vvll s(D + 1, vll(T + 1));

vvll last(D + 1,vll(T+1,0));

ll score(vll t) {

	repn(i, D) {
		repn(j, T) {
			if (t[i] == j) { last[i][j] = i; }
			else { last[i][j] = last[i - 1][j]; }

			cout << i << " " << j << last[i][j] << endl;
		}
	}

	ll ret = 0;
	repn(i, D) {
		ret += s[i][t[i]];
		repn(j, T) {
			ret -= c[j] * (i - last[i][j]);
		}
	}

	return ret;
	
}


int main() {
	cin >> D;
	repn(i, T) cin >> c[i];
	repn(i, D)repn(j, T) cin >> s[i][j];

	vll ans(D + 1);
	
	repn(i, D) {
		ll id = 1;
		repn(j, T) {
			if (s[i][id] < s[i][j]) { id = j; }
			}
		ans[i] = id;
	}

	repn(i, D) {
		cout << 1; if (i != D) { cout << endl; }
	}

	//cout << score(ans) << endl;
	
}

Measured memory_bytes: 3812
#include <bits/stdc++.h>
using namespace std;
using Int = int_fast64_t;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	Int n, m; cin >> n >> m;
	vector<Int> a, b, c;
	for(Int i=0; i<m; ++i){
		Int ta, tb; cin >> ta >> tb;
		a.push_back(ta);
		b.push_back(tb);
		Int t = 0;
		for(Int j=0; j<tb; ++j){
			Int tc; cin >> tc;
			t |= (1<<(tc-1));
		}
		c.push_back(t);
	}
	vector<Int> dp(1<<n, 1e9);
	dp[0] = 0;
	for(Int i=0; i<(1<<n); ++i){
		for(Int j=0; j<m; ++j){
			Int t = i | c[j];
			if(dp[t] > dp[i] + a[j])
				dp[t] = dp[i] + a[j];
		}
	}
	if(dp[(1<<n)-1] == 1e9) cout << -1 << "\n";
	else cout << dp[(1<<n)-1] << "\n";
//	for(Int i=0; i<m; ++i)
//		cout << a[i] << " " << b[i] << " " << bitset<8>(c[i]) << "\n";
//	for(Int i=0; i<(1<<n); ++i)
//		cout << bitset<8>(i) << " " << dp[i] << "\n";
}

Measured memory_bytes: 384
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main (String[] args) throws IOException
	{
		BufferedReader input = new BufferedReader (new InputStreamReader (System.in));

		String originStr = input.readLine();

		String upperStr = originStr.toUpperCase();

		String lowerStr = originStr.toLowerCase();

		char[] originChar = originStr.toCharArray();

		char[] upperChar = upperStr.toCharArray();

		char[] lowerChar = lowerStr.toCharArray();

		//1文字ずつ比較し、大文字小文字を逆転して表示する
		for(int num = 0; num < originChar.length; num++)
		{
			if(originChar[num] != upperChar[num])
			{
				System.out.print(upperChar[num]);
			}
			else
			{
				System.out.print(lowerChar[num]);
			}
		}

		System.out.println();

	}
}



Measured memory_bytes: 25228
#include<iostream>

#define REP(i,j,k) for( int i=j; i<k; i++ )
#define rep(i,j) REP(i,0,j)

using namespace std;

int ru(int x){
	
	int ans = x;
	if( x%10 ) ans += 10-x%10;
	
	return ans;
	
}


int main(){
	
	int a[5],ans=0;
	
	rep(i,5) cin >> a[i];
	
	rep(i,5) ans = min(a[i]-ru(a[i]),ans);
	
	rep(i,5) ans += ru(a[i]);
	
	cout << ans << endl;
	
	return 0;
	
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	int i,no,s,ss,sum,br = 1;
	while(1){
		for(i = 1; i <= 5;i++){
			scanf("%d%d",&s,&ss);
			if (s == 0 && ss == 0){
				br = 0;
				break;
			}
			if (i == 1){
				no = 1;
				sum = s + ss;
			}
			else if ((s + ss) > sum){
				no = i;
				sum = s + ss;
			}
		}
		if (br == 0){
			break;
		}
		switch (no){
			case 1:
				printf("A ");
				break;
			case 2:
				printf("B ");
				break;
			case 3:
				printf("C ");
				break;
			case 4:
				printf("D ");
				break;
			case 5:
				printf("E ");
				break;
		}
		printf("%d\n",sum);
	}
	return 0;
}

Measured memory_bytes: 600