akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define fi first
#define se second

const int N = 200200;
const long long mod = 1e9 + 7;

using namespace std;

int n;
int a[N];
int b[N];
long long d[N];

void upd(int x, long long y)
{
        while(x < N){
                d[x] = max(d[x], y);
                x += x & -x;
        }
}

long long get(int x)
{
        long long res = 0;
        while(x > 0){
                res = max(res, d[x]);
                x -= x & -x;
        }
        return res;
}

int main()
{
        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
        ios_base::sync_with_stdio(0);

        cin >> n;
        for(int i = 1; i <= n; i++){
                cin >> a[i];
        }
        for(int i = 1; i <= n; i++){
                cin >> b[i];
        }
        long long res = 0;
        for(int i = 1; i <= n; i++){
                long long now = get(a[i]) + b[i];
                res = max(res, now);
                upd(a[i], now);
        }
        cout << res << "\n";
}



Measured memory_bytes: 3456
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <deque>
using namespace std;

using VI = vector <int> ;
using VVI = vector <VI> ;
const int MAXS = 100010;
char str[MAXS];

int main() {
    int r = 0; // reverse
    deque <char> strQue;

    scanf("%s", str);
    for (int i = 0; str[i]; ++i) {
        strQue.push_back(str[i]);
    }

    int Q;
    scanf("%d", &Q);

    while (Q--) {
        int T;
        scanf("%d", &T);

        if (T == 1) {
            r ^=  1;
        } else {
            int F;
            char ch;
            scanf("%d %c", &F, &ch);
            --F;

            F ^= r;

            if (F == 0) {
                strQue.push_front(ch);
            } else {
                strQue.push_back(ch);
            }
        }
    }

    if (r) {
        reverse(strQue.begin(), strQue.end());
    }

    for (int i = 0; i < strQue.size(); ++i) {
        printf("%c", strQue[i]);
    }

    printf("\n");

    return 0;
}

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

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const long long INF = 10010010010010;
const long long MOD = 1000000007;
typedef pair<int,int> P;

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

    return res %= MOD;
}

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

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

    int N,K;cin >> N >> K;
    vector<long long> retu(N);
    for(int i = 0;i<N;i++) cin >> retu.at(i);
    vector<long long> rui(N+1);
    rui.at(0) = 0;
    for(int i = 0;i<N;i++){
        if(i == 0){
            rui.at(i+1) = rui.at(i)+abs(retu.at(i));
            continue;
        }
        rui.at(i+1) = rui.at(i)+abs(retu.at(i)-retu.at(i-1));
    }
    long long ans = 1145141919810;
    //for(long long V : rui) cout << V << endl;
    for(int i = 0;i<N-K+1;i++){
        long long kizyun = rui.at(i+K)-rui.at(i+1);
        //cout << kizyun << " ";
        if(retu.at(i+K-1) >= 0 && retu.at(i) < 0){
            kizyun += min(abs(retu.at(i)),abs(retu.at(i+K-1)));
        }
        else if(retu.at(i+K-1) >= 0 && retu.at(i) >= 0){
            kizyun = retu.at(i+K-1);
        }
        else if(retu.at(i+K-1) < 0 && retu.at(i) < 0){
            kizyun = retu.at(i)*-1;
        }
        //cout << kizyun << endl;
        ans = min(ans,kizyun);
        
    }
    cout << ans << endl;
}


Measured memory_bytes: 4760
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int INT_INF = 1 << 30;
#define MOD 1000000007LL
#define endl "\n"

ll ncr(ll n, ll r){
  if(n < r) return 0;
  if(r > n-r) r = n-r;

  ll a = 1, b = 1;
  for(int i = 0; i < r; i++){
    a *= (n - i);
  }
  for(int i = 0; i < r; i++){
    b *= (i + 1);
  }
  return a/b;
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll N, P;
  cin >> N >> P;
  string S;
  cin >> S;
  ll ans = 0;
  if(P == 2){
    for(int i = 0; i < N; i++){
      if((S.at(i) - '0') % 2 == 0) ans += i+1;
    }
  }
  else if(P == 5){
    for(int i = 0; i < N; i++){
      if((S.at(i) - '0') % 10 == 0 || (S.at(i) - '0') % 10 == 5) ans += i+1;
    }
  }
  else{
    vll dp(N+1, INF); //右からN桁をPで割った余り
    vll m(P, 0);
    ll initial = S.at(N-1) - '0';
    dp.at(1) = initial % P;
    m.at(0)++;
    m.at(dp.at(1))++;
    ll keta = 10LL;
    for(int i = 2; i <= N; i++){
      ll num = S.at(N-i) - '0';
      dp.at(i) = (keta * num % P + dp.at(i-1)) % P;
      m.at(dp.at(i))++;
      keta *= 10;
      keta %= P;
    }
    for(int i = 0; i < P; i++){
      ans += ncr(m.at(i), 2);
    }
  }
  cout << ans << endl;
}

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

