akhauriyash/Code-Regression huggingface dataset:
#include <iostream>

using namespace std;


int main() {
	
	int w, h;
	char c;

	cin >> w >> h >> c;

	for (int i = 0; i < h; i++) {

		for (int j = 0; j < w; j++) {

			if ((i == 0 || i == h - 1) && (j == 0 || j == w - 1))
				cout << "+";

			else if (i == 0 || i == h - 1)
				cout << "-";

			else if (j == 0 || j == w - 1)
				cout << "|";

			else if (i == (h - 1) / 2 && j == (w - 1) / 2)
				cout << c;

			else
				cout << ".";

		}

		cout << "\n";

	}
	
	return 0;

}







Measured memory_bytes: 3084
#include <iostream>

using namespace std;

int main() {
    long long q,h,s,d;
    cin >> q >> h >> s >> d;
    long long n;
    cin >> n;
    if(q*2 < h) h = q*2;
    if(h*2 < s) s = h*2;
    if(s*2 < d) d = s*2;
    cout << d*(n/2)+s*(n%2) << endl;
}

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

#define fi first
#define se second
#define vi vector<int>
#define vpi vector<pair<int,int>>
#define vll vector<ll>
#define vpll vector<pair<ll,ll>>
#define endl '\n'

#define si(v) int(v.size())
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep2(i, n, m) for (ll i = n; i <= (m); ++i)
#define rep3(i, n, m) for (ll i = n; i >= (m); --i)

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

using ll = long long;
using ld = long double;
using namespace std;

constexpr ll MOD = 1000000007;

signed main()
{
  cout << fixed << setprecision(20);
  ios::sync_with_stdio(false);
  cin.tie(0);
  
  int n; cin >> n;

  auto f = [&](ll x, ll y) {
    return x / __gcd(x, y) * y;
  };

  ll ans = 1;
  rep(i, n) {
    ll t; cin >> t;
    ans = f(ans, t);
  }

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

Measured memory_bytes: 3608
#include<algorithm>/*{{{*/
#include<cctype>
#include<cassert>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<ctime>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<vector>
using namespace std;
typedef long long lld;
typedef long double lf;
typedef unsigned long long uld;
typedef pair<int,int> pii;
#define fi first
#define se second
#define pb push_back
#define mk make_pair
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define ROF(i,a,b) for(int i=(a);i>=(b);--i)
namespace RA{
    int r(int p){return 1ll*rand()*rand()%p;}
    int r(int L,int R){return r(R-L+1)+L;}
}/*}}}*/
/******************heading******************/
const int N=1e5+5;

int n;
int a[N];

bool dfs(int x){
    if(a[x+1]<=x){
        int cnt=0,pos=x+1;
        while(a[pos]==x)++cnt,++pos;
        int c2=a[x]-x;
        if((cnt&1)||(c2&1))return 1;
        return 0;
    }
    return dfs(x+1);
}
int main(){
    scanf("%d",&n);
    FOR(i,1,n)scanf("%d",&a[i]);
    sort(a+1,a+n+1);
    reverse(a+1,a+n+1);
    int ans=dfs(1);
    puts(ans?"First":"Second");
    return 0;
}


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

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vector<vector<bool>>> vvvb;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<vpll> vvpll;
typedef vector<double> vd;
typedef vector<vd> vdd;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)
#define RFOR(i,x,y) for(ll i=(ll)x; i>=(ll)y; --i)
#define RREP(i,x) RFOR(i, x, 0)
#define ALL(a) a.begin(), a.end()
#define pb push_back
#define debug_print(x...) cerr << "line " << __LINE__ << " : "; debug_print_in(x);

template <typename First>
void debug_print_in(First first){
  cerr << first << endl;
  return;
}

template <typename First, typename... Rest>
void debug_print_in(First first, Rest... rest){
  cerr << first << " ";
  debug_print_in(rest...);
  return;
}

void IN(void){
  return;
}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
  cin >> first;
  IN(rest...);
  return;
}

template <typename First>
void OUT(First first){
  cout << first << endl;
  return;
}

template <typename First, typename... Rest>
void OUT(First first, Rest... rest){
  cout << first << " ";
  OUT(rest...);
  return;
}

template<class t, class u> void chmax(t&a,u b){if(a<b)a=b;};
template<class t, class u> void chmin(t&a,u b){if(a>b)a=b;};
int popcount(int t){return __builtin_popcount(t);} //GCC
int popcount(ll t){return __builtin_popcountll(t);} //GCC

template <typename T>
void vec_print(vector<T> VEC){
  REP(i, VEC.size()){
    cerr << VEC[i] << " ";
  }
  cerr << endl;
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  REP(i,MAT.size()){
    REP(j,MAT[i].size()){
      cerr << MAT[i][j] << " ";
    }
    cerr << endl;
  }
};

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;
constexpr ll MOD = (ll)((1E+9)+7);

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  string S, T;
  IN(S, T);

  OUT(T+S);

  return 0;
}

Measured memory_bytes: 256
from sys import stdin
from itertools import accumulate
N = int(stdin.readline().rstrip())
a = [[None] * N] * 2
accum_a = [[None] * N] * 2
data0 = stdin.readline().split()
data1 = stdin.readline().split()
a[0] = [int(data0[i]) for i in range(N)]
a[1] = [int(data1[i]) for i in range(N-1,-1,-1)]
accum_a[0] = list(accumulate(a[0]))
accum_a[1] = list(accumulate(a[1]))
accum_a[1] = accum_a[1][::-1]
# print(a)
# print(accum_a)
vals_sum = [None] * N
for i in range(N):
    vals_sum[i] = accum_a[0][i] + accum_a[1][i]
print(max(vals_sum))

Measured memory_bytes: 3064
#include <stdio.h>
#define N 100

int main(){
int i,j,A[N],minj,count=0,key,num;

scanf("%d",&num);

for(i=0;i<num;i++){
scanf("%d",&A[i]);
}

for(i=0;i<num;i++){
    minj=i;
    for(j=i;j<num;j++){
        if(A[j]<A[minj]){
            minj=j;  
        } 
    }
        if(i!=minj){
        key=A[i];
        A[i]=A[minj];
        A[minj]=key;
        count++;
        }
    
}

for(i=0;i<num-1;i++){
printf("%d ",A[i]);
}

printf("%d\n%d\n",A[num-1],count);

return 0;
}

