akhauriyash/Code-Regression huggingface dataset:
/*~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
*$* WRITER:kakitamasziru/OxOmisosiru *$*
~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=*/
#ifdef LOCAL_JUDGE
#define _GLIBCXX_DEBUG //FOR THE DEBUG! COMMENT OUT THIS WHEN SUBMITTING!
#endif
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <iomanip>
#include <limits>//setprecision
//#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
//#include <unordered_set> //unordered_set
#include <stack> // stack
#include <deque> // deque
#include <math.h>//pow,,,
#include <cmath>//abs,,,
#include <bitset> // bitset
#define endl "\n";
//It is so troublesome that I include bits/stdc++.h !
using namespace std;

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; }
const long long INF = 10010010010010;
const long long MOD = 1000000007;
typedef pair<int,int> P;

//Solve N^M. This, mod_pow use Iterative Square Method.
long long mod_pow(long long N, long long M) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % MOD, M / 2);
    //最下位ビット(*N)が1の時は単独でNをかける
    if (M & 1) res = (res * N) % MOD;

    return res %= MOD;
}

long long gcd(long long a, long long b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
    return a / gcd(a, b) * b ;
}

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

    int a,b,c,d,e;cin >> a >> b >> c >> d >> e;
    if(a == 0) cout << 1 << endl;
    if(b == 0) cout << 2 << endl;
    if(c == 0) cout << 3 << endl;
    if(d == 0) cout << 4 << endl;
    if(e == 0) cout << 5 << endl;
}


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

int main(){
    int n;
    cin >> n;
    if(n % 2 == 0) printf("%.10f", 0.5);
    else printf("%.10f", (double)((n+1)/2)/(double)n);
}

Measured memory_bytes: 3704
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,m,a[101],tot;
bool cmp(int x,int y)
{
	return x>y;
}
signed main()
{
	scanf("%lld%lld",&n,&m);
	for(int i=1;i<=n;i++)
	scanf("%lld",&a[i]),tot+=a[i];
	sort(a+1,a+n+1,cmp);
	for(int i=1;i<=m;i++)
	if(a[i]*4*m<tot)
	{
		printf("No");
		return 0;
	}
	printf("Yes");
	return 0;
}

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

#define LL long long
const int mod = 1e9 + 7;
char s[100005];

LL power(LL x, LL y) { 
    int res = 1;
    x = x % mod;
    while (y > 0) { 
        if (y & 1) res = (res * x) % mod; 
        y = y >> 1;
        x = x * x % mod; 
    } 
    return res; 
} 

int main() {
    ios::sync_with_stdio(0), cin.tie(0);
    
    cin >> s + 1; int n = strlen(s + 1), cnt = 0, ans = 0;
    for(int i = 1; i <= n; i++) {
        if(s[i] == '1') {
            (ans += power(2LL, cnt) * power(3LL, n - i) % mod) %= mod;
            cnt++;
        }
    }    
    (ans += power(2LL, cnt)) %= mod;
    cout << ans;    
}

Measured memory_bytes: 3744
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<climits>
#include<set>
#include<utility>
#include<typeinfo>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef set<int> S;
#define rep(i, n) for(int i=0; i<n; i++)
const ll MOD=1e9+7;

int main(){

	int a, b;
	cin >> a >> b;
	if(13<=a){
		cout << b << endl;
	} else if(a<=5){
		cout << 0 << endl;
	} else {
		cout << b/2 << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007LL
#define all(x) x.begin() , x.end()

void solve()
{
	ll n; cin >> n;
	ll arr[n]; for (auto &x : arr) cin >> x;
	ll res = 1000, stocks = 0;
	for (int i = 0; i < n; i++) {
		if (i == 0) {
			if ( i + 1 < n and arr[i] < arr[i + 1] and i != n - 1) {
				stocks += (res / arr[i]);
				res -= arr[i] * (res / arr[i]);
			}
		}
		else if (i == n - 1) {
			if (i - 1 >= 0 and arr[i] > arr[i - 1] ) {
				res += stocks * arr[i];
				stocks = 0;
			}
		}
		else {
			if (arr[i] > arr[i - 1] and arr[i] >= arr[i + 1]) {
				res += stocks * arr[i];
				stocks = 0;
			}
			else if (arr[i] <= arr[i - 1] and arr[i] < arr[i + 1])
			{
				stocks += (res / arr[i]);
				res -= arr[i] * (res / arr[i]);
			}
		} //cout << res << "\n";
	}
	cout << res;
}
int32_t main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	ll t = 1; //cin >> t;
	while (t--)
		solve();
	return 0;
}

Measured memory_bytes: 3648
object Main extends App {
  val scanner = new java.util.Scanner(System.in)

  val data = Iterator.continually {
    val H  = scanner.nextInt()
    val W  = scanner.nextInt()

    (H, W)
  }

  val outputs = data.takeWhile(_ != (0, 0)).map {
    case (h, w) =>
      (("#" * w) + "\n") * h
  }

  outputs.foreach(println)
}

Measured memory_bytes: 45060
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in); 
		int N = sc.nextInt();
		int[] nums = new int[N];
		for(int i = 0; i< N ; i++) {
			nums[i] = sc.nextInt();
		}
		Arrays.sort(nums);
		if(!(nums[nums.length/2]-nums[nums.length/2-1]==0)) {
			System.out.println(nums[nums.length/2]-nums[nums.length/2-1]);
		}else {
			System.out.println(0);
		}
	}

}


Measured memory_bytes: 50452
// 物极必反

#include <bits/stdc++.h>

#define append push_back

using namespace std;
using ll = long long;

const int N = 5e5 + 3;
const int M = 1e6 + 7;
const long long MOD = 998244353;
const long long INF = 1e18 + 9;
const int SM = 3e3 + 5;
const int logN = 22, BL = 400;
const long double EPS = 1e-14;
const int dx[] = {1, 0, 0, -1, -1, 1, -1, 1};
const int dy[] = {0, 1, -1, 0, -1, 1, 1, -1};

void debug(){
	cerr << "\n";
}
template<typename Type1, typename... Type2>
void debug(Type1 a, Type2... b) {
    cerr << a << " ";
    debug(b...);
}