int main() {
    int n;
    string s;
    cin >> n >> s;
    int rgb[n][3] = {};
    //個数をカウント
    for(int i = 0; i < n; i++){
        if(s[i] == 'R'){
            rgb[i][0]++;
        }else if(s[i] == 'G'){
            rgb[i][1]++;
        }else{
            rgb[i][2]++;
        }
    }
    //i個時点での総数を計算する
    for(int i = 1; i < n; i++){
        rgb[i][0] += rgb[i-1][0];
        rgb[i][1] += rgb[i-1][1];
        rgb[i][2] += rgb[i-1][2];
    }
    long long cnt = 0;
    for(int i = 0; i < n; i++){
        char x = s[i];
        for(int j = i+1; j < n; j++){
            char y = s[j];
            if(s[i] == 'R' && s[j] == 'B'){
                cnt += rgb[n-1][1] - rgb[j][1];
                if(s[2*j-i] == 'G'){
                    cnt--;
                }
            }else if(s[i] == 'R' && s[j] == 'G'){
                cnt += rgb[n-1][2] - rgb[j][2];
                if(s[2*j-i] == 'B'){
                    cnt--;
                }
            }else if(s[i] == 'B' && s[j] == 'R'){
                cnt += rgb[n-1][1] - rgb[j][1];
                if(s[2*j-i] == 'G'){
                    cnt--;
                }
            }else if(s[i] == 'B' && s[j] == 'G'){
                cnt += rgb[n-1][0] - rgb[j][0];
                if(s[2*j-i] == 'R'){
                    cnt--;
                }
            }else if(s[i] == 'G' && s[j] == 'B'){
                cnt += rgb[n-1][0] - rgb[j][0];
                if(s[2*j-i] == 'R'){
                    cnt--;
                }
            }else if(s[i] == 'G' && s[j] == 'R'){
                cnt += rgb[n-1][2] - rgb[j][2];
                if(s[2*j-i] == 'B'){
                    cnt--;
                }
            }   
        } 
    }
    cout << cnt << endl;
    //cout << rgb[n-1][0] << " " << rgb[n-1][1] << " " << rgb[n-1][2] << endl;

    return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
#include <math.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1001001001;
const int mINF = -1001001001;


int main() {
char s[11];
cin >> s;
int num=strlen(s);
int a[num]={0};
REP(i,num) {
  if(s[i]=='A'||s[i]=='G'||s[i]=='C'||s[i]=='T') a[i]=1;
}
int ans=0;
int temp=0;
REP(i,num) {
  if(a[i]==1) {
    temp++;
  } else if(a[i]==0) {
    temp=0;
  }
  ans = max(ans,temp);
}
cout << ans << endl;
return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String args[]) {
		Scanner in = new Scanner(System.in);
		while (true) {
			int n = in.nextInt();
			if(n == 0) break;
			int sum = 0;
			for(int i = 5; i <= n; i *= 5) 
				sum+=n/i;
			System.out.println(sum);
		}
	}
}

Measured memory_bytes: 17172
//ALDS1_4A
#include <stdio.h>

int search(int A[],int n,int key){
 int i=0;
 A[n]=key;
 while(A[i]!=key) i++;
 return i!=n;
}

int main(){
 int i,n,A[10001],q,key,sum=0;
 scanf("%d",&n);
 for(i=0;i<n;i++) scanf("%d",&A[i]);
 scanf("%d",&q);
 for(i=0;i<q;i++){
  scanf("%d",&key);
  if(search(A,n,key)) sum++;
 }
 printf("%d\n",sum);
 return 0;
}

Measured memory_bytes: 1068
n=int(input())
a=list(map(int,input().split()))
i=0
ans=[]
s=0
for i in range(n):
    while a[i]%2==0:
        a[i]=a[i]//2
        s+=1
    i+=1
    ans.append(s)
    s=0
print(sum(ans))

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

int main() {
  int N;
  cin >> N;
  bool flg=false;
  for(int i=0;i<N;i++){
    string s;
    cin >> s;
    if(s=="Y"){
      flg=true;
    }
  }
  if(flg){
    cout << "Four" << endl;
  }else{
    cout << "Three" << endl;
  }
}

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

#define ll long long 
#define pb push_back
#define mem0(a) memset(a,0,sizeof(a))
#define mem1(a) memset(a,-1,sizeof(a))
#define memf(a) memset(a,false,sizeof(a))
#define all(v) v.begin(),v.end()
#define sz(a) (ll)a.size()
#define F first
#define S second
#define INF 2000000000000000000
#define endl "\n"
#define _time_ 1.0 * clock() / CLOCKS_PER_SEC
#define popcount(x) __builtin_popcountll(x)
#define pll pair<ll,ll> 
#define ld long double

const int M=1000000007;
const int MM=998244353;
const long double PI = acos(-1);

ll power(ll b,ll e,ll m)
{
    if(e==0) return 1;
    if(e&1) return b*power(b*b%m,e/2,m)%m;
    return power(b*b%m,e/2,m);
}
ll power( ll b, ll e)
{
    if(e==0) return 1;
    if(e&1) return b*power(b*b,e/2);
    return power(b*b,e/2);
}
template<typename T, typename U> static inline void amin(T &x, U y){ if(y<x) x=y; }
template<typename T, typename U> static inline void amax(T &x, U y){ if(x<y) x=y; }
template<typename T, typename U> ostream& operator<<(ostream &os, const pair<T, U> &p)
{ 
    return os<<'('<<p.F<< ","<<p.S<<')'; 
}

const int N = 5003;
int n,m;
ll a[N][202];
ll logn[N];
ll dp[N][15][202];
ll A[N];
ll ans[N];

ll query(int l,int r,int x)
{
    int y = logn[r-l+1];
    return max(dp[l][y][x],dp[r+1-(1<<y)][y][x]);
}

void go_(int l,int r,int optl,int optr)
{
    if(l>r)
        return ;
    int mid = (l+r)/2;
    pll p = {-INF,-INF};
    for(int i=optl;i<=min(mid,optr);++i)
    {
        ll u = 0;
        for(int j=1;j<=m;++j)
            u += query(i,mid,j);
        amax(p,make_pair(u-A[mid]+A[i],(ll)-i));
    }
    // cout<<mid<<" ";
    // cout<<p<<"\n";
    ans[mid] = p.F;
    go_(l,mid-1,optl,-p.S);
    go_(mid+1,r,-p.S,optr);
}