Measured memory_bytes: 600
#include<iostream>

using namespace std;

int main(){
  int n, k;
  while(cin >> n >> k) {
    int  x, y, X, Y, ans;
    while(cin >> X >> Y) {
      if(n%2 == 0){
	x = X - n/2;
	y = Y - n/2;
      }
      else {
	x = X -(n + 1)/2;
	y = Y -(n + 1)/2;
      }
      if((y > x &&  0-x >= y) || (y <= x && 0 - x < y )){
	if(X <= n/2 ) ans = X%3;
	else  ans = (n - X + 1) % 3;
      }
      else
	if(Y <= n/2 ) ans = Y%3;
	else ans = (n - Y + 1) % 3;


      if(ans)
	cout << ans << endl;
      else
	cout << "3" << endl;
    }
  }
  return 0;
}
      
      

Measured memory_bytes: 1164
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define LLINF 9223372036854775807
#define MOD ll(1e9+7)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr<<#x<<": "<<x<<endl

int main(){
    string s;
    cin >> s;
    int cnt = 0;
    for(int i = 0; i < s.size(); i++){
        if(s[i]=='x'){cnt++;}
    }

    cout << ((cnt < 8 ) ? "YES" : "NO") << endl;
    return 0;

}


Measured memory_bytes: 256
x = input().split()
a = int(x[0])
b = int(x[1])
c = int(x[2])
d = int(x[3])

while a >= 0 or c >= 0:
  c -= b
  if c <= 0:
    print("Yes")
    break
  a -= d
  if a <= 0:
    print("No")
    break
  

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

#define chmin(x,y) x = min(x,y);
const int INF = 1001001001;

int main(void){
    int n,m,l;
    cin >> n >> m >> l;
    vector<vector<int>> dist(n,vector<int>(n,INF));
    rep(i,n){
        dist[i][i] = 0;
    }
    rep(i,m){
        int a,b,c;
        cin >> a >> b >> c;
        a--;
        b--;
        dist[a][b] = dist[b][a] = c;
    }
    rep(k,n){
        rep(i,n){
            rep(j,n){
                chmin(dist[i][j],dist[i][k]+dist[k][j]);
            }
        }
    }
    vector<vector<int>> dist2(n,vector<int>(n,INF));
    rep(i,n){
        rep(j,n){
            if(dist[i][j]<=l){
                dist2[i][j] = 1;
            }
        }
    }
    rep(k,n){
        rep(i,n){
            rep(j,n){
                chmin(dist2[i][j],dist2[i][k]+dist2[k][j]);
            }
        }
    }
    int q;
    cin >> q;
    rep(i,q){
        int a,b;
        cin >> a >> b;
        a--; b--;
        int ans = dist2[a][b]-1;
        if(dist2[a][b] == INF){
            ans = -1;
        }
        cout << ans <<endl;
    }
    
    
    return 0;
    
}




















































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

vector<pair<long long, int> > V;

long long n;
long long B = 1;

long long func(int i) {
    if (i == (int)V.size())
        return ((n / B < B - 1) ? (B - 1) : 0);
    else {
        long long ans = 0;
        long long p = 1, cnt = V[i].second;
        ans = func(i + 1);
        for (int j = 0; j < cnt; j++) {
            p *= V[i].first;
            B *= p;
            ans += func(i + 1);
            B /= p;
        }
        return ans;
    }
}

