akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main{

public static void main(String[] args) {

// write your code here.
Scanner scn=new Scanner (System.in);
int x=scn.nextInt();
int n=scn.nextInt();
int []arr=new int[n];
boolean temp=false;
for(int i=0;i<n;i++){
    arr[i]=scn.nextInt();
    if(arr[i]==x){
        temp=true;
    }
}
Arrays.sort(arr);
if(arr.length==0){
    System.out.println(x);
    return;
}
if( temp==false){
    System.out.println(x);
    return;
}
int idx=0;
for(int i=0;i<arr.length;i++){
    if(arr[i]==x){
        idx=i;
    }
    
}

int p1=idx+1;
int p2=idx-1;
int val=1;
while(p1!=arr.length && p2!=-1){
    if(arr[p2]!=x-val){
      
        System.out.println(x-val);
        return;
    }
    if(arr[p1]!=x+val){
         
        System.out.println(x+val);
        return;
    }
    val++;
    p2--;
    p1++;
}
if(p1!=arr.length){

   System.out.println(x-val);
   return;
}
if(p2!=-1){
    
    if(arr[p2]==x-val){
         
        System.out.println(x+val);
        return;
    }
      
     System.out.println(x-val);
     return;
}
System.out.println(arr[0]-1);



 }
}

Measured memory_bytes: 35920
#include <bits/stdc++.h>
using namespace std;
  
int n;
int m;
double dp[2][(1 << 16) + 1][17];
double P[17][17];
  
int main() {
  scanf("%d%d", &m, &n);
  for (int i=0; i<m; i++) {
    for (int j=0; j<n; j++) {
      scanf("%lf", &P[i][j]);
    }
  }
  
  int dst = 0;
  int src = 1;
  int lim = 1 << m;
  for (int i=1; i<lim; i++) {
    for (int j=0; j<m; j++) {
      if (!(i >> j & 1)) continue;
     dp[src][i][j] = 1.0;
    }
    dp[src][i][n] = 1.0;
  }

  for (int i=n-1; i>=0; --i) {
    for (int st=0; st<lim; ++st) {
      for (int j=0; j<m; j++) {
        if (!(st >> j & 1)) continue;
        double p = 1.0;
        double cand = 0.0;
        int nst = st & ~(1 << j);
        cand += dp[dst][nst][m]*(1-P[j][i]);
        cand += dp[src][st][j]*P[j][i];
        dp[dst][st][j] = cand;
        dp[dst][st][m] = max(dp[dst][st][m], cand);
      }
    }
    swap(src, dst);
    fill(dp[dst][0], dp[dst][lim], 0);
  }
  printf("%.20f\n", dp[src][lim-1][m]);
}

Measured memory_bytes: 20580
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int Inf = 1000000000;
constexpr ll INF= 1000000000000000000;
constexpr ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<int,int> P;

template<typename T>
T Pow(T a,T b) {
    T ret = 1;
    for(int i = 0;i < b;i++) {
        ret *= a;
    }
    return ret;
}
 
ll mod(ll val) {
    ll res = val % MOD;
    if(res < 0) {
        res += MOD;
    }
    return res;
}
 
ll RS(ll N, ll P, ll M){
    if(P==0) return 1;
    if(P < 0) {
        return 0;
    }
    if(P%2==0){
        ll t = RS(N, P/2, M);
        return t*t % M;
    }
    return N * RS(N, P-1, M) % M;
}