int _runtimeTerror_()
{
    cin>>n>>m;
    for(int i=2;i<=n;++i)
        cin>>A[i];
    for(int i=2;i<=n;++i)
        A[i]+=A[i-1];

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

    for(int j=1;j<=m;++j)
    {
        for(int len=0;len<=13;++len)
        {
            for(int i=1;i<=n;++i)
            {
                logn[i]=log2(i);
                if(i+(1<<len)>n+1)
                    continue;
                if(len==0)
                    dp[i][len][j] = a[i][j];
                else
                    dp[i][len][j] = max(dp[i][len-1][j],dp[i+(1<<(len-1))][len-1][j]);
            }
        }
    }
    go_(1,n,1,n);
    ll answer = -INF;
    for(int i=1;i<=n;++i)
        amax(answer,ans[i]);
    cout<<answer<<"\n";
    return 0;
}

int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    #ifdef runSieve
        sieve();
    #endif
    #ifdef NCR
        initialize();
    #endif
    int TESTS=1;
    //cin>>TESTS;
    while(TESTS--)
        _runtimeTerror_();
    return 0;
}

Measured memory_bytes: 120640
#include <iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
#include<cmath>
#include<queue>
#include<string>
#include<set>
#include<map>
#include<bitset>
#include<stack>
#define UP(i,l,h) for(int i=l;i<h;i++)
#define DOWN(i,h,l) for(int i=h-1;i>=l;i--)
#define W(a) while(a)
#define MEM(a,b) memset(a,b,sizeof(a))
#define INF 0x3f3f3f3f3f3f3f3f
#define LL long long
#define MAXN 100010
#define SIZE 95
#define EPS 1e-10
#define MOD 1000000007

using namespace std;
int mp[110][110];
int draw[10010];

int main() {
    int n,h,w;
    int now=0;
    scanf("%d%d%d",&h,&w,&n);
    UP(i,1,n+1) {
        int x;
        scanf("%d",&x);
        W(x--) {
            draw[now++]=i;
        }
    }
    now=0;
    UP(i,0,h) {
        if(i%2==0) {
            UP(j,0,w) {
                mp[i][j]=draw[now++];
            }
        } else {
            DOWN(j,w,0) {
                mp[i][j]=draw[now++];
            }
        }
    }
    UP(i,0,h) {
        UP(j,0,w){
            if(j!=(w-1))
                printf("%d ",mp[i][j]);
            else
                printf("%d\n",mp[i][j]);
        }
    }
}


Measured memory_bytes: 384
n = gets.chomp.to_i
d = 0
a = []
list = []
n.times do |i|
  a[i] = gets.chomp.split(" ")
  a[i][1] = a[i][1].to_i
  if(a[i][0] == "insert")
    list.unshift(a[i][1])
    
  elsif(a[i][0] == "delete")
    list.delete_at(d) if ((d = (list.index(a[i][1]))) != nil)
  elsif(a[i][0] == "deleteFirst")
    list.shift
  elsif(a[i][0] == "deleteLast")
    list.pop
  else
    error += 1
  end
end
list[0,list.size-1].each do |d|
  print("#{d} ")
end
puts list[-1]

Measured memory_bytes: 272788
from itertools import combinations as comb
import math
n, d = map(int, input().split())
zahyo_list = []
for l in range(n):
    zahyo = list(map(int, input().split()))
    zahyo_list.append(zahyo)

comb_list = list(comb(zahyo_list, 2))

count = 0
for p in comb_list:
    y_zahyo = p[0]
    z_zahyo = p[1]
    hs = 0
    for q in range(d):
        hs += abs(y_zahyo[q]-z_zahyo[q])**2

    if math.sqrt(hs).is_integer():
        count += 1
print(count)

Measured memory_bytes: 3064
N = int(input())
H = list(map(int, input().split()))

ans = 0
temp = 0
for i in range(N-1):
    if H[i] >= H[i+1]:
        temp += 1
    else:
        ans = max(ans, temp)
        temp = 0

ans = max(ans, temp)
print(ans)


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