int main() {
    cin >> n;
    long long m = n;
    for (long long i = 2; i * i <= m; i++) {
        if (m % i != 0)
            continue;
        int cnt = 0;
        while (m % i == 0) {
            cnt++;
            m /= i;
        }
        V.emplace_back(i, cnt);
    }
    if (m != 1)
        V.emplace_back(m, 1);
    cout << func(0) << "\n";
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>

typedef unsigned long long ULLONG;
typedef long long LLONG;
static const LLONG MOD_NUM = 1000000007;

template<class _T> static void getint(_T& a) {
	std::cin >> a;
}
template<class _T> static void getint(_T& a, _T& b) {
	std::cin >> a >> b;
}
template<class _T> static void getint(_T& a, _T& b, _T& c) {
	std::cin >> a >> b >> c;
}

static void A();

int main()
{
	A();
	fflush(stdout);
	return 0;
}

static void A()
{
	int N;
	getint(N);

	std::vector<LLONG> ai(N);
	for (int i = 0; i < N; i++) {
		getint(ai[i]);
	}

	LLONG sum = 0;
	LLONG sign[] = { 1, -1 };
	for (int i = 0; i < N; i++) {
		sum += sign[i % 2] * ai[i];
	}
	LLONG vol = sum;
	printf("%lld ", vol);
	for (int i = 1; i < N; i++) {
		vol = (ai[i - 1] - (vol / 2)) * 2LL;
		printf("%lld ", vol);
	}
	putchar('\n');
}


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

int main()
{
    int N;
    int D[300005];
    bool flag = false;

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

    int maxv = 0;
    for(int i = 0; i < N; i++) {
        if(maxv < 0) {
            flag = true;
        }
        maxv = max(D[i], maxv);
        maxv -= 10;
    }
    maxv = 0;
    for(int i = N - 1; i >= 0; i--) {
        if(maxv < 0) {
            flag = true;
        }
        maxv = max(D[i], maxv);
        maxv -= 10;
    }
    if(flag) cout << "no" << endl;
    else cout << "yes" << endl;
    return (0);
}

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

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

	long long h[n];	for (int i = 0; i < n; i++) { cin >> h[i]; }

	string ans = "Yes";

	for (int i = n - 2; i >=  0 ; i--) {
		if (h[i] > h[i + 1]) {
			h[i]--;			
		}
	}

	for (int i = 0; i < n - 1; i++) {
		if (h[i]  > h[i + 1]) {		
			ans = "No";
			break;
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define inf 999999999
#define loop(i, a, b) for (int i = (a), i##len = (b); i < i##len; ++i)
#define rep(i, n) loop(i, 0, n)
#define lin long long
#define lfl long double

int main(void)
{
    int a,b,c;
    cin >> a >> b;
    for(int i = 1; i <= 3; i++)
    {
        if(a*b*i % 2 == 1)
        {
            cout << "Yes" << endl;
            return 0;
        }
    }

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


Measured memory_bytes: 256
#include <cctype>
#include <cfloat>
#include <climits>
#include <cmath>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <ios>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <forward_list>
#include <random>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <unordered_map>
#include <unordered_set>
#endif

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm( a, b ) (a)/__gcd((a),(b))*(b)
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;
typedef pair< int, P > iP;
typedef pair< P, P > PP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 100005;

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

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

    LL n, a, b;
    cin >> n >> a >> b;
    LL x[n];
    for( int i = 0; i < n; ++i ) cin >> x[i];

    LL res = 0;
    for( int i = 1; i < n; ++i ) {
        LL diff = x[i] - x[i - 1];
        res += min( diff * a, b );

    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
using namespace std;
int a[100000],L[100000],R[100000],M[100000];
int n;

int gcd(int a, int b){
    if(a > b) swap(a,b);
    b = b%a;
    if(!b) return a;
    else return gcd (a,b);
}

void solve(){
    L[1] = a[0]; R[n-2] = a[n-1];
    for(int i=2; i<n; i++){
        L[i] = gcd(L[i-1],a[i-1]);
    }
    for(int i=n-3; i>=0; i--){
        R[i] = gcd(R[i+1],a[i+1]);
    }
    M[0] = R[0];
    M[n-1] = L[n-1];
    for(int i=1; i < n-1; i++){
        M[i] = gcd(L[i],R[i]);
    }
    cout << *max_element(M,M+n) << endl;
}

int main(){
    cin >> n;
    for(int i=0; i<n; i++){
        cin >> a[i];
    }
    solve();
    return 0;
}


Measured memory_bytes: 1792
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<unordered_map>
using namespace std;
//---------------------------------------------------
//ライブラリゾーン！！！！
typedef long long ll;
typedef long double ld;
#define str string
#define rep(i,j) for(ll i=0;i<(long long)(j);i++)
const ll Mod = 1000000007;
const ll gosenchou = 5000000000000000;
short gh[2][4] = { { 0,0,-1,1 },{ -1,1,0,0 } };
struct P {
	ll pos, cost;
};
bool operator<(P a, P b) { return a.cost < b.cost; }
bool operator>(P a, P b) { return a.cost > b.cost; }
struct B {//隣接リスト表現
	ll to;
	ld cost;
};
struct E {//辺の情報を入れる変数
	ll from, to, cost;
};
bool operator<(E a, E b) {
	return a.cost < b.cost;
}
struct H {
	ll x, y;
};
bool operator<(H a, H b) {
	if (a.x != b.x) return a.x < b.x;
	return a.y < b.y;
}
bool operator>(H a, H b) {
	if (a.x != b.x) return a.x > b.x;
	return a.y > b.y;
}
bool operator==(H a, H b) {
	return a.x == b.x&&a.y == b.y;
}
bool operator!=(H a, H b) {
	return a.x != b.x || a.y != b.y;
}
ll gcm(ll i, ll j) {//最大公約数
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcm(j%i, i);
}
ld rad(H a, H b) {
	return sqrt(pow(a.x - b.x, 2.0) + pow(a.y - b.y, 2.0));
}//rad＝座標上の2点間の距離
ll ari(ll a, ll b, ll c) {
	return (a + b)*c / 2;
}//等差数列の和
bool suf(ld a, ld b, ld c, ld d) {
	if (b <= c || d <= a) return 0;
	return 1;
}//[a,b),[c,d)
ll fact(ll x, ll k,ll p) {//最大値、個数
	ll sum = 1;
	for (int i = 0; i < k; i++) {
		sum *= (x--);
		sum %= p;
	}
	return sum;
}//階乗(正）
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res*x%p;
		x = x*x%p;
		n >>= 1;
	}
	return res;
}//x^n%p
#define int long long
const long long inf = 4523372036854775807;
const int iinf = 1500000000;
//----------------------------------------------------
//+++++++++++++++++++++++++++++++++++++++++++++++++++
int n, m;
H a[10000];
signed main() {
	while (cin >> n >> m&&n + m > 0) {
		for (int i = 0; i < n; i++) {
			cin >> a[i].y >> a[i].x;
		}
		sort(a, a + n);
		reverse(a, a + n);
		int sum = 0;
		for (int i = 0; i < n; i++) {
			if (!m) {
				sum += a[i].x*a[i].y;
			}
			else if (a[i].y > m) {
				sum += a[i].x*(a[i].y - m);
				m = 0;
			}
			else {
				m -= a[i].y;
			}
		}
		cout << sum << endl;
	}
	getchar(); getchar();
}


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

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)


void func(long long n, long long m, std::vector<long long> x, std::vector<long long> y){

    lli xSum = 0;
    lli ySum = 0;

    REP(i,1,n){
        xSum += (((x[i]-x[i-1])*(i)*(n-i)))%MOD;
        xSum %= MOD;
    }
    REP(i,1,m){
        ySum += ( ( (y[i]-y[i-1])*(i)*(m-i)))%MOD;
        ySum %= MOD;
    }
    cout<<(xSum*ySum)%MOD<<endl;
}

int main(){
    // cout << fixed << setprecision(5);

    long long n;
    scanf("%lld",&n);
    long long m;
    scanf("%lld",&m);
    std::vector<long long> x(n);
    for(int i = 0 ; i < n ; i++){
        scanf("%lld",&x[i]);
    }
    std::vector<long long> y(m);
    for(int i = 0 ; i < m ; i++){
        scanf("%lld",&y[i]);
    }
    func(n, m, std::move(x), std::move(y));
    return 0;
}


Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {

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

		int margin = 642;
		for(int i = 0; i <= s.length() - 3; i++) {
			// 差を保持
			int tmp = Math.abs(Integer.parseInt(s.substring(i, i+3)) - 753);
			if(tmp < margin) {
				margin = tmp;
			}
		}
		System.out.println(margin);
		sc.close();
	}
}


Measured memory_bytes: 22996
#include <iostream>
#include <string>    
#include <vector>
#include <queue>
#include <cmath>
using namespace std;
typedef long long ll;
ll n, m;

int main() {
	ll h, w;
	ll r = 0;
	cin >> h >> w;
	ll grid[h+2][w+2];
	for(ll i = 1; i <= h; i++){
		string buf;
		cin >> buf;
		for(ll j = 1; j <= w; j++){
			grid[i][j] = (buf[j-1] == '.')? 0 : -1;
			r += grid[i][j]+1;
		}
	}
	for(ll i = 1; i <= h; i++){
		grid[i][0] = -1;
		grid[i][w+1] = -1;
	}
	for(ll j = 1; j <= w; j++){
		grid[0][j] = -1;
		grid[h+1][j] = -1;
	}
	
	grid[1][1] = 1;
	queue<ll> qx, qy;
	qx.push(1);
	qy.push(1);
	ll x, y;
	while(!qx.empty()){
		x = qx.front();
		y = qy.front();
		qx.pop();
		qy.pop();
		if(grid[x-1][y] == 0){
			grid[x-1][y] = grid[x][y]+1;
			qx.push(x-1);
			qy.push(y);
		}
		if(grid[x+1][y] == 0){
			grid[x+1][y] = grid[x][y]+1;
			qx.push(x+1);
			qy.push(y);
		}
		if(grid[x][y-1] == 0){
			grid[x][y-1] = grid[x][y]+1;
			qx.push(x);
			qy.push(y-1);
		}
		if(grid[x][y+1] == 0){
			grid[x][y+1] = grid[x][y]+1;
			qx.push(x);
			qy.push(y+1);
		}
	}
	if(grid[h][w] > 0){
		r -= grid[h][w];
	}
	else{
		r = -1;
	}
	cout << r;
	return 0;
}

Measured memory_bytes: 256
N, Q = map(int, input().split())
S = input()
f = [0] * N
for i in range(N-1):
  add = 0
  if S[i:i+2] == 'AC':
    add = 1
  if i == 0:
    f[i+1] = add
  else:
    f[i+1] = f[i] + add

#print(f)
for i in range(Q):
  l, r = map(int, input().split())
  print(f[r-1]-f[l-1])


Measured memory_bytes: 9412
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    final int N=sc.nextInt();
    final int[] A=new int[N];
    for(int i=0;i<N;i++){
      A[i]=sc.nextInt();
    }
    double a=0.0;
    for(int i=0;i<N;i++){
      a+=(double)1/(double)A[i];
    }
    double answer=(double)1/(double)a;
    System.out.println(answer);
  }
}