int main() {
    int A,B,C,D,E;
    cin >> A >> B >> C >> D >> E;
    if(A == 0) {
        cout << 1 << endl;
    }
    else if(B == 0) {
        cout << 2 << endl;
    }
    else if(C == 0) {
        cout << 3 << endl;
    }
    else if(D == 0) {
        cout << 4 << endl;
    }
    else {
        cout << 5 << endl;
    }
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
const long double PI = (acos(-1));
 
int main() {
  ld a,b,x;
  cin >> a >> b >> x;
  
  ld V = a * a * b;
  ld theta;
  if (x <= V / 2.0) {
    ld Left = 0;
    ld Right = PI / 2.0;
    while (true) {
      ld pivot = (Left + Right) / 2.0;
      if (a*b*b  * tan(PI / 2 - pivot) / 2 > x) Left = pivot;
      else if (a*b*b * tan(PI / 2 - pivot) / 2 < x) Right = pivot;
      else {
        theta = pivot;
        break;
      }
      if (abs(a*b*b * tan(PI / 2 - pivot) / 2 - x) < 0.000000001) {
        theta = pivot;
        break;
      }
    }
  } else if (x > V / 2.0) {
    ld Left = 0;
    ld Right = PI / 2.0;
    while (true) {
      ld pivot = (Left + Right) / 2.0;
      if (a*a*a * tan(pivot) / 2 > (V - x)) Right = pivot;
      else if (a*a*a * tan(pivot) / 2 < (V - x)) Left = pivot;
      else {
        theta = pivot;
        break;
      }
      if (abs(a*a*a * tan(pivot) / 2 - (V - x)) < 0.000000001) {
        theta = pivot;
        break;
      }
    }
  }
  
  theta = theta * 180 / PI;
  
  cout << fixed << setprecision(10) << theta << endl;

    
}

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

//|\\---------------//|\\
//|\\RISE FROM ASHES//|\\
//|\\---------------//|\\

int main() {
    int t;
    cin>>t;
    if(t>=30){
        cout<<"Yes";
    }
    else 
        cout<<"No";
    return 0;
}

Measured memory_bytes: 3624
/*#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>*/
#include<bits/stdc++.h>
using namespace std;

#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORE(i,a,b) for(int i=a;i<=b;i++)
#define RFOR(i,a,b) for(int i=(a);i>(b);i--)
#define RFORE(i,a,b) for(int i=(a);i>=(b);i--)
typedef unsigned long long ull;
typedef long long ll;

int main(){
    int n;
    cin >> n;
    int a[100];
    FOR(i,0,n){
        cin>>a[i];
        if(a[i]>i+1){
            printf("-1\n");
            return 0;
        }
    }
    int ans[100];
    FORE(j,1,n){
        RFORE(i,n-j,0){
                if(a[i]==i+1){
                    ans[n-j]=i+1;
                    FOR(k,i,n-j){
                        a[k]=a[k+1];
                    }
                    break;}
        }
    }
    FOR(i,0,n){
        cout<<ans[i]<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <vector>
#include <string>
#include <algorithm>
#include <iterator>
#include <map>
#include <utility>
#include <list>
#include <climits>
#include <bitset>
#include <numeric>
#include <iomanip>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, n) for(auto i = (n).begin(); i != (n).end(); i++)
#define in_arr(type, a, n) copy_n(istream_iterator<type>(cin), n, (a).begin());
#define ll long long int

int main(){
    float x, t;
    cin >> t >> x;
    cout << fixed << setprecision(7);
    cout << t / x << endl;
    return 0;
}


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

void solve();

string s;

int main(){
    ios::sync_with_stdio(0), cin.tie(0);
    while (cin >> s) {
        solve();
    }
    return 0;
}

void solve() {
    int len = s.size();
    if (s[len-1] == 's') {
        cout << s << "es\n";
    } else {
        cout << s << 's' << '\n';
    }
}


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

int main(){
    string s;
    cin >> s;
    int N = s.size();
    char c = '+';//RでもLでもないもの。
    vector<int> begins;
    for(int i =0; i < N; i++){
        if(c != s.at(i)){
            begins.push_back(i);
            c = s.at(i);
        }
    }
    begins.push_back(N);
    vector<int> ans(N);
    for(int i = 1; i < begins.size() - 1; i++){
        if(i%2 == 1){
            ans[begins.at(i) - 1] = (begins[i]- begins[i-1] + 1)/2 +(begins[i+1]- begins[i])/2;
            ans[begins.at(i)] = (begins[i]- begins[i-1])/2 +(begins[i+1]- begins[i] + 1)/2;
        }
    }
    for(int i =0; i < N; i++){
        cout << ans.at(i) << " ";
    }
    cout << endl;
}

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

#define ll long long
#define mod 1000000007
#define pll pair<long long,long long>
#define pdd pair<long double,long double>
#define vll vector<ll>
#define rep(i,j,n) for(int i=j;i<n;i++)
#define mp make_pair
#define pb push_back
#define pf push_front
#define inf 1e17
priority_queue<pll,vector<pll>,greater<pll> >pq;
priority_queue<ll,vector<ll>,greater<ll> >pq1;

ll result(ll a, ll b, ll p){
    ll ans=1;
    if(b==(-1))
        b=p-2;
    while(b){
        if(b&1){
            ans=(ans*a)%p;
        }
        a=(a*a)%p;
        b>>=1;
    }
    return ans;
}

int main(){
    if(fopen("input.txt", "r"))
    freopen("input.txt", "r", stdin),
    freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n, p;
    cin >> n >> p;
    string s;
    cin >> s;
    vector<ll>arr(n);
    map<ll,ll>m;
    ll g=0;
    ll d=1;
    for(int i=n-1;i>=0;i--){
        ll f=s[i]-'0';
        g =( g+d*f)%p;
        m[g]++;
        d =(d*10)%p;
    }
    ll ans=0;
    if(p==2 || p==5){
        ans=0;
        for(int i=0;i<n;i++){
            ll f=s[i]-'0';
            if(f%p==0)
                ans+=(i+1);
        }
        cout<<ans<<"\n";
        return 0;
    }
    m[0]++;
    for(int i=0;i<p;i++){
        ans += ((m[i]*(m[i]-1))/2);
    }
    cout<<ans;

    return 0;
        
}


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

using ll = long long;

#define vl vector<long long>
using pll = pair<long long, long long>;
#define __ << '\n'
#define _ << ' '
#define all(x) (x).begin(), (x).end()

void error()
{
    cout << "-1";
    exit(0);
}

#define flush fflush(stdout)

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

    int n;
    cin >> n;
    string a, b, c;
    cin >> a >> b >> c;
    ll answer = 0;
    for (auto i = 0; i < n; i++)
    {
        if (a[i] == b[i])
        {
            if (b[i] != c[i])
                answer++;
        } else
        {
            if (a[i] == c[i])
                answer++;
            else if (b[i] == c[i])
                answer++;
            else
                answer += 2;
        }
    }
    cout << answer;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,x,n) for(int i = x; i < n; i++)
#define MAX 100
#define INF 1000000001

// enum {
//   AST_INT,
//   AST_SYM,
//   AST_STR,
//   AST_FUNCALL,
// };



// double winProb(int Rp, int Rq) {
//     return 1/(1+pow(10, (Rq-Rp)/400.));
// }

// int R[1<<10];
// double dp[12][1<<10];
int n,m;
vector<long long> x;
vector<long long> y;

int main() {
   cin >> n >> m;
   
   REP(i,0,n) {
       int tmp;
       cin >> tmp;
       x.push_back(tmp);
   }
   REP(i,0,m) {
       int tmp;
       cin >> tmp;
       y.push_back(tmp);
   }
   
//   cout << (n-1) * (m-1) << endl;
   
   sort(x.begin(),x.end());
   sort(y.begin(),y.end());
   
   long long sum_x = 0;
   REP(k,0,n) {
       sum_x += k*x[k] - (n-1-k)*x[k];
    //   cout << sum_x << endl;
   }
   
   long long sum_y = 0;
   REP(k,0,m) {
       sum_y += k*y[k] - (m-1-k)*y[k];
   }
   
//   cout << sum_x << endl;
   cout << ((sum_x % 1000000007) * (sum_y % 1000000007)) % 1000000007 << endl;
   
}

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

int main() {
    int n,m,X,Y;
    cin >> n >> m >> X >> Y;
    vector<int> x(n),y(m);
    rep(i,n) cin >> x[i];
    rep(i,m) cin >> y[i];
    sort(all(x));
    sort(all(y));
    if(x[n-1] < y[0] && x[n-1] < Y && y[0] > X) cout << "No War" << endl;
    else cout << "War" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
 
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define _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__)

int main(){
    int apple;
    cin>>apple;
    int pieces;
    cin>>pieces;
    pieces+=apple*3;
    cout<<pieces/2<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int,int> P;
 
const int INF = 1e9;
const int mod = 1e9+7;
const double EPS = 1e-10;
const double PI = acos(-1.0);
 
int main()
{
    int n,h;
    cin >> n >> h;
    vector<int> a(n),b(n);
    for(int i = 0; i < n; i++) cin >> a[i] >> b[i];
    sort(a.rbegin(),a.rend()),sort(b.rbegin(),b.rend());
    int sum = 0;
    for(int i = 0; i < n && b[i] > a[0]; i++) sum += b[i];
    int res = 0;
    while(h>0){
        if(sum < h){
            h -= a[0];
            res++;
        }else{
            for(int i = 0; h > 0; i++){
                h -= b[i];
                res++;
            }
            break;
        }
    }
    cout << res << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());
const double pi = 3.141592653589793;

int n, m, par[100001];
vector<int> adj[100001];

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n >> m;
	for(int i = 0; i < m; i++){
		int a, b;
		cin >> a >> b;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
	queue<int> que;
	que.push(1);
	par[1] = 1;
	while(!que.empty()){
		int vtx = que.front();
		que.pop();
		for(auto &i : adj[vtx])
			if(!par[i]){
				que.push(i);
				par[i] = vtx;
			}
	}
	bool val = true;
	for(int i = 1; i <= n; i++)
		if(!par[i]) val = false;
	if(!val) cout << "No\n";
	else{
		cout << "Yes\n";
		for(int i = 2; i <= n; i++) cout << par[i] << "\n";
	}
	return 0;
}

Measured memory_bytes: 10524
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010


int N, A[SIZE];
ll sum[SIZE];
int ptr[SIZE];
ll M;

int main() {

  scanf("%d%lld", &N, &M);

  for (int i=0; i<N; i++)
    scanf("%d", A+i);

  sort(A, A+N);

  for (int i=N-1; i>=0; i--) {
    sum[i] = sum[i+1] + A[i];
  }

  priority_queue<pair<ll,int>> pq;

  ll l = 0, r = 2e5;

  while (l < r) {
    ll mid = (l + r + 1) / 2;

    ll counter = 0;

    for (int i=0; i<N; i++) {
      counter += (A + N) - lower_bound(A, A+N, mid - A[i]);
    }

    if (counter < M) {
      r = mid - 1;
    } else {
      l = mid;
    }
  }

  ll ans = 0, counter = 0;

  for (int i=0; i<N; i++) {
    int t = (A + N) - lower_bound(A, A+N, l - A[i]);

    ans += (ll)A[i] * t;
    ans += sum[N-t];

    counter += t;
  }

  debug(l); debug(counter);

  assert(counter >= M);

  ans -= (counter - M) * l;


  cout << ans << endl;

  return 0;
}


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

template<typename T, typename U>
using pv=vector<pair<T,U>>;
template<typename T>
using matrix=vector<vector<T>>;
template<typename T>
using pque=priority_queue<T>;
template<typename T>
using lpque=priority_queue<T,vector<T>,greater<T>>;

using ll=long long;
using intpair=pair<int,int>;
using llpair=pair<ll,ll>;
using ilpair=pair<int,ll>;
using lipair=pair<ll,int>;
using intvec=vector<int>;
using llvec=vector<ll>;
using intq=queue<int>;
using llq=queue<ll>;
using intmat=vector<intvec>;
using llmat=vector<llvec>;

#define PI 3.141592653589793
#define INTINF 1<<30
#define LLINF 1LL<<60
#define MPRIME 1000000007
#define MPRIME9 998244353
#define MMPRIME (1ll<<61)-1

#define len length()
#define pushb push_back
#define fi first
#define se second

#define setpr fixed<<setprecision(15)
#define all(name) name.begin(),name.end()
#define rall(name) name.rbegin(),name.rend()
#define gsort(vbeg,vend) sort(vbeg,vend,greater<>())

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

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

template<class T>
inline void outmat(T& a, int y, int x) {
	for(int i=0; i<y; i++) {
		for(int j=0; j<x; j++) cout<<a[i][j]<<" ";
		cout<<endl;
	}
}

template<class T>
inline void init(T& v) {
	for(auto &a: v) cin>>a;
}
template<class T, class U>
inline void init(vector<pair<T,U>>& v) {
	for(auto &a: v) cin>>a.first>>a.second;
}
template<class T, class N>
inline void init(T& v, N n) {
	v.resize(n);
	for(auto &a: v) cin>>a;
}
template<class T, class U, class N>
inline void init(vector<pair<T,U>>& v, N n) {
	v.resize(n);
	for(auto &a: v) cin>>a.first>>a.second;
}

template<class N>
void resiz(N n) {
	//empty
}
template<class N, class T, class... U>
void resiz(N n, T&& hd, U&&... tl) {
	hd.resize(n);
	resiz(n,forward<U>(tl)...);
}

ll binpow(ll a, ll ex, ll p) { //繰り返し二乗法
	ll result=1;
	while(ex>0) {
		if(ex&1) result=result*a%p;
		ex>>=1;
		a=a*a%p;
	}
	return result;
}


int N,A,B,C;
intvec L;
int res=INTINF;

void input() {
	cin>>N>>A>>B>>C;
	init(L,N);
}

void solve() {
	for(int bit=0; bit<(1<<(N*2)); bit++) {
		int a=0, b=0, c=0;
		int tmp=-30;
		for(int i=0; i<N; i++) {
			switch((bit>>(i*2))&3) {
				case 1:
					a+=L[i];
					tmp+=10;
					break;
				case 2:
					b+=L[i];
					tmp+=10;
					break;
				case 3:
					c+=L[i];
					tmp+=10;
					break;
				default:
					break;
			}
		}
		if(!a || !b || !c) continue;
		tmp+=abs(A-a)+abs(B-b)+abs(C-c);
		chmin(res,tmp);
	}
	cout<<res<<endl;
}

int main() {
	int t=1;
	while(t) {
		input();
		solve();
		t--;
	}
}


Measured memory_bytes: 3556
#!/usr/bin/env python
from collections import deque, defaultdict
from itertools import combinations, combinations_with_replacement
import bisect
from math import factorial, sqrt, log, ceil, floor

def main():
    N, K = map(int, input().split())

    s = set(range(1, N+1))
    for k in range(K):
        d = int(input())
        As = list(map(int, input().split()))
        for a in As:
            if a in s:
                s.remove(a)

    print(len(s))

if __name__ == '__main__':
    main()


Measured memory_bytes: 9512
from collections import defaultdict
n = int(input())
v = [int(x) for x in input().split()]

even_ocr = defaultdict(int) # v[0], v[2], ..., で各数が何回現れるか
odd_ocr = defaultdict(int)  # v[1], v[3], ..., で各数が何回現れるか

for i in range(n // 2):
    even_ocr[v[2 * i]] += 1
    odd_ocr[v[2 * i + 1]] += 1

even_max_num = 0;  even_max_ocr = 0;
odd_max_num = 0;  odd_max_ocr = 0;
for (num, ocr) in even_ocr.items():
    if ocr > even_max_ocr:
        even_max_ocr = ocr
        even_max_num = num

for (num, ocr) in odd_ocr.items():
    if ocr > odd_max_ocr:
        odd_max_ocr = ocr
        odd_max_num = num

if even_max_num != odd_max_num:
    ans = n - even_max_ocr - odd_max_ocr
else:
# 偶数番目に一番多く現れる数と奇数番目に一番多く現れる数が同じ
    even_next_num = 0;  even_next_ocr = 0;
    odd_next_num = 0;  odd_next_ocr = 0;
    for (num, ocr) in even_ocr.items():
        if num != even_max_num and ocr > even_next_ocr:
            even_next_ocr = ocr
            even_next_num = num

    for (num, ocr) in odd_ocr.items():
        if num != odd_max_num and ocr > odd_next_ocr:
            odd_next_ocr = ocr
            odd_next_num = num

    if even_next_ocr + odd_max_ocr > even_max_ocr + odd_next_ocr:
        # 偶数番目は二番目に多い数、奇数番目は一番多い数に揃える
        ans = n - even_next_ocr - odd_max_ocr
    else:
        ans = n - even_max_ocr - odd_next_ocr

print(ans)

Measured memory_bytes: 17432
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <assert.h>
#include <fstream>

using namespace std;

const int MAXN = 2005;

int n,m,q;
int xa,ya,xb,yb;
int a[MAXN][MAXN];
int r[MAXN][MAXN];
int c[MAXN][MAXN];

string s;

int main()
{
	ios::sync_with_stdio(0);
	cin >> n >> m >> q;
	for (int i = 1;i <= n;i++)
	{
		cin >> s;
		for (int j = 0;j < m;j++)
			a[i][j + 1] = s[j] - '0';
	}
	for (int i = 1;i <= n;i++)
		for (int j = 1;j <= m;j++)
			if (a[i][j] && a[i][j - 1])
				r[i][j] = 1;
	for (int i = 1;i <= n;i++)
		for (int j = 1;j <= m;j++)
			if (a[i][j] && a[i - 1][j])
				c[i][j] = 1;
	for (int i = 1;i <= n;i++)
		for (int j = 1;j <= m;j++)
			a[i][j] = a[i][j] + a[i - 1][j] + a[i][j - 1] - a[i - 1][j - 1];
	for (int i = 1;i <= n;i++)
		for (int j = 1;j <= m;j++)
			r[i][j] = r[i][j] + r[i - 1][j] + r[i][j - 1] - r[i - 1][j - 1];
	for (int i = 1;i <= n;i++)
		for (int j = 1;j <= m;j++)
			c[i][j] = c[i][j] + c[i - 1][j] + c[i][j - 1] - c[i - 1][j - 1];
	while (q--)
	{
		cin >> xa >> ya >> xb >> yb;
		int nodes = a[xb][yb] - a[xa - 1][yb] - a[xb][ya - 1] + a[xa - 1][ya - 1];
		int edges = r[xb][yb] - r[xa - 1][yb] - r[xb][ya] + r[xa - 1][ya] + 
					c[xb][yb] - c[xa][yb] - c[xb][ya - 1] + c[xa][ya - 1];
		cout << nodes - edges << endl;
	}
	return 0;
}

Measured memory_bytes: 48896
/*
 * main.c
 *
 *  Created on: 2019/03/03
 *      Author: family
 */


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

int main()
{
	int a = 0, b = 0, c = 0;
	int sound = 0;
	scanf("%d %d %d", &a, &b, &c);

	sound = b/a;
	if (sound >= c) {
		sound = c;
	}
	printf("%d\n", sound);
	return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (true) {
            int h = Integer.parseInt(sc.next()); 
            int w = Integer.parseInt(sc.next());
            if (h == 0 && w == 0) {
                break;
            } else {
                for (int j = 0; j < h; j++) {
                    for (int i = 0; i < w; i++) {
                        System.out.print("#");
                    }
                    System.out.println();
                }
                System.out.println();
            }
        }
    }
}


Measured memory_bytes: 33148
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from heapq import heapify, heappop, heappush
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

A, B = MAP()

def f(X):
    if X % 2 == 1:
        one_num = (X + 1) // 2
        if one_num % 2 == 0:
            return 0
        else:
            return 1
    else:
        one_num = X // 2
        if one_num % 2 == 0:
            return 0 ^ X
        else:
            return 1 ^ X
print(f(B) ^ f(A-1))



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

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             INT_MAX
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define all(x)			x.begin(),x.end() 
#define FIO				ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)


int nCr(int n , int r ) {
	int p = 1, k = 1;

	if (n - r < r ) {
		r = n - r;
	}
	if (r != 0) {
		while (r != 0) {
			p *= n ;
			k *= r ;
			int m = __gcd(p, k);
			p /= m;
			k /= m;
			n--;
			r--;
		}
	}
	else {
		p = 1;
	}
	return p ;
}

int lcm(int x , int y){
	return (x * y) / __gcd(x, y);
}

int modPower(int x, int y , int p) {
	//Used to calculate (x^y)%p
	int res = 1;
	if (y == 0) {
		return 1;
	}

	x = x % p;
	if (x == 0) {
		return 0  ;
	}

	while (y > 0) {
		if (y & 1) {
			res = (res * x) % p;
		}

		y >>= 1;
		x = (x * x) % p;
	}
	return res ;

}

void aryan_p() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	return;
}



int32_t main() {
	//aryan_p();
	FIO;

	int k, x;
	cin >> k >> x;
	if(k*500>=x){
		cout << "Yes";
	}
	else{
		cout << "No";
	}



	return 0;
}


Measured memory_bytes: 3644
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

def deepcopy(li):
    return [x[:] for x in li]

H,W,K=MAP()
orgn=[[0]*W for i in range(H)]
for i in range(H):
    nums=input()
    for j in range(W):
        orgn[i][j]=int(nums[j])

# ブロックが落ちる動き
def drop():
    for i in range(H-1, 0, -1):
        for j in range(W):
            if grid[i][j]==0 and grid[i-1][j]!=0:
                k=i
                while k<H and grid[k][j]==0:     
                    grid[k][j]=grid[k-1][j]
                    grid[k-1][j]=0
                    k+=1

# 揃ったところを消して合計を計算
def check(times):
    sm=0
    for i in range(H):
        st=0
        cnt=1
        for j in range(1, W):
            if grid[i][j-1]==grid[i][j]:
                cnt+=1
            else:
                if cnt>=K:
                    sm+=grid[i][j-1]*cnt
                    for k in range(st, j):
                        grid[i][k]=0
                cnt=1
                st=j
        else:
            if cnt>=K:
                sm+=grid[i][j]*cnt
                for k in range(st, j+1):
                    grid[i][k]=0
    return 2**times*sm

ans=0
for i in range(H):
    for j in range(W):
        # 元の状態は保持しておいて、全部試す
        grid=deepcopy(orgn)
        grid[i][j]=0    
        res=1
        score=times=0
        # 消えるところがある限りループ
        while res:
            drop()
            res=check(times)
            score+=res
            times+=1
        ans=max(ans, score)

print(ans)


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

int main(void){
  long long int a=0;
  scanf("%lld",&a);
  long long int sum=a-1;
  long long int b=sqrt(a);

  for(int i=2;i<=b;i++){
	  if(a%i==0){
		  if((a/i+i-2)<=sum){
			  sum=a/i+i-2;
		  }
	  }
  }
  printf("%lld",sum);
  return 0;
}

Measured memory_bytes: 128
#include"bits/stdc++.h"
using namespace std;
int a[105];
int main()
{
    int n,k;
    cin>>n>>k;
    for(int i=0;i<n;i++) cin>>a[i];
    sort(a,a+n);
    int ans=0;
    for(int i=0;i<n;i++){
        if(k>=a[i]){
            k-=a[i];
            ans++;
        }
        else {k=0;break;}
    }
    if(k) ans--;
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <ctype.h>
#include <deque>
#include <queue>
#include <cstring>
#include <set>
#include <list>
#include <map>
#include <random>
#include <unordered_map>
#include <stdio.h>

using namespace std;

typedef long long ll;
typedef std::vector<int> vi;
typedef std::vector<bool> vb;
typedef std::vector<string> vs;
typedef std::vector<double> vd;
typedef std::vector<long long> vll;
typedef std::vector<std::vector<int> > vvi;
typedef vector<vvi> vvvi;
typedef vector<vll> vvll;
typedef std::vector<std::pair<int, int> > vpi;
typedef vector<vpi> vvpi;
typedef std::pair<int, int> pi;
typedef std::pair<ll, ll> pll;
typedef std::vector<pll> vpll;

const long long mod = 1000000007;

#define all(c) (c).begin(),(c).end()
#define sz(c) (int)(c).size()
#define forn(i, a, b) for(int i = a; i < b; i++)

#define pb push_back
#define mp make_pair

int main()
{

    ll a,b,c;
    cin>>a>>b>>c;
    if(a%2==0 || b%2==0 || c%2==0) cout<<0;
    else {
        ll ans = min(b*c, a*c);
        ans = min(ans, a*b);
        cout<<ans;
        
    }
    
    
    
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define ALL(v) (v).begin(), (v).end()
#define ios() ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int,int>;
constexpr ll MOD = 10e9+7;
constexpr ll INF = 1LL << 60;
constexpr int Inf = 1e9;
inline int in() {int x; cin >> x; return x;}
template <typename T> inline void out(const T& x) {cout << x << endl;}
template <class T> inline bool chmin(T &a, T b){if (a > b){a = b;return 1;}return 0;}
template <class T> inline bool chmax(T &a, T b){if (a < b){a = b;return 1;}return 0;}
//UP = 0;RIGHT = 1; DOWN = 2; LEFT =3;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b)
{
  if (a < b)
    gcd(b, a);
  int r;
  while ((r = a % b))
  {
    a = b;
    b = r;
  }
  return b;
}
void eratos(bool * isPrime,int max){
  fill(isPrime,isPrime + max,true);
  isPrime[0] = false; 
  isPrime[1] = false; 
  for(int i=2; i<=max/i; ++i) 
      if(isPrime[i]) 
          for(int j=2; j<=max/i; ++j) 
              isPrime[i*j] = false;    
}
//

signed main()
{
  ios();
  string S;
  cin >> S;
  int tmp1 = 0;
  int tmp2 = 0;
  int L = S.length();
  rep(i,L-1)
  {
    if(S[i] != S[i+1])
    {
      tmp1 ++;
    }
    if(S[L-1-i] !=S[L-1-(i+1)] )
    {
      tmp2 ++;
    }
  }
  cout << min(tmp1,tmp2) << endl;

  
}


Measured memory_bytes: 512
using System;
using System.Collections.Generic;
using System.Text;
using System.Numerics;
using System.IO;


namespace SolutionCS
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            string t = Console.ReadLine();

            int ans = 0;
            for (int i = 0; i < 3; i++)
            {
                if(s[i] ==t[i])
                {
                    ans++;
                }
            }
            Console.WriteLine(ans);
        }
    }
}




Measured memory_bytes: 13140
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
//#########################################
struct Data{
	int time,type,x;
};
bool comp(const Data &a,const Data &b){
	if(a.time == b.time)return a.type < b.type;
	return a.time < b.time;
}
signed main(){
	int n,q;cin >> n >> q;
	vector<Data> res;
	rep(i,n){
		int a,b,c;cin >> a >> b >>c ;
		res.push_back((Data){a-c,1,c});
		res.push_back((Data){b-c,-1,c});
	}
	set<int> st;
	sort(res.rbegin(),res.rend(),comp);
	// rep(i,res.size())trace(res[i].time,res[i].type,res[i].x);
	while(q--){
		int d;cin >> d;
		while(res.size()&&res.back().time <= d){
			auto now = res.back();res.pop_back();
			if(now.type == 1){
				st.insert(now.x);
			}
			else{
				st.erase(now.x);
			}
		}
		// trace(st);
		if(st.size() == 0)cout << -1<< endl;
		else cout << *st.begin() << endl;

	}
	return 0;
}

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

char dir[]{ '+','-','*' };

int calc(int a, int b, char c) {
	switch (c) {
	case '+':return a + b;
	case '-':return a - b;
	case '*':return a*b;
	}
}
bool solve(int a, int b, int c, int d, char c1, char c2, char c3) {
	int i = calc(a, b, c1); int j = calc(i, c, c2); int k = calc(j, d, c3);
	if (k == 10) {
		printf("((%d %c %d) %c %d) %c %d\n", a, c1, b, c2, c, c3, d);
		return true;
	}
	i = calc(b, c, c2); j = calc(a, i, c1); k = calc(j, d, c3);
	if (k == 10) {
		printf("(%d %c (%d %c %d)) %c %d\n", a, c1, b, c2, c, c3, d);
		return true;
	}
	i = calc(c, d, c3); j = calc(a, b, c1); k = calc(j, i, c2);
	if (k == 10) {
		printf("(%d %c %d) %c (%d %c %d)\n", a, c1, b, c2, c, c3, d);
		return true;
	}
	i = calc(b, c, c2); j = calc(i, d, c3); k = calc(a, j, c1);
	if (k == 10) {
		printf("%d %c ((%d %c %d) %c %d)\n", a, c1, b, c2, c, c3, d);
		return true;
	}
	i = calc(c, d, c3); j = calc(b, i, c2); k = calc(a, j, c1);
	if (k == 10) {
		printf("%d %c (%d %c (%d %c %d))\n", a, c1, b, c2, c, c3, d);
		return true;
	}
	return false;
}
int main() {
	int a[4];
	while (1) {
		rep(i, 4)scanf("%d", &a[i]);
		sort(a, a + 4);
		if (!a[0])break;
		do {
			rep(i, 3)rep(j, 3)rep(k, 3) {
				if (solve(a[0], a[1], a[2], a[3], dir[i], dir[j], dir[k]))
					goto g;
			}
		} while (next_permutation(a, a + 4));
		puts("0");
	g:;
	}
}

Measured memory_bytes: 3200
#include <bits/stdc++.h>  // Include every standard library
using namespace std;
int dirx[8] = {-1, 0, 0, 1, -1, -1, 1, 1};
int diry[8] = {0, 1, -1, 0, -1, 1, -1, 1};
#define sqr(x) ((LL)(x) * (x))
#define RESET(a, b) memset(a, b, sizeof(a))
#define ALLA(arr, sz) arr, arr + sz
#define REVERSE(v) reverse(ALL(v))
#define SORTA(arr, sz) sort(ALLA(arr, sz))
#define REVERSEA(arr, sz) reverse(ALLA(arr, sz))
#define TC(t) while (t--)
#define ms(s, n) memset(s, n, sizeof(s))
#define FORall(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define size(a) int((a).size())
#define present(t, x) (t.find(x) != t.end())
#define all(a) (a).begin(), (a).end()
#define uni(a) (a).erase(unique(all(a)), (a).end())
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define prec(n) fixed << setprecision(n)
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)
#define IOS                  \
    ios::sync_with_stdio(0); \
    cin.tie(0);              \
    cout.tie(0);
typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pi> vii;
typedef vector<vi> vvi;
const int m = (int)1e5 + 7;
const int MOD = (int)1e9 + 7;
const int MOD2 = MOD + 2;  //1007681537;
const int INF = (int)1e9;
const ll LINF = (ll)1e18;
const ld PI = acos((ld)-1);
const ld EPS = 1e-9;
inline ll gcd(ll a, ll b) {
    ll r;
    while (b) {
        r = a % b;
        a = b;
        b = r;
    }
    return a;
}
inline ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
inline ll fpow(ll n, ll k, int p = MOD) {
    ll r = 1;
    for (; k; k >>= 1) {
        if (k & 1) r = r * n % p;
        n = n * n % p;
    }
    return r;
}
inline ll isqrt(ll k) {
    ll r = sqrt(k) + 1;
    while (r * r > k) r--;
    return r;
}
inline ll icbrt(ll k) {
    ll r = cbrt(k) + 1;
    while (r * r * r > k) r--;
    return r;
}
inline int inv(int a, int p = MOD) { return fpow(a, p - 2, p); }
int modulo(int a, int b) { return (a % b + b) % b; }
#define db(x) cerr << #x << " = " << (x) << " ";

char arr[1005][1005];

int main() {
    IOS;
    int h, w;
    scanf("%d %d", &h, &w);
    
    for (int a = 0; a < h; a++)
        scanf("%s", arr[a]);

    vvi dp(h,vi(w));
    dp[0][0] = 1;
    for (int a = 0; a < h; a++) {
        for (int b = 0; b < w; b++) {
            if (b < w - 1 && arr[a][b + 1] == '.')
                dp[a][b + 1] = (dp[a][b+1]+dp[a][b]) % MOD;
            if (a < h - 1 && arr[a + 1][b] == '.') 
                dp[a + 1][b] = (dp[a+1][b]+dp[a][b]) % MOD;
        }
    }
    printf("%d", dp[h - 1][w - 1]);
}


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