int main(){
  int N,K;cin>>N>>K;
  vector<int>L(N);
  for (int i=0;i<N;++i){
    cin>>L[i];
  }
  sort(L.begin(),L.end());
  reverse(L.begin(),L.end());
  int ans =0;
  for (int i=0;i<K;++i){
    ans+=L[i];
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
import java.util.*;
class Main{
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		Main app = new Main();
		while(sc.hasNext()){
		System.out.println(app.length(sc.nextInt(),sc.nextInt()));
		}
	}
	
	
	
	int length(int a,int b){
		int ans = 1;
		a += b;
		while(a  >=  10){
				ans ++;
				a /=10;
		}
		return ans;
	}
	
	
	
	
	
	
}

Measured memory_bytes: 26320
#include <iostream>
using namespace std;

int main() {
	int N, M, K;
	bool check = false;
	cin >> N >> M >> K;
	for (int i = 0; i <= N; i++) {
		for (int j = 0; j <= M; j++) {
			if (i * (M - j) + (N - i) * j == K) check = true;
		}
	}
	if (check) puts("Yes");
	else puts("No");
}

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

int move(ll i, ll j,ll i_, ll j_,ll H,ll W, vector<vector<char>>& A){
    // cout << i << " " << j << " " << A[i][j] << endl;
    ll r=0;
    if(i_>0){ //down
        i+=i_;
        if(A[i][j-1]=='#') return 1;
    }else{  //right
        j+=j_;
        if(A[i-1][j]=='#') return 1;
    }
    // cout <<"move" <<  i << " " << j << " " << A[i][j] << endl;
    if(A[i][j]=='.') return 0;
    if(i==H && j==W) return 0;
    if(i==H){ //right
        return move(i, j, 0, 1, H, W, A);
    }else if(j==W){ //down
        return move(i, j, 1, 0, H ,W, A);
    }else{
        // cout << "DR" << endl;
        return max(move(i, j, 0, 1, H, W, A), move(i, j, 1, 0, H, W, A));
    }
}

int main(){
    ll H,W;
    cin>>H>>W;
    vector<vector<char>> A;

    vector<char> t;
    rep(j,W+2) t.push_back('.');
    A.push_back(t);

    rep(i,H){
        t.clear();
        t.push_back('.');
        char a;
        rep(j,W){
            cin >> a;
            t.push_back(a);
        }
        t.push_back('.');
        A.push_back(t);
    }
    t.clear();
    rep(j,W+2) t.push_back('.');
    ll r = max(move(1, 1, 0, 1, H, W, A), move(1, 1, 1, 0, H, W, A));

    if(r>0) cout << "Impossible" << endl;
    else cout << "Possible" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define all(v) v.begin(), v.end()
#define sz size()
#define mp make_pair
#define pb push_back
#define rep(p, a, b) for (ll p = a; p < b; p++)
#define rap(p, a, b) for (ll p = a; p <= b; p++)
#define per(p, a, b) for (ll p = a; p >= b; p--)
#define F first
#define S second
using namespace std;

typedef vector<ll> vll;
typedef vector<ld> vld;
typedef pair<ll, ll> pll;

int main()
{
    ll t, i, j, k, ans, n;

    //cin>>t;
    t = 1;
    while (t--)
    {
        ll f=1;
        cin>>n;
        vll v(n);
        rep(p,0,n)
        {
            cin>>v[p];
            if(v[p]%2==0)
            {
                if(!(v[p]%3==0 || v[p]%5==0))f=0;
            }
        }

        if(f)cout<<"APPROVED";
        else cout<<"DENIED";
    }

    return 0;
}

Measured memory_bytes: 3592
#include <iostream>
using namespace std;
/*
 a=>2*b
 */
int main(){
    int n;
    int d[50];
    int a = 0;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> d[i];
    }
    
    for (int i = 0; i < n; i++){
        for (int j= i+1; j<n; j++) {
            a += d[i] * d[j];
        }
    }
    cout << a << endl;
    
    return 0;
}

Measured memory_bytes: 256
//c++ テンプレ
#include<bits/stdc++.h>
using namespace std;

typedef long long llint;
typedef long double ld;

#define inf 1e18
#define mod 1000000007
priority_queue<llint,vector<llint>,greater<llint> > que;
priority_queue<llint> Que;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

vector<llint>a;
vector<llint>b;
int n,m;
llint k;
void solve(){
    cin >> n >> m >> k;
    a.resize(n);
    b.resize(m);
    for(int i=0;i<n;i++)cin >> a[i];
    for(int i=0;i<m;i++)cin >> b[i];
    vector<llint>asum(n+1,0);
    vector<llint>bsum(m+1,0);
    for(int i=1;i<=n;i++)asum[i]=asum[i-1]+a[i-1];
    for(int i=1;i<=m;i++)bsum[i]=bsum[i-1]+b[i-1];
    //2分探索
    int ans=0;
    for(int i=0;i<=n;i++){
        if(asum[i]>k)break;
        int j=upper_bound(bsum.begin(),bsum.end(),k-asum[i])-bsum.begin();
        ans=max(ans,i+j-1);
    }
    cout << ans <<  endl;
}

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




Measured memory_bytes: 9504
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ll long long int
#define int ll
//#define slld(t) scanf("%lld",&t)
// #define sd(t) scanf("%d",&t)
// #define pd(t) printf("%d\n",t)
//#define plld(t) printf("%lld\n",t)
#define vec vector < int >
#define vecp vector < pair < int , int > >
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define debug(x)   cerr<<#x<<": "<<x<<endl
#define pii pair < int , int >
#define pll pair < ll , ll > 
#define pdd pair<double , double>
#define debug(x)   cerr<<#x<<": "<<x<<endl
#define mod  1000000007
#define N    200005
#define mod1 1000000007
#define mod2 998244353
#define bitcnt __builtin_popcountll
#define PI acos(-1)
#define s3   1.73205080757          // square root 3
const  int inf = (int)1e18+10 ;
const int MAX= 100;

 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
ordered_set S;

int powmod(int x , int y){
	int res = 1;
	while(y > 0){
		if(y%2==1)
			res = (res*x)%mod;
		x = (x*x)%mod;
		y/=2;
	}
	return res;
}
int mul(int x , int y){
	return (x*y)%mod;
}
int a[200005];
signed main(){
  fast;
  
  int n;
  cin >> n;
  int ans = 0;
  for(int i = 0 ;i < n ; i++){
  	cin >> a[i];
  	if(a[i]  == ans + 1) ans++;
  }
  if(ans > 0)
  cout << (n - ans) << endl;
  else
  	cout << -1 << endl;

 }

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define all(v) v.begin(),v.end()
#define repf(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>=b;i--)
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007
#define MOD 998244353 

using namespace std;
using namespace __gnu_pbds;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

ordered_set<ll> ors;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
ld PI=3.14159265359;

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

ll invmod(ll a, ll m)
{
    return power(a,m-2,m);
}

ll lp[100001];
vector<ll> pr;

void prime()
{
    repf(i,1,100001) lp[i]=i;
    repf(i,2,100001)
    {
        if(lp[i]==i)
        {
            for(ll j=2*i;j<100001;j+=i)
            {
                if(lp[j]==j) lp[j]=i;
            }
        }
    }
    repf(i,2,100001) if(lp[i]==i) pr.pb(i);
}


void solve(ll tt) {
    ll n;
    cin>>n;
    ll val=power(10,n,mod);
    val=(val+power(8,n,mod))%mod;
    val=(val-(2*power(9,n,mod))%mod+mod)%mod;
    cout<<val<<endl;
} 


int main()
{
    IOS;
    prime();
    ll t=1;
    // cin>>t;
    repf(tt,1,t+1) {
        solve(tt);
    }
}     

Measured memory_bytes: 4564
#include <iostream>
using namespace std;

#define ABS(X) ((X)>0?(X):-(X))

int main(void){
  long long a,b,c,k;
  
  cin >> a >> b >> c >> k;
  if (ABS(a-b)>=1000000000000000000ll){
    cout << "Unfair" << endl;
  } else {
    cout << (k%2==0?(a-b):(b-a)) << endl;
  }
  return 0;
}
  

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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//==================================

int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif

    ll N, X;
    cin >> N >> X;

    Vl A(N);
    for (int i = 0; i < N; i++) {
        int a;
        cin >> a;
        A[i] = abs(a - X);
    }

    ll ans = A[0];
    for (int i = 0; i < N; i++) {
        ans = __gcd(ans, A[i]);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>

using namespace std;

int main() {

    int n;
    cin >> n;
    vector<int> a(3, 0);
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        if (x % 4 == 0)
            a[2]++;
        else
            if (x % 2 == 0)
                a[1]++;
            else
                a[0]++;
    }

    if (a[0] > a[2] + 1) {
        printf("No\n");
        return 0;
    }
    if (a[0] > a[2] && a[1] > 0) {
        printf("No\n");
        return 0;
    }
    printf("Yes\n");

	return 0;
}


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

int main() {
	char S[100000];
	int S_len;

	scanf("%s", S);

	S_len = strlen(S);


	int i, flag;
	char c, Not_Found;

	for(c=97; c<=122; c++){
		flag = 0;
		for(i=0; i<=S_len; i++) {
			if(S[i] == c)
				flag = 1;
		}
		if (flag == 0) {
			Not_Found = c;
			break;
		}
	}

	if(flag == 0)
		printf("%c\n", Not_Found);
	else
		printf("None\n");
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <stack>
#include <stdlib.h>

using namespace std;

int miw,maw,mih,mah;

void create_map(int n, vector<pair<int,int> > &nd, vector<pair<int,int> > &place, int **array) {
  
  for(int i = 0; i < n-1; i++) {
    //cout << i << endl;
    pair<int,int> p = nd[i];
    pair<int,int> adj  = place[p.first];

    pair<int,int> np = (make_pair(adj.first, adj.second));

    //cout << "current::" << adj.first << " " << adj.second << endl;
    
    if(p.second == 0)
      np.second -= 1;
    else if(p.second == 1)
      np.first  += 1;
    else if(p.second == 2)
      np.second += 1;
    else if(p.second == 3)
      np.first  -= 1;

    if(miw > np.second)
      miw = np.second;
    else if(maw < np.second)
      maw = np.second;
    else if(mih > np.first)
      mih = np.first;
    else if(mah < np.first)
      mah = np.first;
    //cout << "next::" << np.first << " " << np.second << endl;
    array[np.first][np.second] = i+1;
    place.push_back(np);
    
  }


}



int main(int argc, char *argv[]){


  while(true) {
  int n;
  cin >> n;
  if(n == 0)
    break;
  if(n != 1) {
  vector<pair<int,int> > nd;
  vector<pair<int,int> > place;

  for(int i = 0; i < n-1; i++) {
    int e, d;
    cin >> e;
    cin >> d;
    nd.push_back(make_pair(e,d));
  }

  miw = maw = mih = mah = n;
  int tmp = n*2;
  int **array;
  array = (int **)malloc(sizeof(int *)*tmp);
  for(int i = 0; i < tmp; i++)
    array[i] = (int *)malloc(sizeof(int)*tmp);

  for(int i = 0; i < tmp; i++)
    for(int j = 0; j < tmp; j++)
      array[i][j]  = -1;
  
  
  array[n][n] = 0;
  place.push_back(make_pair(n,n));

  create_map(n, nd, place, array);

  /*
  for(int i = 0; i < tmp; i++) {
    for(int j = 0; j < tmp; j++){
      if(array[i][j] >= 0)
	cout << array[i][j] << " ";
      else
	cout << "  ";
    }
    cout << endl;
    }
  */
  /*
  int max_h, max_w;
  int up, bottom, width, count;
  bool flag = false;
  max_h = max_w = width = count = 0;
  
  for(int i = 0; i < tmp; i++) {
    for(int j = 0; j < tmp; j++){
      if(array[i][j] >= 0) {
	if(count == 0)
	  up = i;
	width++;
	count++;
      }
      
      if(count == n) {
	bottom = i;
	count++;
      }
      
      if(count == 1)
	flag = true;
      if(flag) {
	up = i;
	flag = false;
	} 
    }
    if(max_w < width)
      max_w = width;
    width = 0;
  }

  //cout << bottom << " " << up << endl;
  max_h = bottom - up + 1;
  */
  cout << maw - miw + 1<< " " << mah - mih + 1<< endl;
  
  for(int i = 0; i < tmp; i++)
    free(array[i]);
  free(array);
  }
  else
    cout << 1 << " " << 1 << endl;
  }
  return 0;
}

Measured memory_bytes: 3280
import           Control.Monad
import qualified Data.ByteString.Char8 as BS
import           Data.List
import           Data.Maybe
import           Debug.Trace

readInt = fst . fromJust . BS.readInt
getInt = readInt <$> BS.getLine

isPrime x | x < 2 = False
          | x == 2 = True
          | otherwise = let sx = ceiling $ sqrt $ fromIntegral x
                        in and [x `mod` i /= 0 | i <- [2..sx]]

solve n | isPrime n = n
        | otherwise = solve (n+1)

main = do
  x <- getInt
  let ans = solve x
  print ans

Measured memory_bytes: 508
#include <algorithm>
#include<string>
#include<iomanip>
#include<iostream>
#include<math.h>
#include<vector>
using namespace std;
#define NUM 100001
typedef long long ll;

int main() {
	long N, M;

	cin >> N>>M;

	cout << (N * 3 + M) / 2 << endl;

	return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
@author: H_Hoshigi
"""
def f(N, k):
    return  -(k*(k+1)*(2*k+1))//6 + (N+1) * (k*(k+1))//2 + k
def main():
    N, K = map(int, input().split())
    #counter = 0
    #for k in range(K, N+2):
    #    print(k * (N - k +1) + 1)
    #    counter += (k * (N - k +1) + 1)
    counter = f(N, N+1) - f(N, K-1)
    print(counter%(1000000007))

if __name__ == "__main__":
    main()




Measured memory_bytes: 9196
h, w = list(map(int, input().split()))
grid = []
for i in range(h):
    temp = list(input())
    if "#" in temp:
        grid.append(temp)
    else:
        h -= 1
i = 0
while i < len(grid[0]):
    for j in range(h):
        if grid[j][i] == "#":
            i += 1
            break
        if j == h - 1:
            for k in range(h):
                del grid[k][i]
for i in range(h):
    print("".join(grid[i]))

Measured memory_bytes: 38896
from sys import stdin
N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]
cnt = 0
abs_sum = 0
for i in A:
    abs_sum += abs(i)
    if i < 0:
        cnt += 1
mi = min([abs(i) for i in A])
if cnt % 2 == 0:
    print(abs_sum)
else:
    print(abs_sum-(mi*2))

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

#define For(i, l, r) for (register int i = (l), i##end = (int)(r); i <= i##end; ++i)
#define Fordown(i, r, l) for (register int i = (r), i##end = (int)(l); i >= i##end; --i)
#define Rep(i, r) for (register int i = (0), i##end = (int)(r); i < i##end; ++i)
#define Set(a, v) memset(a, v, sizeof(a))
#define Cpy(a, b) memcpy(a, b, sizeof(a))
#define debug(x) cout << #x << ": " << (x) << endl

using namespace std;

typedef long long ll;

template<typename T> inline bool chkmin(T &a, T b) { return b < a ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, T b) { return b > a ? a = b, 1 : 0; }

inline int read() {
	int x(0), sgn(1); char ch(getchar());
	for (; !isdigit(ch); ch = getchar()) if (ch == '-') sgn = -1;
	for (; isdigit(ch); ch = getchar()) x = (x * 10) + (ch ^ 48);
	return x * sgn;
}

void File() {
#ifdef zjp_shadow
	freopen ("D.in", "r", stdin);
	freopen ("D.out", "w", stdout);
#endif
}

const int Mod = 1e9 + 7;

ll n; map<pair<ll, ll>, int> M;

int Dfs(ll u, ll v) {
	if (v <= 0) return v == 0;
	if (M.find({u, v}) != M.end()) return M[{u, v}];
	int ans = ((Dfs(u >> 1, v >> 1) + 
				Dfs(u - 1 >> 1, v - 1 >> 1)) % Mod + 
				Dfs(u >> 1, v - 2 >> 1)) % Mod;
	return M[{u, v}] = ans;
}

int main () {

	File();

	cin >> n;

	printf ("%d\n", Dfs(n, n));

	return 0;

}

Measured memory_bytes: 256
def computeGCD(x, y):
    while (y):
        x, y = y, x % y
    return x

def computeLCM(x, y):
    return x * y // computeGCD(x, y)

a, b, c, d = map(int, input().split())
ways1 = b // c - ((a - 1) // c)
ways2 = b // d - ((a - 1) // d)
lcm = computeLCM(c, d)
ways = ways1 + ways2 - (b // lcm - ((a - 1) // lcm))
print(b - a + 1 - ways)



Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

void maxHeapify(vector<int> &a, int i, int n){
	int il = (i+1)*2-1, ir = (i+1)*2;
	int largest;
	if(il < n && a.at(il) > a.at(i)) largest = il;
	else largest = i;
	if(ir < n && a.at(ir) > a.at(largest)) largest = ir;
	// if(i == 3){
	// 	cerr << il << " " << ir << " " << a.at(il) << " " << a.at(ir) << " " << largest << endl;
	// }

	if(largest != i){
		swap(a.at(i), a.at(largest));
		maxHeapify(a, largest, n);
	}
}

void buildMaxHeap(vector<int> &a, int n){
	for(int i = n/2-1; i >= 0; i--){
		maxHeapify(a, i, n);
		// rep(i, n){
		// 	cout << " " << a.at(i);
		// }
		// cout << endl;
	}
}

int main(){
	int n;
	cin >> n;
	vector<int> a(n);
	rep(snip_i, n) cin >> a.at(snip_i);
	buildMaxHeap(a, n);
	rep(i, n){
		cout << " " << a.at(i);
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 4608
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
    static PrintWriter out;

    public static void main(String[] args) throws IOException {
        out = new PrintWriter(new OutputStreamWriter(System.out));
        CF_Reader in = new CF_Reader();

        double n = in.Double();
        double x = n / 3;

        System.out.println(x * x * x);

        out.close();
    }


    static class CF_Reader {
        BufferedReader br;
        StringTokenizer st;

        public CF_Reader() throws IOException {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine().trim());
            return st.nextToken();
        }

        long Long() throws IOException {
            return Long.parseLong(next());
        }

        int Int() throws IOException {
            return Integer.parseInt(next());
        }

        double Double() throws IOException {
            return Double.parseDouble(next());
        }

        char Char() throws IOException {
            return next().charAt(0);
        }

        String Line() throws IOException {
            return br.readLine().trim();
        }
    }
}


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

using namespace std;

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

inline int toInt(string s) {int v; istringstream sin(s);sin>>v; return v;}

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector< vector<int> > Mat;
typedef tuple<int, int, int, int> T;

const int MOD = (int)1e9+7;
const int INF = (int)1e9;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

template <typename T> void chmax(T &a, T b) { a = max(a, b); }
template <typename T> void chmin(T &a, T b) { a = min(a, b); }

ll N, W;
ll v[110], w[110];
vector<ll> wary[5];

int main(){
    cin >> N >> W;
    rep(i, N){
        cin >> w[i] >> v[i];
        ll ww = w[i] - w[0];
        wary[ww].push_back(v[i]);
    }

    for(ll i = 0; i < 4; i++){
        sort(wary[i].begin(), wary[i].end());
        wary[i].push_back(0);
        reverse(wary[i].begin(), wary[i].end());
        for(ll j = 1; j < wary[i].size(); j++){
            wary[i][j] += wary[i][j-1];
        }
    }

    ll ans = 0;
    for(ll i = 0; i < wary[0].size(); i++){
        for(ll j = 0; j < wary[1].size(); j++){
            for(ll k = 0; k < wary[2].size(); k++){
                for(ll l = 0; l < wary[3].size(); l++){
                    if( (i + j + k + l) * w[0] + j + 2 * k + 3 * l > W ){
                        continue;
                    }

                    ll sum = wary[0][i] + wary[1][j] + wary[2][k] + wary[3][l];
                    ans = max(ans, sum);
                }
            }
        }
    }

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

Measured memory_bytes: 256
N, K = map(int, input().split())
R = range(K, N + 2)
A = []
for i in R:
    s_max = (N + (N - i + 1)) * i / 2
    s_min = (i - 1) * i / 2
    n = s_max - s_min + 1
    A.append(n)
S = int(sum(A))
print(S % (10 ** 9 + 7))

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

using namespace std;
#define inputInt(a) int a; cin >> a; 
#define inputInt2(a,b) int a; int b; cin >> a >> b; 
#define inputInt3(a,b,c) int a; int b; int c; cin >> a >> b >> c;
#define inputLong(a) long a;cin >> a; 
#define inputIntArray(a,N) int a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputLongArray(a,N) long a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputIntArray2(a,b,N) int a[N]; int b[N]; for(int i=0;i<N;i++){cin >> a[i] >> b[i];}
#define output(answer) cout << answer << endl;
#define fN(i,N)    for(int i=0; i<N; i++)
#define fSE(i,s,e) for(int i=s; i<=e; i++)
#define ll long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const int LIMIT = 1e6;//1e6→50ms,1e7→500ms,1e8→5000ms程度。
const ll MOD = 1e9+7;
vector<ll> FacMod(LIMIT), InvMod(LIMIT), FacInvMod(LIMIT);

void ComInit(){//tableを作成
  FacMod[0] = FacMod[1] = 1;
  InvMod[0] = 0; InvMod[1] = 1; //InvMod[0]は定義できない
  FacInvMod[0] = FacInvMod[1] = 1;
  
  for(int i=2; i<LIMIT; i++){
    FacMod[i] = FacMod[i-1]*i%MOD;
    InvMod[i] = -InvMod[MOD%i]*(MOD/i)%MOD + MOD;
    FacInvMod[i] = FacInvMod[i-1] * InvMod[i]%MOD;
  }
}

ll ComMod(int n, int k){
  if(n>=0 && k>=0 && n>=k){
    return FacMod[n]*(FacInvMod[k]*FacInvMod[n-k]%MOD)%MOD;
  }else{
    return 0; //戻り値を0にする方が計算結果に影響が少ない。
  }
}

int main()
{
  //input
  int N, K; cin >> N >> K;
  ComInit();

  //main
  
  
  // output
  
  for(int i=1; i<=K; i++){
    //青いボールの分け方→K-1個の仕切りの中からi-1個選ぶ。→青いボールがi組できる。
    ll blue = ComMod(K-1,i-1);
    //青いボールの組を1個の青いボールとみなす。→N-K+1個の箱からi個選ぶ。
    ll red = ComMod(N-K+1,i);
    cout << red*blue%MOD << endl;
  }
  return 0;
}

Measured memory_bytes: 23680
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <iomanip> //fixed << setprecision(10)
 
using namespace std;
 
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
 
typedef long long ll;
typedef vector<int> vi;
 
int main(){
    int n;
    cin >> n;
    if(n%2 == 0){
        cout << n/2 << endl;
    }
    else{
        cout << (n/2)+1 << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
# 02 AtCoder Beginner Contest 106 B - 105
import sys
import math

N = int(input())


def divisor(n):
    ans = 0
    for i in range(1, int(math.sqrt(n + 1)), 2):  # 偶数は回答に含めないため、約数が　2の倍数となる数字は存在しない
        if n % i == 0:
            ans += 1
            if i != int(math.sqrt(n + 1)):
                ans += 1

    return ans


ans = 0
for i in range(105, N + 1, 2):  # 偶数は回答に含めない
    if divisor(i) == 8:
        ans +=1

print(ans)


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

int main() {
  long long MOD = 1000000007; 
  long long n;
  long long k;
  cin >>n>>k;
  long long kotae=0;
  for(int i=k;i<=n+1;i++){
    kotae+=(i*(n-i+1)+1)%MOD;
    //cout<<i*(n-i+1)+1<<endl;
  }
  cout<<kotae%MOD<<endl;
  return 0;
}

Measured memory_bytes: 3632
#pragma region kyomukyomupurin

/**
 *    author  : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏
 *    created : 2020-05-05 17:21:13
 **/

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#include <cmath>
#include <complex>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

using int64 = long long;

template <class T>
using binary_heap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) {
  return os << '(' << p.first << ", " << p.second << ')';
}

template <class T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) {
  int flag = 0;
  for (auto e : vec) os << (flag++ ? ", " : "{") << e;
  return os << (vec.empty() ? "{}" : "}");
}

template <class T>
std::ostream& operator<<(std::ostream& os, const std::set<T>& st) {
  int flag = 0;
  for (auto e : st) os << (flag++ ? ", " : "{") << e;
  return os << (st.empty() ? "{}" : "}");
}

template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) {
  int flag = 0;
  for (auto e : mp) os << (flag++ ? ", " : "{") << e;
  return os << (mp.empty() ? "{}" : "}");
}

template <class T>
std::istream& operator>>(std::istream& is, std::vector<T>& vec) {
  for (T& e : vec) is >> e;
  return is;
}

#define all(_) begin(_), end(_)
#define rall(_) rbegin(_), rend(_)

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

void debug_out() { std::cerr << '\n'; }

template <class Head, class... Tail>
void debug_out(Head&& head, Tail&&... tail) {
  std::cerr << head;
  if (sizeof...(Tail) != 0) std::cerr << ", ";
  debug_out(std::forward<Tail>(tail)...);
}

#pragma endregion kyomukyomupurin

int cnt[1010][1010];

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

  int n; cin >> n;

  for (int i = 0; i < n; ++i) {
    int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2;
    ++cnt[x1][y1]; --cnt[x1][y2]; --cnt[x2][y1]; ++cnt[x2][y2];
  }

  for (int i = 0; i < 1010; ++i) {
    for (int j = 1; j < 1010; ++j) {
      cnt[i][j] += cnt[i][j - 1];
    }
  }

  for (int i = 1; i < 1010; ++i) {
    for (int j = 0; j < 1010; ++j) {
      cnt[i][j] += cnt[i - 1][j];
    }
  }

  int ans = 0;

  for (int i = 0; i < 1010; ++i) {
    for (int j = 0; j < 1010; ++j) {
      ans = max(ans, cnt[i][j]);
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 7196
#include<stdio.h>
#include<string.h>
void reverse(char str[])
{
  int i,j,x;
  char revstr[1000];
  i=0;
  while(str[i]!='\0')
    i++;
  x=i;
  j=0;
  for(i=i-1;i>=0;i--,j++)
    revstr[j]=str[i];
  revstr[j]='\0';
  int n;
  for(n=0;n<x;n++)
    str[n]=revstr[n];
}
main(){
  char str[1000],tmp[1000];
  int i=0;
  while(~scanf("%s",str)){
    strcpy(tmp,str);
    reverse(str);
    if(strcmp(tmp,str)==0){
      i++;
    }
  }
  printf("%d\n",i);
  return 0;
}

Measured memory_bytes: 560
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
 
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
    return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

int main() {
    string s; cin >> s;

    vector<string> v = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};

    int i = find(v.begin(), v.end(), s) - v.begin();

    cout << 7 - i << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<vector>
using namespace std;

class node {
public:
	int d = -1, f = -1;
	vector<int> v;
};

int cnt = 1;
vector<int> A;
node V[10001];

void Serch(int u) {
	V[u].d = cnt; cnt++;

	for (int i = 0; i < V[u].v.size(); i++) {
		if (V[V[u].v[i]].d < 0) {
			Serch(V[u].v[i]);
		}
	}

	V[u].f = cnt; cnt++; A.push_back(u);
}

int main() {
	int v, e, s, t;
	scanf("%d %d", &v, &e);
	for (int i = 0; i < e; i++) {
		scanf("%d %d", &s, &t);
		V[s].v.push_back(t);
	}

	for (int i = 0; i < v; i++) {
		if (V[i].d < 0) Serch(i);
	}

	for (int i = v-1; i  >= 0; i--) cout << A[i] << endl;
	return 0;
}


Measured memory_bytes: 3660
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program{
	const int mod=(int)1e9+7;
	const double eps=1e-11;
	static void Main(){
		Sc sc=new Sc();
		var s=sc.S;
		Console.WriteLine("{0}",(s[0]=='7'||s[1]=='7'||s[2]=='7')?"Yes":"No");
	}
}
public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),int.Parse);}
	public int[] Ia3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),long.Parse);}
	public long[] La3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),long.Parse);}
	public double[] Da2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),double.Parse);}}
	public double[] Da3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),double.Parse);}
	public double[] Da3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),double.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}

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

int n, c;
int beet[32];
int press[32];
int dp[32][1 << 17];

int dfs(int board, int p);
int bit_count(int x);

int main()
{
    int a;
    
    while (scanf("%d %d", &n, &c), n != 0 && c != 0) {
        for (int i = 0; i < 32; i++) {
            for (int j = 0; j < (1 << 17); j++) {
                dp[i][j] = -1;
            }
            beet[i] = 0;
            press[i] = 0;
        }
        
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < 16; j++) {
                scanf("%d", &a);
                beet[i] = (beet[i] << 1) | a;
            }
        }

        for (int i = 0; i < c; i++) {
            for (int j = 0; j < 16; j++) {
                scanf("%d", &a);
                press[i] = (press[i] << 1) | a;
            }
        }

        cout << dfs(0, 0) << endl;
    }
    return 0;
}

int dfs(int board, int p)
{
    if (dp[p][board] != -1) {
        return dp[p][board];
    }
    
    if (p >= n) {
        return 0;
    }

    int b = board | beet[p];
    int max_score = 0;
    int score;

    for (int i = 0; i < c; i++) {
        score = bit_count(b & press[i]);
        max_score = max(max_score, dfs(b & (~press[i]), p + 1) + score);
    }

    return dp[p][board] = max_score;
}

int bit_count(int x)
{
    int ans = 0;
    while (x) {
        ans += (x & 1);
        x = x >> 1;
    }
    return ans;
}



Measured memory_bytes: 19532