Measured memory_bytes: 22740
T = 10 ** 6 + 20
n = int(input())
a = [int(i) for i in input().split()]
table = [True for _ in range(T)]
a.sort()
ans = 0
for i in range(n):
    if table[a[i]]:
        for j in range(a[i], T, a[i]):
            table[j] = False
        if i + 1 < n:
            if a[i + 1] != a[i]:
                ans += 1
        elif i + 1 == n:
            ans += 1
print(ans)


Measured memory_bytes: 32268
#include <algorithm>

#include <bitset>

#include <tuple>

#include <cstdint>

#include <cstdio>

#include <cctype>

#include <assert.h>

#include <stdlib.h>

#include <stdio.h>

#include <cassert>

#include <cfloat>

#include <climits>

#include <cmath>

#include <complex>

#include <ctime>

#include <deque>

#include <fstream>

#include <functional>

#include <iomanip>

#include <iostream>

#include <iterator>

#include <list>

#include <limits>

#include <map>

#include <memory>

#include <queue>

#include <random>

#include <set>

#include <stack>

#include <string>

#include <unordered_map>

#include <unordered_set>

#include <utility>

#include <vector>

#include <math.h>
using namespace std;
int main() {
    string S, T, U;
    int A, B;
    cin >> S >> T >> A >> B >> U;
    if (S == U) {
        cout << A - 1 << " " << B << endl;
    }
    else {
        cout << A << " " << B - 1 << endl;
    }
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
using namespace std;
#define rep(i, n) for(int i=0; i<n; ++i)
typedef long long ll;
//必要な宣言
#define MAX 100000

//問題をよく読もう！
//論理的に考えよう！
//サンプルを確認しよう!
//絶対に諦めるな！
//工夫をしろ！
int main() {
  int A, B;
  char op;
  cin >> A >> op >> B;

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

  return 0;
}


Measured memory_bytes: 256
// AOJ 0550: Dividing Snacks
// 2017.11.18 bal4u@uu

#include <stdio.h>
#include <string.h>
#define TM 0
#if TM
#include <time.h>
#endif

#define INF 0x33333333
int dp[10001];
char buf[20], *p;

int getint()
{
	int n = 0;
	while (*p >= '0') n = (n<<3) + (n<<1) + (*p++ & 0xf);
	return n;
}

int main()
{
    int n, ti, i, j, jj;
#if TM
	clock_t start, finish;
	start = clock();
#endif
	fgets(p=buf, 20, stdin), n = getint();
	memset(dp, INF, sizeof(dp));
    dp[0] = 0;
    for (i = 1; i < n; i++) {
		fgets(p=buf, 20, stdin), ti = getint();
		for (jj = i >> 1, j = 0; j <= jj; j++) {
			if (dp[j] > dp[i-j] + ti) dp[j] = dp[i-j] + ti;
			if (dp[i-j] > dp[j] + ti) dp[i-j] = dp[j] + ti;
		}
    }
	printf("%d\n", dp[n>>1]);
#if TM
	finish = clock();
	printf("time %lf\n", (double)(finish-start)/CLOCKS_PER_SEC);
#endif
	return 0;
}

Measured memory_bytes: 1888
S = input()
size = len(S)

ans = 0

for binary in range(1 << size - 1):
    exp = S[0]
    for i in range(size - 1):
        if (binary >> i) & 1:
            exp += "+"
        exp += S[i + 1]
    ans += eval(exp)

print(ans)


Measured memory_bytes: 2940
#include<iostream>
    #include<stdio.h>
    //#include <bits/stdc++.h>
    #include<vector>
    #include<float.h>
    #include<iomanip>
    #include<algorithm>
    #include<string>
    #include<cstring>
    #include<math.h>
    #include<cmath>
    #include<sstream>
    #include<set>
    #include<map>
    #include<queue>
    #include<cassert>
    #include<cmath>
    #include<cstdint>
     
    #define INF 1e9
    #define rep(i,n)for(int i=0;(i)<(int)(n);i++)
    #define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
    #define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
    #define vec(type,n) vector<type>(n)
    #define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
    #define ALL(a)  (a).begin(),(a).end()
     
    using namespace std;
    using ll = long long;
    using Graph = vector<vector<int>>;
    using P = pair<ll, ll>;
     
//const ll MOD = INF + 7;
//Combination MOD
const int MOD = 1e9 + 7;

//bit全探索
vector<int>bitSearch(int bit,int n){
    vector<int>S;
    rep(i,n)if(bit&(1<<i))S.push_back(i);
    S.push_back(1e9);
    return S;
}

int main(){
   int h, w, k, res = 0;
   cin >> h >> w >> k;
   vector<string> fld(h);
   rep(i, h)cin >> fld[i];
   int sum = 0;
   rep(i, h)rep(j, w)if(fld[i][j] == '#')sum++;
   vector<vector<int>> chk(h, vector<int>(w, 0));
   for(int bit1 = 0; bit1 < (1 << h); bit1++){
      for(int bit2 = 0; bit2 < (1 << w); bit2++){
         chk = vector<vector<int>> (h, vector<int>(w, 0));
         vector<int> Sh = bitSearch(bit1, h);
         vector<int> Sw = bitSearch(bit2, w);
         for(int bh : Sh){       //tate
            if(bh == INF)break;
            rep(j, w)if(fld[bh][j] == '#')chk[bh][j] = 1;
         }
         for(int bw : Sw){
            if(bw == INF)break;
            rep(j, h)if(fld[j][bw] == '#')chk[j][bw] = 1;
         }

         int cnt = 0;
         rep(i, h)rep(j, w)if(chk[i][j] == 1)cnt++;
         if(sum - cnt == k)res++;
      }
   }
   cout << res << endl;
}


Measured memory_bytes: 3632
# include <bits/stdc++.h>
#define INF 1e9
using namespace std;

int main(){

  int L, R;
  cin >> L >> R;

  int mod = 2019;
  int lb, ub;
  lb = L;
  ub = min(R+1, lb+mod*2);

  int ans = mod-1;
  for(int i=lb; i < ub; i++){
    for(int j= i+1; j< ub; j++){
      int mi, mj;
      mi = i % mod;
      mj = j % mod;
      ans = min(ans, (mi * mj) % mod);
    }
  }
  cout << ans << endl;

}


Measured memory_bytes: 256
// D - Binomial Coefficients

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

int a[100000];

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

	int max_a = 0;
	for (int i=0; i<n; i++) {
		cin >> a[i];
		max_a = max(max_a, a[i]);
	}

	int max_r = -1;
	int max_r_idx;
	for (int i=0; i<n; i++) {
		if (a[i] == max_a) continue;
		int r = a[i];
		if (r > max_a / 2) r = max_a - r;

		if (r > max_r) {
			max_r = r;
			max_r_idx = i;
		}
	}

	cout << max_a << " " << a[max_r_idx] << endl;

	return 0;
}