#define ll long long

signed main()
{
  int a,b,c;
  cin >> a >> b >> c;
  if(a==b&&b==c) cout<< a+b << "\n";
  else if(a+b < b+c && a+b < a+c) cout<< a+b << "\n";
  else if(b+c < a+b && b+c < a+c) cout<< b+c << "\n";
  else if(a+c < a+b && a+c < b+c) cout<< a+c << "\n";
}

Measured memory_bytes: 3592
/*
好题
从(1,1)出发向右走m步，路径纵向宽度<=n，方案数
考虑累加答案-->朴素DP，O(n^3)
先考虑所有方案（枚举所有纵向宽度为n的框子）
一条路径被多个框算到？
额外加一个限制（路径必须碰到框子下边界）来去重！-->O(n^2)
*/
#include<cstdio>
#include<cstring>
#include<algorithm>
#define N 3010
#define mod 1000000007
#define ll long long
using namespace std;
int n, m, f[N][N][2], ans;
int main(){
	scanf("%d%d", &n, &m); m--;
	memset(f, 0, sizeof(f));
	for(int i=2; i<=n; i++)f[0][i][0]=1; f[0][1][1]=1;
	for(int i=0; i<=m-1; i++){
		for(int j=1; j<=n; j++){
			if(j<n)f[i+1][j+1][0]=(f[i+1][j+1][0]+f[i][j][0])%mod;
			f[i+1][j][0]=(f[i+1][j][0]+f[i][j][0]*2%mod)%mod;
			if(j>2)f[i+1][j-1][0]=(f[i+1][j-1][0]+f[i][j][0])%mod;
			if(j==2)f[i+1][j-1][1]=(f[i+1][j-1][1]+f[i][j][0])%mod;
			if(j<n)f[i+1][j+1][1]=(f[i+1][j+1][1]+f[i][j][1])%mod;
			f[i+1][j][1]=(f[i+1][j][1]+f[i][j][1]*2%mod)%mod;
			if(j>1)f[i+1][j-1][1]=(f[i+1][j-1][1]+f[i][j][1])%mod;
		}
	}
	ans=0; for(int i=1; i<=n; i++)ans=(ans+f[m][i][1])%mod; ans=(ll)ans*4%mod;
	printf("%d", ans);
	return 0;
}