int main(){
    // freopen(".in", "r", stdin);
    // freopen(".out", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    long long n; cin >> n;
    vector<long long> a(n);
    
    for(long long i = 0; i < n; i++){
        cin >> a[i];
    }
    
    long long ans = INF;
    for(long long p = 1; p <= 100; p++){
        long long sum = 0;
        for(long long i = 0; i < n; i++){
            sum += (a[i] - p) * (a[i] - p);
        }
        ans = min(ans, sum);
    }
    
    cout << ans;

    return 0;
}


Measured memory_bytes: 3656
import java.io.*;
import java.util.Scanner;
 
public class Main {
 
  public static void main(String[] args) {
 
    try {
      // 標準入力受け取り
      Scanner scan = new Scanner(System.in);      
      Long sum      = Long.parseLong(scan.next());
      Long blue     = Long.parseLong(scan.next());
      Long red      = Long.parseLong(scan.next());
      Long result   = sum/(blue+red)*blue;
      
      // 「合計と青+赤の余り」と「青いボールの数」を比較し、小さい数を加算
      result += Math.min(sum%(blue+red), blue);

      System.out.println(result);
      
    } catch (Exception e) {     
      System.out.print("error");
    }
  }
}

Measured memory_bytes: 23892
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<(n);i++)
#define rep2(i,a,n) for(int i=a;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 INFL = 1e18;
const int INF = 1001001001; 
typedef pair<int,int> P;
#define foreach(ix,i) for(auto& (ix) : (i))
typedef long double ld;
const int mod =1000000007;
//const int PI = acos(-1);
int main(){
	int n;cin>>n;
	vi me(n,0);
	rep(i,n){
		me[abs(i-(n-i-1))]++;
	}
	vi cn(n,0);
	rep(i,n){
		int a;cin>>a;
		cn[a]++;
	}
	rep(i,n){
		if(cn[i]!=me[i]){
			cout<<0<<endl;
			return 0;
		}
	}
	ll ans =1;
	rep(i,n){
		ans*=max(1,me[i]);
		ans%=mod;
	}
	cout<<ans<<endl;

}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long int
#define fast  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define w(t)            int t; cin>>t; while(t--)
const int mod = 1000000007;
bool comp(pair<ll,ll>& a, pair<ll,ll>& b)
{
    if(a.second == b.second)
    return a.first > b.first;
    else
    return b.second < a.second;
}
int main()
{
    fast
    ll n;
    cin>>n;
    vector<ll> v(n+1);
    for(ll i=0;i<n;i++)
    {
        cin>>v[i];
    }
    sort(v.rbegin(),v.rend());
    ll sum = v[0];
    ll cnt = 1;
    for(ll i=2;i<=n-1;i+=2)
    {
        if(i<n-1)
        {
            sum += 2*v[cnt];
            cnt++;

        }
        else if(i==n-1)
        {
            sum += v[cnt];
        }

    }
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 4756
s = gets.chomp.split("").map(&:to_i)
od = ev = 0
s.each_with_index do |e, i|
  od += e if i.odd?
  ev += e if i.even?
end
od_max = (s.size)/2.floor
ev_max = (s.size+1)/2.floor
puts [od_max - od + ev, ev_max - ev + od].min

Measured memory_bytes: 7676
#include <iostream>
#include <algorithm>
#include <string>
#define int long long
using namespace std;
signed main() {
	int h, w; cin >> h >> w;
	bool a[200], b[200]; char m[200][200];
	for (int j = 0; j < w; j++)b[j] = 1;
	for (int i = 0; i < h; i++){
		a[i] = 1;
		for (int j = 0; j < w; j++) {
			cin >> m[i][j];
			if (m[i][j] == '#') {
				a[i] = 0;
				b[j] = 0;
			}
		}
	}
	a[199] = 0;
	for (int i = 0; i < h; i++) {
		if (a[i])continue;
		for (int j = 0; j < w; j++) {
			if (!b[j])cout << m[i][j];
		}
		cout << endl;
		a[199] = 1;
	}
	if (!a[199])cout << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();

int main() {
    int n;
    string s;
    cin >> n;
    char pre = '@';
    unordered_set<string> visit;
    bool valid = true;
    for(int i = 0; i < n; i++) {
        cin >> s;
        if (visit.count(s)) {
            valid = false;
        }
        visit.insert(s);
        if (i > 0 && s[0] != pre) {
            valid = false;
        }
        pre = s.back();
    }
    if (valid)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}



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

namespace ConsoleApp1
{
	class Program
	{
		static void Main(string[] args)
		{
			var inputs = Console.ReadLine().Split(' ').Select(input => int.Parse(input)).ToArray();
			Console.WriteLine(inputs[0] * inputs[1] % 2 == 0 ? "No" : "Yes");
			return;
		}
	}

}


Measured memory_bytes: 13268
let () = Scanf.scanf "%d\n" @@ fun n ->
  let cnt = Array.make 1000001 0 in
  for i=1 to n do
    Scanf.scanf " %d" @@ fun a -> cnt.(a) <- 1 + cnt.(a)
  done;
  let dp = Array.make 1000001 1 in
  for a=0 to 1000000 do
    if cnt.(a) <> 1 then dp.(a) <- 0;
    if 0 < cnt.(a) then
      let rec mark i =
        if i <= 1000000 then
          (cnt.(i) <- 0; mark (i+a)) in
      mark (a)
  done;
  Printf.printf "%d\n" @@ Array.fold_left (+) 0 dp

Measured memory_bytes: 21796
SENTINEL = 9999
SIZE = (60, 80, 100, 120, 140, 160, SENTINEL)
WEIGHT = (2, 5, 10, 15, 20, 25, SENTINEL)
PRICE = (600, 800, 1000, 1200, 1400, 1600, SENTINEL)


def check(item, base_list, output):
    for index, base in enumerate(base_list):
        if item <= base:
            return output[index]


while True:

    input_count = int(input())

    if input_count == 0:
        break

    sum = 0

    for _ in range(input_count):
        vertical, horizontal, height, weight = [int(item) for item in input().split(" ")]
        size = vertical + horizontal + height

        price = max(check(size, SIZE, PRICE), check(weight, WEIGHT, PRICE))

        if price != SENTINEL:
            sum += price

    print(sum)



Measured memory_bytes: 5624
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define ALLG(v) v.begin(), v.end() ,greater<int>()
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
ll GCD(ll x, ll y) { return y ? GCD(y, x % y) : x; }
ll LCM(ll x, ll y) { return x * y / GCD(x, y); }
ll GetDigit(ll num) {
	ll digit = 0;
	while (num != 0) {
		num /= 10;
		digit++;
	}
	return digit;
}


int facctorialMethod(int k) {
	int sum = 1;
	for (int i = 1; i <= k; ++i)
	{
		sum *= i;
	}
	return sum;
}

using namespace std;
int main() {

	int K, A, B;


	cin >> K >> A >> B;
	
	string ans = "NG";

	for (int i = A; i <= B; i++)
	{
		if (i % K == 0) {
			ans = "OK";
			break;
		}
	}


	cout << ans << endl;
}

Measured memory_bytes: 3596
#include <stdio.h>
#define HEN 1
int main(){
  int A[100][100];
  int a,b,c,d,i,j,k,n;

  scanf("%d",&n);

  for(i=0; i < n;i++){
    for(j=0; j < n;j++){
      A[i][j]=0;
    }
  }

  for(i=0; i < n;i++){

    scanf("%d %d",&c,&d);
    c=c-1;
    
    for(j=0; j < d; j++){
      
      scanf("%d",&k);
      k=k-1;
      A[c][k]=HEN;
    }
  }

  for(i=0; i < n;i++){
    for(j=0; j < n;j++){
      if(j){
        printf(" ");
      }
      printf("%d",A[i][j]);
    }
    printf("\n");
  }
  return 0;
}



Measured memory_bytes: 2112
function Main(input) {
  input.trim();
  input = input.split(" ").map(Number);
  input.sort();
  var ans = new Array(input[1]).fill(input[0]);
  console.log(ans.join(""));
}Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());
function arr1dto2d (arr){
	for(var i=0;i<arr.length;i++){
    arr[i]=arr[i].split(" ").map(Number);
    }
  return arr;
}


Measured memory_bytes: 7372
#include<iostream>
#include<algorithm>
using namespace std;
struct point{
	long long x;
	long long dis;
};
bool cmp(point a,point b){
	return a.dis<b.dis;
}
int main(){
	long long k,n;
	while(cin>>k>>n){
		point a[n];
		for(int i=0;i<n;i++)
			cin>>a[i].x;
		for(int i=n-1;i>=0;i--){
			if(i==0)
				a[i].dis=a[i].x+k-a[n-1].x;
			else
				a[i].dis=a[i].x-a[i-1].x;
		}
			
		sort(a,a+n,cmp);
		long long sum=0;
//		for(int i=0;i<n;i++)
//			cout<<a[i].dis<<" ";
//		cout<<endl;
		for(int i=0;i<n-1;i++){
			sum+=a[i].dis;
		}
		cout<<sum<<endl;
	}
	return 0;
} 

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

#define ll long long

ll n, a;
int main() {
  ll num = 1, cnt = 0;
  cin >> n;
  for(ll i = 0; i < n; i++) {
      cin >> a;
      if(a == num) {
          num++;
      } else {
          cnt++;
      }
  }
  if(cnt < n) {
      cout << fixed << cnt;
  } else {
      cout << -1;
  }
}


Measured memory_bytes: 384
object Main extends App{
  val sc = new java.util.Scanner(System.in)
  val numR = sc.nextInt
  val numL = sc.nextInt
  val numD = sc.nextInt

  var result = 0
  for(num <- numR to numL if(num % numD == 0)){
    result += 1
  }
  println(result)
}


Measured memory_bytes: 55324
fun main(args: Array<String>) {
    val n = getInt()
    val a = LongArray(n + 1)
    var out = 0L

    (1..n).forEach { k ->
        var i = k
        while (i <= n) {
            a[i]++
            i += k
        }

        out += k * a[k]
    }
    println(out)
}

fun getInt() = readLine()!!.toInt()

Measured memory_bytes: 114668
char buf[99];sz;
int N,A,B;
long mod=1e9+7;
long p(long a,long b){
	long ret=1;
	while(b)
	{
		if(b&1)ret=ret*a%mod;
		b>>=1;
		a=a*a%mod;
	}
	return ret;
}
main()
{
	read(0,buf,99);
	for(;;)
	{
		char c=buf[sz++];
		if(c<'0')break;
		N=N*10+c-'0';
	}
	for(;;)
	{
		char c=buf[sz++];
		if(c<'0')break;
		A=A*10+c-'0';
	}
	for(;;)
	{
		char c=buf[sz++];
		if(c<'0')break;
		B=B*10+c-'0';
	}
	long ans=p(2,N)-1;
	long x=1,y=1;
	for(int i=1;i<=A;i++)
	{
		x=x*(N-i+1)%mod;
		y=y*i%mod;
	}
	ans-=x*p(y,mod-2)%mod;
	for(int i=A+1;i<=B;i++)
	{
		x=x*(N-i+1)%mod;
		y=y*i%mod;
	}
	ans-=x*p(y,mod-2)%mod;
	printf("%d\n",(ans%mod+mod)%mod);
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main(){
   int n;
   cin >> n;
   int mono = n/100;
   int simoni = n%100;
   for(int i=0;i<mono;i++){
       if(simoni >= 5)simoni -= 5;
       else if(simoni == 4)simoni -=4;
       else if(simoni == 3)simoni -=3;
       else if(simoni == 2)simoni -=2;
       else if(simoni == 1)simoni -=1;
       if(simoni == 0){
           cout << 1 << endl;
           return 0;
       }

   }
   cout << 0 << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<string>
#include<unordered_map>
#include <iomanip>
using namespace std;
 
#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j,k
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define sort(a) sort(a.begin(),a.end())
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define sizeoof(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
ll ans=0;llfor;///////////////////////////////////////////////////////////
int main(){
  string S;
  string T="CODEFESTIVAL2016";
  cin>>S;
  int count=0;
  for(int i=0;i<16;i++){
    if(S[i]!=T[i]) count++;
  }
  cout<<count<<endl;
return 0;}


Measured memory_bytes: 3568
#include <stdio.h>

int main(int argc,char* argv[]){
    int x,y,z;
    int i=0;
    scanf("%d %d %d",&x,&y,&z);
    for(i=0;(i*(y+z))<=(x-z);i++);
    printf("%d\n",--i);
    return 0;
}


Measured memory_bytes: 128
import sys
import math
from itertools import accumulate as acc
input=sys.stdin.readline
N=int(input())
a=[[0,0,0]]+[list(map(int,input().split())) for i in range(N)]

for i in range(N):
    dt,dx,dy=[a[i+1][j]-a[i][j] for j in range(3)]
    if abs(dx)+abs(dy)>dt or (abs(dx)+abs(dy)-dt)%2!=0:
        print("No")
        sys.exit()
print("Yes")

Measured memory_bytes: 28120
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
long long inf = 1000000000000;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int main() {
	int n;
	cin >> n;
	int i;
	int a[1000], b[1000], x[1000], y[1000];
	for (i = 0; i < n; i++) {
		cin >> a[i] >> b[i] >> x[i] >> y[i];
	}
	for (i = 0; i < n; i++) {
		if (x[i] >= 5 && y[i] >= 2) {
			int ans = a[i] * x[i] + b[i] * y[i];
			ans *= 8;
			ans /= 10;
			cout << ans << endl;
		}
		else {
			int ans = a[i] * x[i] + b[i] * y[i];
			int ans2 = (max(5, x[i]) * a[i] + max(2, y[i]) * b[i]);
			ans2 *= 8;
			ans2 /= 10;
			cout << min(ans, ans2) << endl;
		}
	}
	return(0);
}


Measured memory_bytes: 3112
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		long mod = 1000000007;
		int n = in.nextInt();
		int k = in.nextInt();
		int[] a = new int[n];
		for(int i=0;i<n;i++) a[i] = in.nextInt();
		long rev = 0;
		for(int i=0;i<n;i++) {
			for(int j=i+1;j<n;j++) {
				if(a[i]>a[j]) rev++;
			}
		}
		long rev2 = 0;
		for(int i=0;i<n;i++) {
			for(int j=0;j<n;j++) {
				if(a[i]>a[j]) rev2++;
			}
		}
		long ans = ((rev2 % mod) * ((((long)k * (long)(k-1))/2) % mod));
		ans = (ans + (rev*k)%mod)%mod;
		System.out.println(ans);
		in.close();

	}

}

Measured memory_bytes: 25956
#include<bits/stdc++.h>
using namespace std;
using Long = long long;

const Long MOD = 1e9 + 7;

int main(){
  int n;
  cin >> n;
  vector<Long> v(n + 1) , ac(n + 1);
  for( int i = 1 ; i <= n ; ++i ) cin >> v[i];
  for( int i = 1 ; i <= n ; ++i ) ac[i] = ( ac[i - 1] + v[i] ) % MOD;
  Long ans = 0;
  for( int i = 2 ; i <= n ; ++i ) {
  	ans = ans + ( v[i] * ac[i - 1] % MOD ) ;
  	ans %= MOD;
  }
  cout << ans ;
  return 0;
}


Measured memory_bytes: 6420
#include <bits/stdc++.h>
using namespace std;
 
 
int main() {
  int N;
  cin >> N;
  
  vector<int> vec(N);
  
  for(int i; i < N; i++){
    int A_i;
    cin >> A_i;
    vec.at(i) = A_i;
  }
  int M = 1;
  for(int i; i < N; i++){
    if( vec.at(i)%6 == 0 ||  vec.at(i)%10 == 0)
      M *= 1;
    else if( vec.at(i)%2 != 0)
       M *= 1;
    else
      M *= 0;
  }
  if(M)
    cout << "APPROVED";
  
  else
    cout << "DENIED";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
LL ma[510][510]={0},sum[510][510];
LL n,m,q;
LL getsum(LL x,LL y){
	LL l1,r1,l2,r2;
	l1=r1=x;l2=r2=y;
	LL i,j,k;
	i=sum[l1-1][r2];
	j=sum[l2][r1-1];
	k=sum[l1-1][r1-1];
	return sum[l2][r2]-i-j+k;
}
int main(){
	LL i,j,k,l,r;
	cin>>n>>m>>q;
	for(i=0;i<m;i++){
		cin>>l>>r;
		ma[l][r]++;
	}
	for(i=1;i<=500;i++){
		for(j=1;j<=500;j++){
			k=sum[i-1][j]+sum[i][j-1]-sum[i-1][j-1];
			sum[i][j]=k+ma[i][j];
		}
	}
	for(i=0;i<q;i++){
		cin>>l>>r;
		cout<<getsum(l,r)<<endl;
	}
	return 0;
}

Measured memory_bytes: 4864
#pragma GCC optimize(3)

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>

using namespace std;

typedef long long ll;

const int maxn = 1000 + 10;
const int inf = 0x3f3f3f3f;

bool cmp(ll x, ll y)
{
	return x > y;
}

ll read()
{
	ll x;
	scanf("%lld", &x);
	return x;
} 

int n, k, a[maxn];

int main()
{
	n = read();
	k = read();
	for(int i = 1; i <= n; i ++)
	{
		a[i] = read();
	}
	ll ans = 0;
	for(int i = 0; i <= min(k, n); i ++)
	{
		for(int j = 0; i + j <= min(k, n); j ++)
		{
			priority_queue<int, vector<int>, greater<int> >q;
			ll sum = 0;
			for(int x = 1; x <= i; x ++)
			{
				q.push(a[x]);
				sum += 	a[x];
			}
			for(int y = 1; y <= j; y ++)
			{
				q.push(a[n-y+1]);
				sum+=a[n-y+1];
			} 
			int c = k - i - j;
			while(c --)
			{
				if(q.empty())
				{
					break;
				}
				if(q.top() < 0)
				{
					sum -= q.top();
					q.pop();
				}
				else
				{
					break;
				}
			}
			ans = max(ans,sum);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main()
{
	int n, a, b;
	
	scanf("%d %d %d", &n, &a, &b);
	
	if(n*a==b)printf("%d", b);
	else if(n*a<b)printf("%d", n*a);
	else if(n*a>b)printf("%d", b);
	
return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <cstdio>

using namespace std;

int main(){
  int n;
  cin >> n;
  double p[n];
  int i,j;
  for(i=0;i<n;i++){
    cin >> p[i];
  }
  
  double dp[n+1][n+1];
  for(i=0;i<=n;i++)dp[0][i]=0.0;
  dp[0][0]=1.0;
  for(i=1;i<=n;i++)dp[i][0]=dp[i-1][0]*(1.0-p[i-1]);
  for(i=1;i<=n;i++){
    for(j=1;j<=n;j++){
      if(j<=i)dp[i][j]=dp[i-1][j]*(1.0-p[i-1])+dp[i-1][j-1]*p[i-1];
      else dp[i][j]=0.0;
    }
  }

  double ret = 0.0;
  for(i=n/2+1;i<=n;i++)ret+=dp[n][i];
  printf("%.12f\n",ret);;
  return 0;
}

Measured memory_bytes: 70528
#include <bits/stdc++.h>
#include <vector>
using namespace std;
int main() {
  int n,k;
  cin >> n >> k;
  vector <int> b;
  for (int i=0; i<n; i++) {
    int t = 0;
    cin >> t;
    b.push_back(t);
  }
  int a = 0;
  for (int j=0; j<n; j++) {
    if (b[j] <= k-b[j]) {
      a += b[j]*2;
    } else {
      a += (k-b[j])*2;
    }
  }
  cout << a;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int p;
		while ((p = in.nextInt()) > 0) {
			for (int i = 0; i < 9; i++) {
				p -= in.nextInt();
			}
			System.out.println(p);
		}
	}
}

Measured memory_bytes: 17196
#include <bits/stdc++.h>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
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>
vector<T> table(int n, T v) { return vector<T>(n, v); }

template <class... Args>
auto table(int n, Args... args) {
    auto val = table(args...);
    return vector<decltype(val)>(n, move(val));
}
const ll INF = 1e9;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a[7] = {0,105,135,165,189,195,201};
    int n;
    cin >> n;
    rep(i,7){
        if (a[i] <= n && n < a[i+1]){
            PRINT(i);
            break;
        }
    }
}

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

using namespace std;

int main(){
    int n; cin >> n;
    int flag = 0;
    while(n > 0){
        if(n % 7 == 0) flag = 1;
        n = n - 4;
    }
    if(flag == 1 || n == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include <string>
#include <vector>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
 
using namespace std;
 
int main()
{
  string S;
  cin >> S;
  
  int value = 100000;
  for(int i=0; i<S.size()-2; ++i) {
    int n = (S[i] - '0');
    n = n*10 + (S[i+1] - '0');
    n = n*10 + (S[i+2] - '0');
    
    value = min(value, abs(753 - n));
  }
  
  cout << value << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ff          first
#define ss          second
#define ll         	long long int
#define pb          push_back
#define ar 			array
#define mp 			make_pair
#define f(i,n)   	for(ll i =0;i<n;i++)
#define inf 		INT_MAX
#define pll 		pair<ll, pair<ll,ll>>
const ll INF = 1e18;
void init(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE 
		freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#endif
}
void solve(){
	
	ll N;
	cin>>N;
	vector<ll> A(N+1 , 0);
	ll sum = 0;
	for(ll i = 0;i<=N;i++){
		cin>>A[i];
		sum += A[i];
	}
	ll ans  = 0;
	ll space  = 1;
	for(ll i = 0;i<=N;i++,space *= 2,space = min(space , sum)){

		ans += min(sum , space);
		
		sum -= A[i];
		space -= A[i];
		if(space < 0){
			cout<<"-1"<<endl;
			return;
		}
	}

	cout<<ans<<endl;
	return;

}
int main(){
	init();
	ll t = 1;
	//cin>>t;
	for(ll i=1;i<=t;i++){
		//cout<<"Case #"<<i<<": ";
		solve();
	}
}


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

using namespace std;

using ll = long long;
constexpr int mo = 1e9+7;
constexpr int inf = 1<<30;
constexpr ll infl = 1ll<<60;
constexpr ll mo2 = 998244353;
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int n;
    cin>>n;
    cout << 1ll*(n/500)*1000 + 1ll*(((n%500)/5)*5) << endl; 
    return 0;
}

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

using namespace std;
#define ll long long int
#define ull unsigned long long int
#define module 1000000007


int main()
{
    int a,b;
    cin>>a>>b;
    if(2*b>=a) cout<<0<<endl;
    else cout<<(a-(2*b))<<endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,k,i,j;
  cin>>n>>k;
  int ar[n];int win[k+1];
  memset(win,0,sizeof(win));
  for(i=0;i<n;i++)
  {
    cin>>ar[i]; win[ar[i]]=1;
  }
  for(i=0;i<=k;i++)
    if(win[i]==1)
      	continue;
  	else
    	for(j=0;j<n;j++)
      		if(i-ar[j]<0)
        		continue;
      		else if(win[i-ar[j]]==0)
        		win[i]=1;
  if(win[k]==1)
    cout<<"First";
  else
    cout<<"Second";
  return 0;
}

Measured memory_bytes: 640
N = int(input())

l4 = N // 4
l7 = N // 7

ck = 0

for i in range(l4+1):
  for j in range(l7+1):
    
    if i * 4 + j * 7 == N:
      ck = 1
      
if ck == 0:
  print("No")
else:
  print("Yes")

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

int main(){
	
	int H,W,N,ans,big;
    std::cin >> H >> W >> N;
    if(H>W)big = H;
    else big = W;
    
    if(N%big==0)ans = N/big;
    else ans = N/big + 1;
    
    std::cout << ans;
	return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES 
#include<iomanip> 
#include<cmath>  
#include<iostream>
#include<fstream>
#include<vector>
#include<algorithm>
#include<numeric>
#include<bitset>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<queue>
#include<deque>
#include<stack>
using namespace std;
typedef long long ll;
#define repi(i,a,b) for(ll i = (ll)(a) ; i < (ll)(b) ; i++)
#define repd(i,a,b) for(ll i = (ll)(a) ; i > (ll)(b) ; i--)
#define rd(x) cin >> x
#define wr(x)  cout << x
#define wrln(x) cout << x << endl
const ll MAX_10p5 = 100010;
const ll MAX_10p9 = 1000000010;
const ll MAX_10p18 = 1000000000000000010;
const ll MOD = 1000000007;
const ll m4x[4] = { 1,0,-1,0 };
const ll m4y[4] = { 0,1,0,-1 };
const ll m8x[8] = { 1,1,0,-1,-1,-1,0,1 };
const ll m8y[8] = { 0,1,1,1,0,-1,-1,-1 };
const ll m9x[9] = { 1,1,0,-1,-1,-1,0,1,0 };
const ll m9y[9] = { 0,1,1,1,0,-1,-1,-1,0 };

struct edge {
	ll from, to, cost;
	bool operator<(const edge& right) const {
		return cost < right.cost;
	}
};
struct point {
	ll x, y;
	bool operator<(const point& right) const {
		return x == right.x ? y < right.y : x < right.x;
	}
};

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

ll t[2 * MAX_10p5], ans;

int main() {
	ll N, T;
	cin >> N >> T;
	repi(i, 0, N) rd(t[i]);
	repi(i, 1, N) {
		ans += min(T, t[i] - t[i - 1]);
	}
	ans += T;
	wrln(ans);
	return 0;
}


Measured memory_bytes: 1792
n = int(input())
h = list(map(int,input().split()))
 
mizuyari = 0
for i in range(sorted(h)[n-1]):
    maenohana = False
    for j in range(n):
        if not maenohana and i+1<=h[j]:
            mizuyari += 1
        maenohana = i+1<=h[j]
print(mizuyari)

Measured memory_bytes: 3060
//C++14 (Clang 3.8.0)

#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string>
#include <climits>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int maxn=100001;
bool used[51];
vector<int> g[51];
int desa,desb;
void dfs(int s){
  if(used[s])return ;
  used[s]=true;
  for(int i=0;i<g[s].size();i++){
    if((desa==s and desb==g[s][i]) or (desb==s and desa==g[s][i]))continue;
    dfs(g[s][i]);
  }
}

int main(){
  int n,m;
  cin>>n>>m;
  P edges[10000];
  for(int i=0;i<m;i++){
    int a,b;
    cin>>a>>b;
    a--;
    b--;
    g[a].push_back(b);
    g[b].push_back(a);
    edges[i]=P(a,b);
  }
  int res=0;
  for(int i=0;i<m;i++){
    fill(used,used+n,false);
    desa=edges[i].first;
    desb=edges[i].second;
    dfs(0);
    for(int j=0;j<n;j++){
      if(!used[j]){res++;
      break;}
    }
  }
  cout<<res<<endl;
  return 0;
}


Measured memory_bytes: 384
#!/usr/bin/python
# -*- coding: utf-8 -*-

# 1
s = raw_input()
a, b = s.split()

ret = False
for c in xrange(1, 4):
    i = int(a) * int(b) * c
    if i % 2 == 1:
        ret = True
print 'Yes' if ret else 'No'


Measured memory_bytes: 2568
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>

using namespace std;
int main()
{
    int n; cin >> n;
    vector<double> v(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
    
    std::sort(v.begin(), v.end());
    
    double avg = v[0];
    for (int i = 1; i < n; ++i)
    {
        avg = (avg + v[i]) / 2.0;
    }
    cout << avg << endl;
    
    return 0;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const unsigned int M = 1000000007;
int main(){
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    string str;
    while(cin>>str){
        for(int i=0;i<str.length();i++){
            if(str[i]==',')cout<<" ";
            else cout<<str[i];
        }
        cout<<endl;
    }
}


Measured memory_bytes: 256
/**
 *      ///----- My Info -----///
 *      Clock: nowl
 *      Code by: Ernesto Abreu
 *      Codeforces User: Ernest0_0Abreu
 *      Country: Cuba
 *      E-mail: ernestoabreup@gmail.com
 *      ©CopyRight
**/
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
        ///----- My Template -----///
///=====================================================================================================================
/// Red-Black Tree
// #include <ext/pb_ds/assoc_container.hpp>  // .find_of_order(x); .order_of_key(x);
// using namespace __gnu_pbds;
// typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update > indexed_set;
/// Typedef
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vii;
/// Function
#define pi (acos(-1))
#define lg2(x) 31-__builtin_clz(x)
#define lgx(x,b) log(b)/log(x)
/// Macros
#define fst first
#define scd second
#define pb push_back
#define left (node<<1)
#define right ((node<<1)+1)
#define sz(x) (int)(x.size())
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
/// Debug
#define _end cout << "\n"
#define debug(x) cerr << #x << " = " << x << " "
/// Constant
const int MAXN = 1e6+7;
const int MOD = 1e9+7;
const ull BASE = 311;
const ld EPS = 1e-9;
const int INF = ((1<<30)-1);
const ll INFLL = ((1ll<<62ll)-1ll);
/// Hash Prime Numbers: 2, 277, 293, 307, 331, 337, 1009, 2027;
/// Module Prime Numbers: 3, 998244353, 1000000007, 1000000009, 1000000021, 1000000033;
///=====================================================================================================================
#define int long long
        ///----- My code -----///



int32_t main (){

    ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
    cout.setf(ios::fixed);cout.precision(0);
//  freopen("a.in", "r", stdin);

    int N;
    cin >> N;
    int sum = 0;
    for(int i = 1; i <= N; i++){
        if(i%3==0 || i%5==0) continue;
        sum+=i;
    }

    cout << sum;

    return 0;
}
/*
Test case:

*/



Measured memory_bytes: 3692
#include<stdio.h>
#include<stdlib.h>
#define centering center=(right-left)/2+left
main(){
	int i,j,s,q,t,sum,left,right,center;
	int n[100000],m[50000];
	scanf("%d",&s);
	for(i=0;i<s;i++){
		scanf(" %d",&j);
		n[i]=j;
	}
	scanf(" %d",&t);
	for(i=0;i<t;i++){
		scanf(" %d",&j);
		m[i]=j;
	}
	sum=0;
	for(j=0;j<t;j++){
		left=0;right=s-1;
		while(left<=right){
			centering;
			if(m[j]==n[center]){
				sum++;break;
			}else{
			if(m[j]<n[center]){
				right=center-1;
			}else{
			if(m[j]>n[center]){
				left=center+1;
			}}}
		}
	}
	printf("%d\n",sum);
	return 0;
}

Measured memory_bytes: 1184
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		float sum = 0;
		for (int y=0; y<n; y++) {
			a[y] = sc.nextInt();
			sum += a[y];
		}
		int p = Math.round(sum/n);
		int res = 0;
		for (int i=0; i<n; i++) {
			res += (a[i] - p)*(a[i] - p);
		}
		System.out.println(res);
		sc.close();
	}

}


Measured memory_bytes: 27256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define ALL(a) a.begin(), a.end()
ll dx[4] = { 0, 1, 0, -1 };
ll dy[4] = { 1, 0, -1, 0 };
const ll INF = 1e14;
const ll MOD = 1e9 + 7;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int N, M;
    cin >> N >> M;
    vector<vector<ll>> jobs(M);
    priority_queue<int> pq;
    ll ans = 0;
    rep(i, N)
    {
        int a, b;
        cin >> a >> b;
        if (a > M) {
            continue;
        }
        jobs[M-a].push_back(b);
    }
    for (int i = M - 1; i >= 0; i--) {
        for (auto& b : jobs[i]) {
            pq.push(b);
        }
        if (!pq.empty()) {
            ans += pq.top();
            pq.pop();
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5632
import numpy as np
N = int(input())
ans = np.zeros((10**4+5))
for i in range(1,100):
  for j in range(1,100):
    for l in range(1,100):
      f = (i+j)**2+(j+l)**2+(l+i)**2
      if((f%2==0) and (f<=2*10**4)):
        ans[int(f/2)] += 1

for i in range(1,N+1):
  print(int(ans[i]))

Measured memory_bytes: 27488
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define EPS (1e-7)
#define INF (1e9)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
const double PI = acos(-1);
const ll MOD = 1000000007;
// const ll MOD = 998244353;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
 
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
///////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N; cin >> N;
    vector<int> P(N),Q(N);
    rep(i,N) cin >> P[i];
    rep(i,N) cin >> Q[i];
    int cntp = 0;
    int cntq = 0;

    vector<int> A(N);
    rep(i,N) A[i] = i+1;
    int k = 0;
    do {
        bool okp = true;
        bool okq = true;
        rep(i,N) {
            if (P[i] != A[i]) okp = false;
            if (Q[i] != A[i]) okq = false;
        }
        if (okp) cntp = k;
        if (okq) cntq = k;
        k++;
    } while (next_permutation(all(A)));

    cout << abs(cntp-cntq) << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<stack>
using namespace std;

int main(){
    
    int n;
    string str1,str2;
    stack<int> st;
    
    cin >> n;
    while(n--){
        cin >> str1 >> str2;
        int i,j,num1,num2,kuri,sum;
        i = str1.size()-1;
        j = str2.size()-1;
        kuri = 0;
        while(i>=0 || j>=0){
            num1 = 0;
            num2 = 0;
            if(i >= 0) num1 = str1[i]-'0';
            if(j >= 0) num2 = str2[j]-'0';
            sum = num1+num2+kuri;
            st.push(sum%10);
            kuri = 0;
            if(sum >= 10) kuri = 1;
            i--;
            j--;
        }
        if(st.size()+kuri > 80){
            cout << "overflow" << endl;
            while(!st.empty()) st.pop();
            continue;
        }
        if(kuri == 1) cout << 1;
        while(!st.empty()){
            cout << st.top();
            st.pop();
        }
        cout << endl;
    }
    
    return(0);
}


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

// Binary Indexed Tree (Fenwick tree)
// O(log n)
template<typename T>
struct BIT {
  int n;
  vector<T> d;
  BIT(int n=0) : n(n), d(n+1) {}
  
  void add(int i, T x=1) {
    for (i++; i <= n; i += i & -i) {
      d[i] += x;
    }
  }
  
  T sum(int i) {
    T x = 0;
    for (i++; i; i -= i & -i) {
      x += d[i];
    }
    return x;
  }
  
  T sum(int l, int r) {
    return sum(r-1) - sum(l-1);
  }
};

int main() {
  int n, q;
  cin >> n >> q;
  
  vector<int> c(n);
  rep(i, n) cin >> c[i];
  
  vector<int> pi(n+1, -1);  // 配列内のある要素が出現したindex
  vector<vector<int>> ps(n);  // 配列内のある要素が二回目以降出現したindexのリスト
  rep(i, n) {
    int l = pi[c[i]];
    if (l != -1) ps[l].push_back(i);  // 配列内のある要素が既に出現していたら
    pi[c[i]] = i;
  }
  
  vector<vector<P>> qs(n);  // query区間のleftを行, rightとquery indexのペアを列に持つ
  rep(qi, q) {
    int l, r;
    cin >> l >> r;
    --l; --r;  // queryは1-index想定で入力されるが, c[n]が0-indexなので合わせる
    qs[l].emplace_back(r, qi);
  }
  
  vector<int> ans(q);
  BIT<int> d(n);
  for (int x = n-1; x >= 0; --x) {
    for (int y : ps[x]) d.add(y, 1);  // BITにおける, index 1からy+1までに現れる重複の総数
    for (P query : qs[x]) {
      int r = query.first, i = query.second;
      ans[i] = (r-x+1) - d.sum(r);  // 区間内の値の種類数は, 区間内の要素数 - 重複の数
    }
  }
  
  rep(i, q) cout << ans[i] << endl;
}

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

const long long INF = 1e18;

int binary_search(long long arr[], int n, long long key) {
  int left = -1;
  int right = n;

  while ( right - left > 1 ) {
    int mid = left + (right - left) / 2;
    if ( arr[mid] >= key ) { right = mid; } else { left = mid; }
  }

  return right;
}

int main() {
  int a, b, q;
  cin >> a >> b >> q;
  long long s[a], t[b];
  for ( int i = 0; i < a; i++ ) { cin >> s[i]; }
  for ( int i = 0; i < b; i++ ) { cin >> t[i]; }

  while ( q-- > 0 ) {
    long long x;
    cin >> x;
    int s_pos = binary_search(s, a, x);
    int t_pos = binary_search(t, b, x);
    long long ans = INF;
    long long len;
    // right_shrine -> right_temple
    if ( s_pos < a && t_pos < b ) {
      len = abs(x - s[s_pos]) + abs(s[s_pos] - t[t_pos]);
      ans = min(len, ans);
    }
    // right_shrine -> left_temple
    if ( s_pos < a && t_pos-1 >= 0 ) {
      len = abs(x - s[s_pos]) + abs(s[s_pos] - t[t_pos-1]);
      ans = min(len, ans);
    }
    // left_shrine -> right_temple
    if ( s_pos-1 >= 0 && t_pos < b ) {
      len = abs(x - s[s_pos-1]) + abs(s[s_pos-1] - t[t_pos]);
      ans = min(len, ans);
    }
    // left_shrine -> left_temple
    if ( s_pos-1 >= 0 && t_pos-1 >= 0 ) {
      len = abs(x - s[s_pos-1]) + abs(s[s_pos-1] - t[t_pos-1]);
      ans = min(len, ans);
    }
    // right_temple -> right_shrine
    if ( t_pos < b && s_pos < a ) {
      len = abs(x - t[t_pos]) + abs(t[t_pos] - s[s_pos]);
      ans = min(len, ans);
    }
    // right_temple -> left_shrine
    if ( t_pos < b && s_pos-1 >= 0 ) {
      len = abs(x - t[t_pos]) + abs(t[t_pos] - s[s_pos-1]);
      ans = min(len, ans);
    }
    // left_temple -> right_shrine
    if ( t_pos-1 >= 0 && s_pos < a ) {
      len = abs(x - t[t_pos-1]) + abs(t[t_pos-1] - s[s_pos]);
      ans = min(len, ans);
    }
    // left_temple -> left_shrine
    if ( t_pos-1 >= 0 && s_pos-1 >= 0 ) {
      len = abs(x - t[t_pos-1]) + abs(t[t_pos-1] - s[s_pos-1]);
      ans = min(len, ans);
    }
    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 5060
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define printYes() cout << "Yes" << endl;
#define printNo() cout << "No" << endl;
#define printVector(v) rep(i, v.size()) cout << v[i] << endl;

int main()
{
  string S;
  cin >> S;
  long long ans = 0;
  rep(i, pow(2, S.size() - 1))
  {
    int n = i;
    int pow10 = 0;
    int index = S.size() - 1;
    long long num = 0;
    while (index != -1)
    {
      if (n & 1)
      {
        num += pow(10, pow10) * (S[index] - '0');
        ans += num;
        num = 0;
        pow10 = 0;
      }
      else
      {
        num += pow(10, pow10) * (S[index] - '0');
        pow10++;
      }
      index--;
      n = n >> 1;
    }
    ans += num;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define EB emplace_back
#define MP make_pair
#define all(o) (o).begin(), (o).end()
#define mset(m,v) memset(m,v,sizeof(m))
#define fr(i,n) for(lli i=0;i<n;++i)
#define rep(i,a,b) for(lli i=a;i<=b;++i)
#define remin(a,b) (a=min((a),(b)))
#define remax(a,b) (a=max((a),(b))) 
#define endl '\n'
typedef long long lli;        typedef long double ld;
typedef pair<lli,lli> ii;     typedef vector<lli> vi;
typedef vector<ii> vii;       typedef vector<vi> graph;
long long MOD=1000000007;     long double EPS=1e-9;
#define debarr(a,n) cout<<#a<<" : ";for(int i=0;i<n;i++) cerr<<a[i]<<" "; cerr<<endl;
#define debmat(mat,row,col) cout<<#mat<<" :\n";for(int i=0;i<row;i++) {for(int j=0;j<col;j++) cerr<<mat[i][j]<<" ";cerr<<endl;}
#define pr(...) dbs(#__VA_ARGS__, __VA_ARGS__)
template <class S, class T>ostream& operator <<(ostream& os, const pair<S, T>& p) {return os << "(" << p.first << ", " << p.second << ")";}template <class T>ostream& operator <<(ostream& os, const vector<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T>ostream& operator <<(ostream& os, const unordered_set<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}template <class S, class T>ostream& operator <<(ostream& os, const unordered_map<S, T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T>ostream& operator <<(ostream& os, const set<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}template <class T>ostream& operator <<(ostream& os, const multiset<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class S, class T>ostream& operator <<(ostream& os, const map<S, T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}template <class T> void dbs(string str, T t) {cerr << str << " : " << t << "\n";}
template <class T, class... S> void dbs(string str, T t, S... s) {int idx = str.find(','); cerr << str.substr(0, idx) << " : " << t << ","; dbs(str.substr(idx + 1), s...);}template <class T> void prc(T a, T b) {cerr << "["; for (T i = a; i != b; ++i) {if (i != a) cerr << ", "; cerr << *i;} cerr << "]\n";}
lli binpow(lli b,lli p,lli mod){lli ans=1;for(;p;p>>=1){if(p&1)ans=ans*b%mod;b=b*b%mod;}return ans;}

void pre(){

}

lli dp[3010][3010][2];

void solve(){	
	lli n,m;
	cin>>n>>m;
	fr(i,n){
		dp[0][i+1][0]=1;
	}
	dp[0][0][1]=1;
	fr(i,m){
		fr(j,n+1){
			fr(k,2){
				if(dp[i][j][k]){
					if(j>0){
						dp[i+1][j][k|(j<2)]+=dp[i][j][k];
						dp[i+1][j-1][k|(j<2)]+=dp[i][j][k];
						dp[i+1][j][k|(j<2)]%=MOD;
						dp[i+1][j-1][k|(j<2)]%=MOD;
					}
					if(j<n){
						dp[i+1][j][k]+=dp[i][j][k];
						dp[i+1][j+1][k]+=dp[i][j][k];
						dp[i+1][j+1][k]%=MOD;
						dp[i+1][j][k]%=MOD;
					}
				}
			}
		}
	}
	lli ans=0;
	fr(i,n+1){
		ans=(ans+dp[m][i][1])%MOD;
	}
	cout<<ans<<endl;
}

signed main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	//freopen("in.txt","r",stdin);//freopen("out.txt","w",stdout);
	pre();int t=1;//cin>>t;
	for(int i=1;i<=t;i++){
		//cout<<"Case #"<<i<<": ";
		solve();
	}
}

Measured memory_bytes: 141568
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(I, a, b) for (int i = (a); i < (b); ++i)
using namespace std;
using ll = long long;

int main() {
  int n,q;
  string s;
  cin >> n >> q >> s;
  vector<int> a(n+1);
  REP(i,n+1){
    if(i != 0){
      if(s[i-1] == 'A' && s[i] == 'C'){
        a[i]++;
        
      }
      a[i] += a[i-1];
    }
  }
  
  REP(i,q){
    int l,r;
    cin >> l >> r;
    cout << a[r-1]-a[l-1] << endl;
  }
  
  
}


Measured memory_bytes: 3764