Measured memory_bytes: 4008
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);
        int n = Integer.parseInt(stdIn.next());
        int k = Integer.parseInt(stdIn.next());

        int x = 1;
        int r = 0;
        while (true) {
            if (n < x) {
                System.out.println(r);
                break;
            }
            x *= k;
            r++;
        }
    }
}

Measured memory_bytes: 21716
#include <iostream>

int main() {
    int S;
    std::cin >> S;
    
    int h, m, s;
    h = S / 3600;
    m = (S % 3600) / 60;
    s = (S % 60);
    
    std::cout << h << ":" << m << ":" << s << std::endl;
    
    return 0;
}


Measured memory_bytes: 3096
import java.util.HashMap;
import java.util.Scanner;

public class Main{
	//	public static HashMap<Integer, Integer> hei = new HashMap<Integer, Integer>();
	public static void main(String[] args){
		Scanner in = new Scanner(System.in);
		while(true){
			int r = in.nextInt();
			int n = in.nextInt();
			if(r == 0) break;
			int[] h = new int[41];
			for(int i=0; i<n; i++){
				int xl = in.nextInt();
				int xr = in.nextInt();
				int hei = in.nextInt();
				for(int j=xl+20; j<xr+20; j++){
					h[j] = Math.max(h[j], hei);
				}
			}
			int[] p = new int[r*2-1];
			for(int i=-r+1; i<r; i++){
				p[i+r-1] = Math.min(h[20+i], h[20+i-1]);
			}
			double[] circle = new double[r*2-1];
			for(int i=-r+1; i<r; i++){
				circle[i+r-1] = Math.sqrt(r*r-i*i)-r;
			}
			double res = 100;
			for(int i=0; i<r*2-1; i++){
				res = Math.min(res, p[i]-circle[i]);
			}
			System.out.println(String.format("%.4f", res));
		}
	}

	//	public static void setMap(int x, int y){
	//		if(hei.containsKey(x)){
	//			int by = hei.get(x);
	//			
	//		}else{
	//			hei.put(x, y);
	//		}
	//	}
}

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


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

#define reps(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   reps(i,0,n)
#define all(x) (x).begin(),(x).end()
#define INF (1000000000)
#define MOD (1000000007)
#define PI (acos(-1))