Measured memory_bytes: 70912
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int D,N; 
    cin >> D >> N;
    int i = 0;
    while(N > 0){
        i++;
        if(D == 0 && i % 100 != 0){
            N--;
        }
        if(D == 1 && i % 100 == 0 && i % 10000 != 0 && i % 1000000 != 0){
            N--;
        }
        if(D == 2 && i % 10000 == 0 && i % 1000000 != 0){
            N--;
        }
    }
    cout << i << endl;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000009LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define fo(i,j,n) for (int i=(j); i < (n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main() {
    int x; cin >> x;
    vector<int> list{1};
    for(int i=2; i<=x; i++){
        int num = i;
        while(num <= x){
            num *= i;
            list.push_back(num);
        }
    }
    sort(all(list));
    auto iter = upper_bound(all(list), x);
    int res = *(--iter);
    cout << res << ln;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;//×Ô¶¯È¡Ä£2^64 
const double pi=acos(-1.0);
const int mod = 998244353; // 998244353;
const int inf = 0x7fffffff;//2^31-1	
const ll INF = 0x7fffffffffffffff;
const int dx[]={-1,0,1,0},dy[]={0,1,0,-1};
//double begin_time=clock();    double end_time=clock();printf("time= %f ms\n",end_time-begin_time);
//bool operator < (const mmp &a) const{return x<a.x||x==a.x&&y<a.y;}       //map<int,map<int,int> >z;
//map<int,int>::iterator it;for(it=z.begin();it!=z.end();it++)printf("%d %d\n",it->first,it->second);
//ll poww(ll a,ll b){ll s=1;while(b){if(b&1)s=(s*a)%mod;a=(a*a)%mod;b>>=1;}return s%mod;}  //¿ìËÙÃÝÈ¡Ä£ 
//lower_bound(begin,end,num); µÚÒ»¸ö>=numµÄÊý×Ö upper_bound(begin,end,num); µÚÒ»¸ö>numµÄÊý×Ö,·µ»ØµØÖ·
//freopen("input.in","r",stdin);     freopen("output.out","w",stdout);      //ÎÄ¼þ¶ÁÐ´Ìá½» 
//reverse(s.begin(),s.end());   //·­×ª×Ö·û´® ||        floor(); ÏòÏÂÈ¡Õû  ceil(); ÏòÉÏÈ¡Õû
//ÊýÖáÉÏµÄn¸öµãÒÆ¶¯µ½Í¬Ò»Î»ÖÃ£¬ÒÆ¶¯µ½¸Ã×éÊý×ÖµÄÖÐÎ»ÊýµÄ×Ü¾àÀë×î¶Ì
//bool isPrime(int n){if(n==2||n==3)return 1;if(n%6!=1&&n%6!=5)return 0;
//int t=sqrt(n);for(int i=5;i<=t;i+=6)if(n%i==0||n%(i+2)==0)return 0;return 1;}//ÅÐ¶ÏËØÊý   


int main()
{
	ios::sync_with_stdio(false);cin.tie(0);
	ll a,b,c,d,e,f,T;
//	cin>>T;
//	while(T--)
	{
		string q;
		cin>>q;
		for(int i=0;i<q.size();i++)if(q[i]=='?')q[i]='D';
		cout<<q<<endl;
		
	}
 
 
 
}




Measured memory_bytes: 3784
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

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

	std::vector<int> p(5);
	std::cin >> p[0] >> p[1] >> p[2] >> p[3] >> p[4];

	std::sort(p.begin(), p.end(),
		[](int x, int y) {
			if (x <= 10) return false;
			if (y <= 10) return true;
			if (0 == x % 10) return false;
			if (0 == y % 10) return true;
			return ((x%10) < (y%10));
		}
	);

	int t = 0;
	for (int i = 4; 1 <= i; --i) {
		if (p[i] <= 10) {
			t += 10;
		} else if (p[i]%10) {
			t += p[i] + (10 - p[i]%10);
		} else {
			t += p[i];
		}
	}
	t += p[0];

	std::cout << t;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2005;
int read(){
	int f=1,g=0;
	char ch=getchar();
	for (;!isdigit(ch);ch=getchar()) if (ch=='-') f=-1;
	for (;isdigit(ch);ch=getchar()) g=g*10+ch-'0';
	return f*g;
}
int n,m,ans,cnt,b[N],fa[N],depth[N],c[N],h[N*3],fr[N*3];
struct node{int u,v;}a[N*3];
vector<int> e[N];
unordered_set<int> g[N];
void work(int x,int fath){
	fa[x]=fath;depth[x]=depth[fath]+1;
	for (auto y : e[x])
	if (y!=fath) work(y,x);
	b[++cnt]=x;
}
void add(int u,int v){
	a[++cnt]=(node){u,v};
	if (u==v) return;
	g[u].insert(cnt);g[v].insert(cnt);
}
void calc(int x,int i,int j){
	int u=a[i].u+a[i].v-x,v=a[j].u+a[j].v-x;
	g[u].erase(i);g[v].erase(j);
	add(u,v);
	fr[i]=fr[j]=cnt;
	h[i]=(a[i].v==u);h[j]=(a[j].u==v);
}
void chk(int x,int y){
	while (x!=y){
		if (depth[x]<depth[y]) swap(x,y);
		c[x]++;x=fa[x];
	}
}
int main(){
	n=read();m=read();
	for (int i=1;i<n;i++){
		int u=read(),v=read();
		e[u].push_back(v);
		e[v].push_back(u);
	}
	work(1,0);cnt=0;
	for (int i=1;i<=m;i++){
		int u=read(),v=read();
		add(u,v);chk(u,v);
	}
	for (int i=1;i<=n;i++){
		int x=b[i],las=0;
		for (auto now : g[x])
		if (!las) las=now;
		else {calc(x,las,now);las=0;}
		if (las){
			int y=a[las].u+a[las].v-x;
			g[y].erase(las);
			add(fa[x],y);
			fr[las]=cnt;h[las]=(a[las].v==x);
		}
	}
	for (int i=2;i<=n;i++) ans+=min(c[i],2);
	printf("%d\n",ans);
	for(int i=cnt;i;i--) h[i]^=h[fr[i]];
	for (int i=1;i<=m;i++)
	if (!h[i]) printf("%d %d\n",a[i].u,a[i].v);
	else printf("%d %d\n",a[i].v,a[i].u);
	return 0;
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int) n; i++)
#define repb(i, n) for (int i = (int) n; i >= 0; i--)
#define reps(i, m, n) for (int i = (int) m; i < (int) n; i++)
#define repsb(i, m, n) for (int i = (int) m; i >= (int) n; i--)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
# define pb(a) push_back(a)
#define ll long long int
const ll LLINF = 1e18 + 10;
int dy[] = { 0, 0, 1, -1, 0 };
int dx[] = { 1, -1, 0, 0, 0 };
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; }
//vector<vector<int>> vec(n_rows, vector<int>(n_cols, value));
using namespace std;
int main(int argc, char const * argv[]){
    int n, k;
    cin >> n >> k;
    vector<int> v(n,-1);   
    rep(i,n) cin>>v[i];
    int ans = 0;
    rep(i, n) ans += 2 * min(v[i], abs(v[i] - k));
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int A;
  cin >> A;
 
  if (A == 1 || A == 2 || A == 3 || A == 5 || A == 7 || A == 11 || A == 13 || A == 15 || A == 17 || A == 19 || A == 23 || A == 29 || A == 31){
    cout << 1 << endl;
  } 

  if (A == 4 || A == 6 || A == 9 || A == 10 || A == 14 || A == 21 || A == 22 || A == 25 || A == 26){
    cout << 2 << endl;
  }

  if (A == 8 || A == 12 || A == 18 || A == 20 || A == 27){
    cout << 5 << endl;
  }

  if (A == 16){
    cout << 14 << endl;
  }

  if (A == 24){
    cout << 15 << endl;
  }

  if (A == 28 || A == 30){
    cout << 4 << endl;
  }

  if (A == 32){
    cout << 51 << endl;
  }

}

Measured memory_bytes: 256
import java.math.BigDecimal;
import java.util.Scanner;

public class Main {
	private Scanner sc;
	
	public static void main(String[] args) {
		new Main();
	}
	
	public Main() {
		sc = new Scanner(System.in);
		
		while (sc.hasNextLine()) {
			String[] nico = sc.nextLine().split(" ");

			int[] cards = new int[10];
			for (int i = 0; i < cards.length; i++) {
				cards[i] = 1;
			}
			int c0 = Integer.parseInt(nico[0]);
			int c1 = Integer.parseInt(nico[1]);
			int c2 = Integer.parseInt(nico[2]);

			cards[c0 - 1] = 0;
			cards[c1 - 1] = 0;
			cards[c2 - 1] = 0;
			
			int rest = 20 - c0 - c1;
			
			int p = 0;
			for (int i = 0; i < cards.length; i++) {
				if ((cards[i] == 1) && ((i + 1) > rest)) p++;
			}
			
			if ((p / 7.0) * ((p - 1) / 6.0) + ((7 - p) / 7.0) * (p / 6.0) > 0.5) System.out.println("NO");
			else System.out.println("YES");
		}
	}
}

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

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    int a[n][m];

    for(int i = 0 ; i < n; i ++){
        for(int j = 0; j < m; j++){
            cin >> a[i][j];
        }
    }

    vector<int> b(m);
    for(int i = 0; i < m; i++)
        cin >> b[i];
    vector<int> ans(n);
    for(int i = 0 ; i < n;i++){
        int sum = 0;
        for(int j = 0 ; j < m;j++){
            sum += a[i][j] * b[j];
        }
        ans[i] = sum;
    }
    for(int i = 0 ; i < n; i++)
        cout << ans[i] << endl;
    return 0;
}



Measured memory_bytes: 3228