int main(){
  int N;
  string S;
  cin >> N >> S;

  int sumb[N]={},sumw[N]={};
  rep(i,N){
    if(i==0){
      if(S[i] == '#')sumb[i]=1;
      else sumw[i] = 1;
    }else{
      if(S[i] == '#'){
        sumb[i] = sumb[i-1]+1;
        sumw[i] = sumw[i-1];
      }else{
        sumb[i] = sumb[i-1];
        sumw[i] = sumw[i-1]+1;
      }
    }
  }

  if(N==1){
    cout << 0 << endl;
    return 0;
  }
  if(N==2){
    if(S==".." || S=="##" || S==".#"){
      cout << 0 << endl;
    }else{
      cout << 1 << endl;
    }
    return 0;
  }

  int ans = INF;
  rep(w,N){
    if(w==0){
      ans = min(ans,sumw[N-1]);
      continue;
    }
    if(w==N-1){
      ans = min(ans,sumb[N-1]);
      continue;
    }
    ans = min(ans,sumb[w-1]+sumw[N-1]-sumw[w-1]);
  }

  cout << ans << endl;
}

Measured memory_bytes: 2180
import sys
from collections import Counter
read = sys.stdin.read
readline = sys.stdin.readline

H, W = map(int, readline().split())
a = read().split()
s = []
for i in a:
    s.extend(list(i))

s = Counter(s)
r = [0] * 4
for i in s.values():
    r[i % 4] += 1

if r[1] + r[3] > 1:
    print('No')
    exit()

h = H % 2
w = W % 2

if h and w:
    if not r[1]:
        r[3] -= 1
        r[2] += 1
    if H + W - r[2] * 2 >= 0 and (H + W - 2 - r[2] * 2) % 4 == 0:
        print('Yes')
    else:
        print('No')
else:
    if r[1] + r[3] != 0:
        print('No')
        exit()
    if h:
        if W - r[2] * 2 >= 0 and (W - r[2] * 2) % 4 == 0:
            print('Yes')
        else:
            print('No')
    elif w:
        if H - r[2] * 2 >= 0 and (H - r[2] * 2) % 4 == 0:
            print('Yes')
        else:
            print('No')
    else:
        if r[0] and r.count(0) == 3:
            print('Yes')
        else:
            print('No')

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

int h[100000], dp[100000];

int main() {
  ios::sync_with_stdio(0); cin.tie(0);
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < n; i++) cin >> h[i];
  fill_n(dp, n, 2e9);
  dp[0] = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 1; j <= k; j++)
      if (i+j < n)
	dp[i+j] = min(dp[i+j], dp[i]+abs(h[i+j]-h[i]));
  }
  cout << dp[n-1] << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <unordered_map>
#include <string>
#include <cmath>
#include <set>
#include <cmath>
using namespace std;

vector<vector<long long>> dp;


const long long mod = 1e+9 + 7;

void solve()
{
	int h, w;
	cin >> h >> w;

	dp.assign(2, vector<long long>(w, 0));

	for (int i = 0; i < h; i++)
	{
		for (int k = 0; k < w; k++)
		{
			dp[i & 1][k] = 0;

			if (i == 0 && k == 0)
			{
				dp[i][k] = 1;
			}
			char c;
			cin >> c;

			if (c == '.')
			{
				if (i)
				{
					dp[i & 1][k] += dp[(i + 1) & 1][k];
				}

				if (k)
				{
					dp[i & 1][k] += dp[i & 1][k - 1];
				}
				  
				dp[i & 1][k] %= mod;
			}

			//cout << dp[i & 1][k] << " ";
		}
		//cout << "\n";
	}

	cout << dp[(h - 1) & 1][w - 1];
}

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

	int t = 1;
	//cin >> t;
	while (t--)
	{
		solve();
	}
	return 0;
}

Measured memory_bytes: 256
use std::env;
use std::io::*;
use std::str::*;
use std::mem;
use std::collections::HashMap;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let s = stdin.bytes().map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().ok().unwrap()
}
fn read_char() -> char {
    let c = read::<String>();
    let c = c.chars().collect::<Vec<char>>();
    c[0]
}
fn read_String_Vec() -> Vec<char> {
    let S = read::<String>();
    S.chars().collect::<Vec<char>>()
}

fn vecchar_to_String(Vs: Vec<char>) -> String {
    let mut S = String::new();
    for i in 0..Vs.len() {
        S.push(Vs[i]);
    }
    S
}

/*
A : 65
Z : 90
a : 97
z : 122
*/

/*
let N = read::<i32>();
let S = read::<String>();
let S = read_String_Vec();
let C = read_char();
*/

/*
 .to_string() : * -> String
 &*S          : String -> &str
*/

fn main() {
    // main の引数
    /*
        引数なしのときargs.len() = 1;
    */
    let args: Vec<String> = env::args().collect();

    let A = read::<i32>();
    let B = read::<i32>();
    let C = read::<i32>();
    let D = read::<i32>();

    let start = {
        if A < C {
            C
        } else {
            A
        }
    };
    let end = {
        if B < D {
            B
        } else {
            D
        }
    };

    let mut t = end - start;
    if t < 0 {
        t = 0;
    }

    println!("{}", t);
}


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

using namespace std;

int p[100005];

int main(){
	int n;
	cin >> n;
	int sum = 0;
	for(int i=0;i<n;i++){
		cin >> p[i];
		sum += p[i];
	}
	sort(p,p+n);
	sum -= p[n-1]/2;
	cout << sum;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {

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

        int n = scan.nextInt();
        int a[] = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = scan.nextInt();
        }
        if (n != 1) {
        for (int i = n - 1; i >= 0; i = i - 2) {
            System.out.print(a[i] + " ");
        }
        int s = (n % 2 == 0 ? 0 : 1);

        for (int i = s; i < n - 2; i = i + 2) {
            System.out.print(a[i] + " ");
        }
        System.out.println(a[n - 2]);
    }else{
            System.out.println(a[0]);
        }
}

}

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

using namespace std;

int main()
{
	int n;
	cin>>n;
	long long int sum=0;
	for(int i=1;i<=n;i++) {
		if(i%3==0||i%5==0) continue;
		sum+=i;
	}
	cout<<sum<<'\n';
	return 0;
} 

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

typedef long long ll;

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define ANS(n) cout << (n) << endl

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(a);i>=(b);i--)

#define ALL(obj) (obj).begin(),(obj).end()

#define pii pair<int,int>

#define pb(a) push_back(a)
#define mp make_pair

int main()
{
	int n,m;
	cin >> n >> m;
	int a[n], b[n];
	FOR(i,0,n)cin >> a[i] >> b[i];
	int c[m],d[m];
	FOR(i,0,m)cin >> c[i] >> d[i];
	FOR(i,0,n){
		int ans = -1;
		ll dist = LLINF;
		FOR(j,0,m){
			ll ndist = abs((ll)a[i] - c[j]) + abs((ll)b[i] - d[j]);
			if(ndist < dist){
				ans = j+1;
				dist = ndist;
			}
		}
		ANS(ans);
	}
	return 0;
}


Measured memory_bytes: 256
/**
*    created: 23.06.2020 23:56:19
**/
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pcnt(bit) __builtin_popcount(bit)
#define mod 1000000007
#define pi acos(-1.0)
using namespace std;

signed main() {

    cin.tie(0);
    ios_base::sync_with_stdio(false);

    string s;
    cin >> s;
    if (s[2] == s[3] && s[4] == s[5]) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

typedef long long ll;

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define ANS(n) cout << (n) << endl

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(a);i>=(b);i--)

#define ALL(obj) (obj).begin(),(obj).end()

#define pii pair<int,int>

#define pb(a) push_back(a)
#define mp make_pair

int main()
{
	int n;
	cin >> n;
	int cnt[26];
	FOR(i,0,26)cnt[i] = 1;
	FOR(i,0,n){
		char a;
		cin >> a;
		cnt[a - 'a']++;
	}
	ll ans = 1;
	FOR(i,0,26)ans = ans * cnt[i] % MOD;
	ans--;
	ANS(ans);
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define F first
#define S second
#define MP make_pair
#define pb push_back
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;
typedef pair< int, P > iP;
typedef pair< P, P > PP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    string a, b;
    cin >> a >> b;
    if( a.size() > b.size() ) cout << "GREATER";
    else if( a.size() < b.size() ) cout << "LESS";
    else {
        bool flg = true;
        for( int i = 0; i < a.size(); ++i ) {
            if( a[i] > b[i] ) {
                flg = false;
                cout << "GREATER";
                break;
            } else if( a[i] < b[i] ) {
                flg = false;
                cout << "LESS";
                break;
            }

        }
        if( flg ) cout << "EQUAL";
    }

    cout << endl;
    return 0;
}


Measured memory_bytes: 256
h,w,k = map(int,input().split())
from itertools import product
import copy

arr = []
for i in range(h):
    string = input()
    line = []
    for moji in string:
        if moji == '.':
            line.append(0)
        else:
            line.append(1)
    arr.append(line)

row = list(range(h))
col = list(range(w))
ans = 0


for bits in product((0, 1), repeat=len(row)):
    combrow = [x for x, bit in zip(row, bits) if bit == 1]
    
    for bits in product((0, 1), repeat=len(col)):
        combcol = [x for x, bit in zip(col, bits) if bit == 1]
    
        tmparr = copy.deepcopy(arr)
        

        for delrow in combrow:
            tmparr[delrow] = [0]*w
        
        for delcol in combcol:
            for i in range(h):
                tmparr[i][delcol]=0
        
        
        count = 0
        for line in tmparr:
            count += sum(line)
        if count == k:
            ans += 1


print(ans)

Measured memory_bytes: 9360
#define REP(i,n) for(int i=0; i<(int)(n); i++)
 
#include <queue>
#include <set>
#include <cstdio>
inline int getInt(){ int s; scanf("%d", &s); return s; }
 
using namespace std;
 
int main(){
  const int n = getInt();
  const int t = getInt();
  const int e = getInt();
 
  REP(i,n){
    const int x = getInt();
 
    REP(j,t + 1){
      const int xx = x * j;
      if(t - e <= xx && xx <= t + e){
        printf("%d\n", i + 1);
        return 0;
      }
      if(t + e < xx) break;
    }
  }
 
  puts("-1");
 
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
const ll INF = 1e8;
const ll MOD = 1e9 + 7;

int cnt(int n) {
    int cnt = 0;
    while (n%2 == 0) {
        cnt ++;
        n /= 2;
    }
    return cnt;
}

int main() {
    int n; cin >> n;
    int ans = INF;
    for (int i = 0; i < n;i ++) {
        int a; cin >> a;
        ans = min(ans,cnt(a));
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize(2)
#pragma G++ optimize(2)
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<cmath>
#include<map>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
using namespace std;

#define pa pair<int,int>
#define sc(n) scanf("%d",&n)
#define ss(n) scanf("%s",n)
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define mes(a,b) memset(a,b,sizeof a)
#define mem(a,b,n) memset(a,b,n*sizeof(int))
#define uint unsigned int

const  int N = 1e6 + 10;
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;

typedef long long ll;
typedef long double ld;

int t,n,m;
int a[100];
int b[100];

int main()
{
	sc(n);
	fo(i,1,n)
	{
		sc(a[i]);
		b[i]=a[i];
	}
	int cnt=0;
	sort(a+1,a+n+1);
	fo(i,1,n)
	{
		if(b[i]!=a[i])
			cnt++;
	}
	if(cnt<=2)
		puts("YES");
	else
		puts("NO");

}



Measured memory_bytes: 256
# 幅優先探索（行きがけ）
import collections
import sys
import copy
import re


def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())


def main():
    H, W, K = LI()
    c = []

    N = H+W
    for i in range(H):
        c.append(list(S()))

    ans = 0
    for i in range(2**N):
        cow = []
        row = []
        cCopy = copy.deepcopy(c)
        blacks = 0
        for j in range(N):
            if ((i >> j) & 1):  # 順に右にシフトさせ最下位bitのチェックを行う
                if j >= W:
                    row.append(j)
                else:
                    cow.append(j)
        for h in range(H):
            if (h+W) in row:
                continue
            else:
                for w in range(W):
                    if w in cow:
                        continue
                    if cCopy[h][w] == "#":
                        blacks += 1

        if blacks == K:
            ans += 1

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 10012
#include <iostream>
#include <cstdint>
#include <cstdint>
#include <algorithm>
#include <vector>

using namespace std;

int a[100'000];
int acc[100'000];

int main()
{
    int n;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    sort(a, a + n);

    int ax = 0;
    for (int i = 0; i < n; i++)
    {
        ax += a[i];
        acc[i] = ax;
    }

    int negs = 0;
    int mscore = -1000'000'000;
    for (int i = 1; i <= n - 1; i++)
    {
        int hisum = acc[n - 1] - acc[i - 1];
        int losum = acc[i - 1];
        int score = hisum - losum;

        if (mscore < score)
        {
            mscore = score;
            negs = i;
        }
    }
    cout << mscore << endl;

    vector<int> po;
    vector<int> ne;

    for (int i = 0; i < n; i++)
    {
        if (i < negs)
        {
            ne.push_back(a[i]);
        }
        else
        {
            po.push_back(a[i]);
        }
    }

    int tmp = po[0];
    po[0] = ne[0];
    ne[0] = tmp;

    int x = ne[0];
    for (int i = 1; i < ne.size(); i++)
    {
        cout << x << " " << ne[i] << endl;
        x = x - ne[i];
    }

    int y = po[0];
    for (int i = 1; i < po.size(); i++)
    {
        cout << y << " " << po[i] << endl;
        y = y - po[i];
    }

    cout << x << " " << y << endl;

    return 0;
}

Measured memory_bytes: 3192
#include <bits/stdc++.h>
#define N 1000001
using namespace std;
typedef pair <int,int> P;
int n,u,v,m,num[N];
P U[N],V[N];

void in(P a[]){
  for(int i=1;i<=n;i++)
    for(int j=1,b;j<=n;j++) cin>>b,a[b]=P(i,j);
}

int game(P A[],int B){
  int ta[501]={},yo[501]={},X[2]={},cnt=n!=1? 0:-3;

  for(int i=0;i<m;i++){
    int y=A[num[i]].first,x=A[num[i]].second;
    if(x==0)continue;
    X[0]+=(x==y),X[1]+=(x+y==n+1);
    if(X[0]==n) X[0]=-1e9,cnt++;
    if(X[1]==n) X[1]=-1e9,cnt++;
    cnt+=(++ta[y]==n)+(++yo[x]==n);
    if(cnt>=B)return i;
  }
  return m;
}

int main(){
  cin>>n>>u>>v>>m;
  in(U),in(V);
  for(int i=0;i<m;i++) cin>>num[i];
  int Uscore=game(U,u);
  int Vscore=game(V,v);
  if(Uscore<Vscore) cout <<"USAGI"<<endl;
  else if(Uscore>Vscore)cout <<"NEKO"<<endl;
  else cout<<"DRAW"<<endl;
  return 0;
}

Measured memory_bytes: 17544
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>
#include <math.h>
using namespace std;

int main()
{
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
	}
	int count = 0;
	for (int i = 0; i < n; ++i) {
		bool pr = true;
		for (int j = 2; j * j <= a[i]; ++j) {
			if (a[i] % j == 0) {
				pr = false;
				break;
			}
		}
		if (pr) {
			count++;
		}
	}
	cout << count << endl;

	return 0;
}



Measured memory_bytes: 3100
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'
#define rep(i, n)    for(ll i = 0; i < (n); ++i)
#define repA(i, a, n)  for(ll i = a; i <= (n); ++i)
#define repD(i, a, n)  for(ll i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (ll)(x).size()
#define unique_sort(x) (sort(x.begin(), x.end()), x.resize(distance(x.begin(), unique(x.begin(), x.end()))))
#define fill(a)  memset(a, 0, sizeof (a))
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
typedef long double ld;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
const ll mod = 1e9+7;

int main()
{
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    ll tt=1;
        // cin >> tt;
    while((tt)--){
        ll a,b; cin >> a >> b;
        repA(i,1,1e3){
            ll a1 = i*8/100 ,b1 = i*10/100;
            if(a1==a and b1==b ){
                cout << i << endl;
                return 0;
            }
        }
        cout << -1 << endl;

    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define all(x) x.begin(),x.end()
#define let auto const

template<typename... Types>
struct dynarr: std::vector<Types...> {
  using std::vector<Types...>::vector;
  using size_type = typename std::vector<Types...>::size_type;
  auto&& operator[](size_type i) { return this->at(i); }
  auto&& operator[](size_type i) const { return this->at(i); }
};

struct query {
  i64 type;
  i64 x;
  i64 s;
  i64 t;
};


int main() {
  i64 N, Q, L, R;
  cin >> N >> Q >> L >> R;
  vector<i64> A(N);
  rep(i,0,N) {
    cin >> A[i];
  }
  sort(all(A));
  vector<query> qq;
  rep(i,0,Q) {
    i64 type, x, s, t;
    cin >> type >> x >> s >> t;
    qq.push_back({ type, x, s, t });
  }

  auto calc = [&](i64 i) {
    i64 a = A[i];
    for(auto q: qq) {
      i64 x = q.x;
      i64 s = q.s;
      i64 t = q.t;
      if(q.type == 1) {
        if(x <= a) {
          a = (a + s) * t;
        }
      }
      else {
        if(a <= x) {
          a = (a - s) / t;
        }
      }
    }
    return a;
  };

  i64 Li;
  i64 Ri;

  {
    i64 OK = -1;
    i64 NG = N;

    while(abs(NG - OK) > 1) {
      i64 m = (OK + NG) / 2;
      if(calc(m) < L) { OK = m; }
      else { NG = m; }
    }
    Li = OK;
  }
  {
    i64 OK = -1;
    i64 NG = N;

    while(abs(NG - OK) > 1) {
      i64 m = (OK + NG) / 2;
      if(calc(m) <= R) { OK = m; }
      else { NG = m; }
    }
    Ri = OK;
  }
  cout << Ri - Li << endl;
}



Measured memory_bytes: 12796