akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int n;
  cin >> n;
  
  vector<int> p(n);
  for(int i=0;i<n;i++){
    cin >> p.at(i);
  }
  
  int ans=0;
  
  for(int j=0;j<n-2;j++){
    if((p.at(j)<p.at(j+1)&&p.at(j+1)<p.at(j+2))||(p.at(j)>p.at(j+1)&&p.at(j+1)>p.at(j+2))){
      ans++;
    }
       }
       
    cout << ans << endl;
  }


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep0(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
  int n, ans=0;
  string s;
  cin >> n >> s;
    rep0(j,10){
      rep0(i,n){
        if((int)(s[i]-'0')==j){
          rep0(k,10){
            for(int m=i+1;m<n;m++){
              if((int)(s[m]-'0')==k){
                rep0(l,10){
                  for(int p=m+1;p<n;p++){
                    if((int)(s[p]-'0')==l){
                      ans++;
                      break;
                    }
                  }
                }
                break;
              }
            }
          }
          break;
        }
      }
      
    }
    cout << ans;

}

Measured memory_bytes: 256
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi  vector<int> 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   all(a) (a.begin(),a.end())
#define   ff   first
#define   ss   second
#define   pii  pair<int,int> 
#define   lcm(a,b) (a*b)/__gcd(a,b) 
using namespace std;

inline void solve(){
    int n; cin>>n;
    n--; 
    vi c(n),s(n),f(n);
    for (int i=0;i<n;i++) cin>>c[i]>>s[i]>>f[i];
    for (int i=0;i<n;i++){
        int sum=c[i]+s[i];
        for (int j=i+1;j<n;j++){
            if (s[j]>=sum) sum=s[j];
            if (sum%f[j]) sum += (f[j]-(sum%f[j]));
            sum += c[j]; 
        }
        cout << sum << endl;
    }
    cout << 0 << endl;
}

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


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

#define For(i, j, k) for(int i = j; i <= k; i++)

using namespace std;

const int N = 410, M = 1000;

struct Face{
	int col[4];

	Face change(int mn){
		int tmp[4];
		Face ret;
		For(i, 0, 3) tmp[i] = col[i];
		For(i, 0, 3) ret.col[i] = tmp[(mn + i) % 4];
		return ret;
	}

	void Rotate(){
		int mn = 0;
		long long v = 1ll << 60;
		For(i, 0, 3){
			long long s = 0;
			For(j, 0, 3) s = s * M + col[(i + j) % 4];
			if(s < v) v = s, mn = i;
		}
		*this = change(mn);
	}

	bool operator < (const Face& A) const{
		For(i, 0, 3) if(col[i] ^ A.col[i]) return col[i] < A.col[i];
		return false;
	}

	bool operator == (const Face& A) const{
		return !(*this < A || A < *this);
	}
}A[N];

int n;
multiset<Face> S;

int main(){
	
	scanf("%d", &n);
	For(i, 1, n) For(j, 0, 3) scanf("%d", &A[i].col[j]);
	For(i, 1, n) A[i].Rotate(), S.insert(A[i]);

	long long ans = 0;
	For(i, 1, n) For(j, i + 1, n){
		For(d, 0, 3){
			Face B[4];
			long long ret = 1;
			For(k, 0, 3){
				B[k].col[1] = A[i].col[k], B[k].col[0] = A[i].col[(k + 1) % 4];
				B[k].col[3] = A[j].col[(4 - k + d) % 4], B[k].col[2] = A[j].col[(4 - k + d + 1) % 4];
				B[k].Rotate();
				int same = (B[k] == A[i]) + (B[k] == A[j]);
				For(v, 0, k - 1) same += B[v] == B[k];
				ret *= (S.count(B[k]) - same);
				
				same = 1;
				For(v, 1, 3) if(B[k].change(v) == B[k]) ++same;
				ret *= same;
			}
			ans += max(0ll, ret);
		}
	}

	printf("%lld\n", ans / 3);
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); ++(i))
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<int, lint> pil;
typedef pair<lint, int> pli;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod*mod;
constexpr int MAX = 1000010;

int main(){
        int n;
        scanf("%d", &n);
        pii p[n];
        rep(i, n){
                int x, L;
                scanf("%d%d", &x, &L);
                p[i]={x-L, x+L};
        }
        sort(p, p+n, [](const pii &a, const pii &b){return a.se<b.se;});
        int last=-INT_MAX, ans=0;
        rep(i, n){
                if(last<=p[i].fi){
                        ++ans;
                        last=p[i].se;
                }
        }
        printf("%d\n", ans);
}

Measured memory_bytes: 1024
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * @author mihira
 *
 */
public class Main {
    
    static final String keyAc = "AC";
    
    static final String keyWa = "WA";
    
    static final String keyTle = "TLE";

    static final String keyRe = "RE";
    
    static final String cntLiteral = " x ";
    
    
    public static void main(String[] args) {
        
        //　入力された値を受け取る
        Scanner scanner = new Scanner(System.in);
        
        List<String> list = new ArrayList<>();
        
        int cntNum = Integer.parseInt(scanner.nextLine());
        
        for (int i = 0; i < cntNum ; i++) {
            String getData = scanner.nextLine();
            list.add(getData);
        }
        
        // 保持した値をイコールズメソッドで比較
        
        int cntAc = 0;
        
        int cntWa = 0;
        
        int cntTle = 0;
        
        int cntRe = 0;
        
        
        for(int cntupNum = 0; cntupNum< cntNum; cntupNum++){  
                
            switch(list.get(cntupNum)) {
                case keyAc:
                    cntAc++;
                    break;
                    
                case keyWa:
                    
                    cntWa++;
                    break;
                    
                case keyTle:
                    
                    cntTle++;
                    break;
                    
                case keyRe:
                    
                    cntRe++;
                    break;
                    
                
            }
            
            
        
        }

        System.out.println(keyAc+cntLiteral+cntAc);
        
        System.out.println(keyWa+cntLiteral+cntWa);
        
        System.out.println(keyTle+cntLiteral+cntTle);
        
        System.out.println(keyRe+cntLiteral+cntRe);
    }

}


Measured memory_bytes: 66032
n = int(input())
a = list(map(int,input().split()))
gcd = a[-1]
def Euclid(n1,n2):
    if n1 % n2 == 0:
        return n2
    return Euclid(n2,n1%n2)
for i in range(n-1):
    gcd = Euclid(gcd,a[(-1)*(i+2)])
print(gcd)


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

using namespace std;

const int N = 1e5+5;

const int mod = 1e9+7;

int main(){
    int n , x , t;
    cin >> n >> x >> t;
    int cnt = 0;
    while(n){
        cnt += t;
        n -= min(n , x);
    }
    cout << cnt << "\n";
	return 0;
}


Measured memory_bytes: 3568
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int p = sc.nextInt();
        int q = sc.nextInt();
        int r = sc.nextInt();


        System.out.println(Math.min(p + q, Math.min(q + r, r + p)));


    }

}


Measured memory_bytes: 21844
#include <iostream>
#include <cstdio>
//#define DEBUG
using namespace std;
const int MAX = 1e5 + 10;
int arr[MAX];
int answer[MAX];
char char_answer[MAX];
int main(int argc, char *argv[]) {
	int N;
	while(cin >> N) {
		scanf("%s", char_answer + 1);
		for(int i = 1; i <= N; i++) {
			
			
			if(char_answer[i] == 'o')
				answer[i] = 1;
			else {
				answer[i] = 0;
			}
			
			#ifdef DEBUG 
			cout << char_answer[i];
			#endif
		}
		#ifdef DEBUG 
		cout << endl;
		#endif
		//cases: 1 sheet 0 wolf
		int flag = 0;
		for(int cases = 0; cases < 2; cases++) {
			arr[1] = cases;
			for(int i = 0; i < 2; i++) {
				arr[0] = i;
				for(int j = 1; j <= N; j++) {
					if(arr[j]) { // j is sheet
						if(answer[j]) // answer is o
							arr[j + 1] = arr[j - 1];
						else {
							arr[j + 1] = arr[j - 1] ^ 1;
						}
					}else { // j is wolf
						if(answer[j])// answer is o
							arr[j + 1] = arr[j - 1] ^ 1;
						else {
							arr[j + 1] = arr[j - 1];
						}
					}
				}
				#ifdef DEBUG
				for(int l = 0; l <= N + 1; l++) {
					cout << arr[l];
					
				}
				cout << endl;
				#endif
				if(arr[0] == arr[N] && arr[N + 1] == arr[1] && flag == 0) {
					for(int i = 1; i <= N; i++) {
						if(arr[i])
							cout << "S";
						else {
							cout << "W";
						}
					}
					cout << endl;
					flag = 1;
					
				}
			}
		}
		if(flag == 0)
			cout << -1 << endl;
		
	}
}

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

#include<iomanip>
using namespace std;
int main()
{
    int n;
    cin>>n;
    vector<double> p;
    for (int i=0;i<n;i++)
    {
        double a;
        cin>>a;
        p.push_back(a);
    }
    vector<vector<double>> dp;
    for (int i=0;i<n+1;i++)
    {
        vector<double> v1(n+1);
        dp.push_back(v1);
    }
    dp[0][0]=1;
    
    for (int i=1;i<n+1;i++)
    {
        for (int j=0;j<n+1;j++)
        {
            if (j==0)
            {
                dp[i][j]=(1-p[i-1])*dp[i-1][j];
            }
            else
            {
                dp[i][j]=(1-p[i-1])*dp[i-1][j]+p[i-1]*dp[i-1][j-1];
            }
            
        }
    }
    double sum=0;
    for(int i=n/2+1;i<=n;i++)
    {
        sum+=dp[n][i];
    }
    cout<<setprecision(9)<<sum;
    
}

Measured memory_bytes: 73812
from collections import Counter

s = str(input())
k = int(input())
d = Counter(s)
L = sorted(d.keys())[:k]
ss = set()
for c in L:
    for i in range(len(s)):
        if s[i] == c:
            ss.add(s[i])
            for j in range(1, k+1):
                if i + j >= len(s):
                    break
                else:
                    ss.add(s[i:i+j+1])
print(sorted(ss)[k-1])

Measured memory_bytes: 3700
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(LL &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const LL &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
VL AA[8];
int main(){
    int N,M;
    R(N,M);
    REP(i,N){
        LL d[3];
        REP(j,3)R(d[j]);
        REP(j,8){
            LL now=0;
            REP(k,3){
                if((j>>k)&1)now+=d[k];
                else now-=d[k];
            }
            AA[j].PB(now);
        }
    }
    LL an=0;
    REP(i,8){
        sort(ALL(AA[i]),greater<LL>());
        LL now=0;
        REP(j,M)now+=AA[i][j];
        an=max(an,now);
    }
    W(an);
    return 0;
}


Measured memory_bytes: 384
K, N = map(int, input().split())

A = list(map(int, input().split()))
D = []

for i in range(0,N-1):
  d = A[i + 1] - A[i]
  D.append(abs(d))
  
d2 = A[N-1] - (A[0] + K)
D.append(abs(d2))

kankaku = max(D)
saitan = K - kankaku

print(saitan)

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

int main(){
    int N;
    cin>>N;
    vector<int>A(N-1),B(N,0);
    for(int i=0;i<N-1;i++){
        cin>>A.at(i);
        ++B.at(A.at(i)-1);
    }
    for(int i=0;i<N;i++){
        cout<<B.at(i)<<endl;
    }
}


Measured memory_bytes: 4768
s = input()
n = len(s)+1
a = [0]*n
l = []
c = 0
for i in range(len(s)-1):
  if s[i] != s[i+1]:
    l.append([s[c], c, i-c+1])
    c = i+1
l.append([s[c], c, len(s)-c])

for i in l:
  if i[0] == "<":
    for j in range(i[2]+1):
      a[i[1]+j] = max(a[i[1]+j], j)
  else:
    for j in range(i[2]+1):
      a[i[1]+j] = max(a[i[1]+j], i[2]-j)
      
print(sum(a))

Measured memory_bytes: 40860
import sys

def gcd(a, b): return gcd(b, a % b) if b else abs(a)
def lcm(a, b): return abs(a // gcd(a, b) * b)

n, *x = map(int, sys.stdin.read().split())

def main():
    d = abs(x[1] - x[0])
    for i in range(1, n):
        d = gcd(d, x[i+1] - x[i])
    print(d)

if __name__ ==  '__main__':
    main()

Measured memory_bytes: 14052
#include <bits/stdc++.h>
 
using namespace std;
using ll = long long;
// #define int ll
using PII = pair<int, int>;
 
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
 
template<typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }
 
template<typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts) { 
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type
fill_v(T &t, const V &v) { t=v; }
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t, const V &v ) { for(auto &e:t) fill_v(e,v); }
 
template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')'; return out;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
  for(T& x: vec) {is >> x;} return is;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'['; for(T i: a) {out<<i<<',';} out<<']'; return out;
}
 
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; // DRUL
const int INF = 1<<30;
const ll LLINF = 1LL<<40;
const ll MOD = 1000000007;

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

  ll n;
  cin >> n;
  n = 2*n-1;
  vector<ll> a(n);
  REP(i, n) cin >> a[i];
  
  //         0
  //       1,0,0
  //     1,0,1,0,0
  //   1,0,1,0,1,0,0
  // 1,0,1,0,1,0,1,0,0

  auto check = [&](ll mid) -> bool {
    vector<ll> v(n);
    REP(i, n) v[i] = a[i] >= mid;

    ll l = n/2, r = n/2;
    while(l>0 && v[l] != v[l-1]) l--;
    while(r<n-1 && v[r] != v[r+1]) r++;
    if(v[l] != v[r]) {
      if(l+1 <= n/2) l++;
      else r--;
    }
    // cout << l << " " << r << endl;
    if(n/2 < (l+r)/2) return v[l-1];
    if((l+r)/2 < n/2) return v[r+1];
    return v[l];
  };

  // cout << check(5) << endl;

  ll lb = 1, ub = n+1;
  while(ub-lb > 1) {
    ll mid = (lb+ub)/2;
    // cout << lb << " " << mid << " " << ub << endl;
    if(check(mid)) lb = mid;
    else ub = mid;
  }

  cout << lb << endl;

  return 0;
}


Measured memory_bytes: 3436
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String N = sc.next();
		sc.close();
		char[] tmpN = new char[N.length()];
		for(int a = 0 ; a < N.length() ; a++){
			if(N.charAt(a)=='1'){
				tmpN[a] = '9';
			}else{
				tmpN[a] = '1';
			}
		}
		String N2 = new String(tmpN);
		System.out.println(N2);
	}
}

Measured memory_bytes: 23252
n = int(input())
s = input()
ans = 0
for i in range(n):
    s1 = [s[j] for j in range(i) ]
    s2 = [s[j] for j in range(i,n)]
    s1 = set(s1)
    s2 = set(s2)
    ans = max(len(list(s1 & s2)),ans)
print(ans)


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

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

    private void run() {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int[] v = new int[N];
        for(int i = 0; i < N; i++) {
            v[i] = scanner.nextInt();
        }
        Arrays.sort(v);
        double prev = v[0];
        for(int i = 1; i < N; i++) {
            prev = (prev + v[i]) / 2;
        }
        System.out.println(prev);
    }
}


Measured memory_bytes: 21844
N, M = map(int, input().split(' '))
AC = [0]*N
WA = [0]*N

for i in range(M):
    # for文で回しつつ処理する
    p, S = input().split(' ')
    p = int(p)
    #  ACの場合
    if S == 'AC':
        #  結果番号を格納
        AC[p-1] = 1
    #  WAの場合, かつ前回正解していない
    elif S == 'WA' and AC[p-1] == 0:
        #  不正解番号を格納
        WA[p-1] += 1
 
AC_cnt = 0
WA_cnt = 0
for i in range(N):
    # 正解があった場合
    if AC[i] == 1:
        # 正解数とカウント
        AC_cnt += 1
        # ペナルティとカウント
        WA_cnt += WA[i]
 
print(AC_cnt, WA_cnt)

Measured memory_bytes: 4596
# coding: utf-8
# Here your code !

H , W  = input().split()
H = int(H)
W = int(W)
OK = False

st = ""
for n in range(H):
    st += input()
    
counter = {}
for c in st:
    if not c in counter:
        counter[c] = 1
    else:
        counter[c] += 1

#H,Wが偶数の時
if (H % 2 == 0) & (W % 2 == 0) :
    for i in counter.keys():
        if not (counter[i] % 4 == 0) : 
            #一度でも4の倍数でなかったらだめ
            OK = False
            break
        OK = True
elif (H % 2 != 0) & (W % 2 != 0) :
    #一個の奴が必ず一つある -> 奇数が必ず一つある
    kisuuCounter = 0
    for i in counter.keys():
        if counter[i] % 2 == 1 : 
            kisuuCounter += 1
            kisuu = i
    
    if kisuuCounter == 1 : 
        counter[kisuu] -= 1
        twoPair = (W + H - 2) / 2
        q = {i : (counter[i] % 4) / 2 for i in counter.keys()}
        p = {i: (counter[i] - 2*q[i]) / 4 for i in counter.keys() }
        
        x = twoPair - sum(q.values())
        if (x >= 0) & (x % 2 == 0) & (x <= 2 * sum(p.values())) : 
            OK = True
else :
    kisuuCounter = 0
    for i in counter.keys():
        if counter[i] % 2 == 1 : 
            kisuuCounter += 1
            kisuu = i
    
    if kisuuCounter == 0 :
        if H % 2 == 0 : 
            twoPair = H / 2
        else : 
            twoPair = W / 2
        
        q = {i : (counter[i] % 4) / 2 for i in counter.keys()}
        p = {i: (counter[i] - 2*q[i]) / 4 for i in counter.keys() }
        x = twoPair - sum(q.values())
        if (x >= 0) & (x % 2 == 0) & (x <= 2 * sum(p.values())) : 
            OK = True
        
if OK : print("Yes")
else : print("No")

Measured memory_bytes: 3188
#include<bits/stdc++.h> //Ithea Myse Valgulious
namespace chtholly{
typedef long long ll;
#define re0 register int
#define rec register char
#define rel register ll
#define gc getchar
#define pc putchar
#define p32 pc(' ')
#define pl puts("")
/*By Citrus*/
inline int read(){
  int x=0,f=1;char c=gc();
  for (;!isdigit(c);c=gc()) f^=c=='-';
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return f?x:-x;
  }
inline bool read(ll &x){
  x=0;int f=1;char c=gc();
  for (;!isdigit(c)&&~c;c=gc()) f^=c=='-';
  if (!~c) return 0;
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return x=f?x:-x,1;
  }
template <typename mitsuha>
inline int write(mitsuha x){
  if (!x) return pc(48);
  if (x<0) x=-x,pc('-');
  int bit[20],i,p=0;
  for (;x;x/=10) bit[++p]=x%10;
  for (i=p;i;--i) pc(bit[i]+48);
  }
inline char fuhao(){
  char c=gc();
  for (;isspace(c);c=gc());
  return c;
  }
}using namespace chtholly;
using namespace std;
int mp[999][999],w=read(),h=read();

int main(){
int i,j;
for (int n=read();n--;){
  int x=read(),y=read(),op=read();
  switch(op){
    case 1:{
      for (i=0;i<x;++i){
        for (j=0;j<h;++j){
          mp[i][j]=1; 
		  }
	    }
	  break;
	  }
	case 2:{
	  for (i=x;i<w;++i){
	    for (j=0;j<h;++j){
	      mp[i][j]=1;
		  }
	    }
	  break;
	  }
	case 3:{
	  for (i=0;i<w;++i){
	    for (j=0;j<y;++j){
	      mp[i][j]=1;
		  }
	    }
	  break;
	  }
	case 4:{
	  for (i=0;i<w;++i){
	    for (j=y;j<h;++j){
	      mp[i][j]=1;
		  }
	    }
	  break;
	  }
    }
//  for (i=0;i<w;++i,pl){
//    for (j=0;j<h;++j){
//      write(mp[i][j]),p32; 
//	  }
//    }
  }
int ans=0;
for (i=0;i<w;++i){
  for (j=0;j<h;++j) ans+=!mp[i][j]; 
  }write(ans);
}


Measured memory_bytes: 640
#include<stdio.h>

int main()
{
    int k,x,start,end,i;
    
    scanf("%d %d",&k,&x);
    
    
    start = x - k + 1;
    end = x + k - 1;
    
    printf("%d",start);
    for(i=start+1;i<end+1;i++)
    {
        printf(" %d",i);
    }
    printf("\n");
    
    
    return 0;
}



Measured memory_bytes: 128
N, M = map(int, input().split())

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
uf = UnionFind(N)
#print(uf.parents)

for i in range(M):
    a = list(map(int, input().split()))
    uf.union(a[0]-1, a[1]-1)
#print(uf)
print(uf.group_count()-1)

Measured memory_bytes: 12752
#include <bits/stdc++.h>
using namespace std;
using str = string;
using ll = long long;
#define REP(i,n) for(int i=0; i<int(n); i++)
#define RREP(i,n) for(int i=int(n)-1; i>=0; i--)
#define FOR(i,f,t) for(int i=int(f); i<=int(t); i++)
#define RFOR(i,f,t) for(int i=int(f); i>=int(t); i--)
#define ALL(vec) (vec).begin(),(vec).end()
#define ASORT(vec) sort(ALL(vec))
#define DSORT(vec) sort(ALL(vec), greater<int>());
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define YES(ans) if(ans) cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define Yes(ans) if(ans) cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define yes(ans) if(ans) cout<<"yes"<<endl; else cout<<"no"<<endl;

int main() {
    int x, y, z;
    cin >> x >> y >> z;
    cout << z << " " << x << " " << y << endl;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
typedef map <str,int> mapsi;
typedef map <str,int> :: iterator mapsitr;
typedef map <int , int> mint;
typedef map <ll , ll> mll;
typedef set <int> si;
typedef set <ll> sll;
typedef si :: iterator sitr;
typedef si :: reverse_iterator rsitr;
typedef sll :: iterator sltr;
typedef sll :: reverse_iterator rsltr;
#define mset multiset
typedef mset <int> msi;
typedef mset <ll> msll;
typedef msi :: iterator msitr;
typedef msi :: reverse_iterator msritr;
typedef msll :: iterator msltr;
typedef msll :: reverse_iterator mslritr;
#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define fi first
#define se second
#define fs first.second
#define ss second.second
#define ff first.first
#define sf second.first
#define newl '\n'
char to_upper (char x){
    if( 97 <= int(x) && int(x) <= 126)return char(x-32);
    else if( 65 <= int(x) && int(x) <= 90)return x;
}
char to_lower (char x){
    if( 97 <= int(x) && int(x) <= 126)return x;
    else if( 65 <= int(x) && int(x) <= 90)return char(x+32);
}
int numerize (char x){
    if(48 <= int(x) && int(x) <= 57)return int(x-'0');
    else if( 97 <= int(x) && int(x) <= 126)return int(x-96);
    else if( 65 <= int(x) && int(x) <= 90)return int(x-64);
}
//void IO(){
//	#ifndef ONLINE_JUDGE
//	    freopen("input.txt", "r", stdin);
//	    freopen("output.txt", "w", stdout);
//	#endif
//}
// end of Template

int m;
int main(){
	//IO();
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>m;
    cout<<(24-m)+24<<newl;
}


Measured memory_bytes: 256
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String one = sc.next();
        String two = sc.next();
        String three = sc.next();
        System.out.print(three + " ");
        System.out.print(one + " ");
        System.out.print(two);
    }
}


Measured memory_bytes: 25172
#include <bits/stdc++.h>
using namespace std;
typedef long long   signed int LL;
typedef long long unsigned int LU;
#define incII(i, l, r) for(int i = (l)    ; i <= (r); ++i)
#define incID(i, l, r) for(int i = (l)    ; i <  (r); ++i)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); --i)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec(i, n)  decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
template<typename T> bool setmin  (T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmax  (T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
LL mo(LL a, LL b) { assert(b > 0); a %= b; if(a < 0) { a += b; } return a; }
LL fl(LL a, LL b) { assert(b > 0); return (a > 0 ? a / b : (a - b + 1) / b); }
LL ce(LL a, LL b) { assert(b > 0); return (a < 0 ? a / b : (a + b - 1) / b); }
#define bit(b, i) (((b) >> (i)) & 1)
#define BC __builtin_popcountll
#define SC(T, v) static_cast<T>(v)
#define SI(v) SC(int, v.size())
#define SL(v) SC( LL, v.size())
#define RF(e, v) for(auto & e: v)
#define ei else if
#define UR assert(false)

// ---- ----

int H, h, W, w;

int main() {
	cin >> H >> W >> h >> w;
	
	cout << (H - h) * (W - w) << endl;
	
	return 0;
}


Measured memory_bytes: 256
<?php
 	$a = fgets(STDIN);
	$b = fgets(STDIN);
	$c = fgets(STDIN);
	$x = fgets(STDIN);
	$answer = 0;
	for ($i = 0; $i <= $a; $i ++) {
      for ($j = 0; $j <= $b; $j ++) {
        for ($k = 0; $k <= $c; $k ++) {
          if ($i * 500 + $j * 100 + $k * 50 == $x) {
          	$answer += 1;
          }
        }
      }
    }

	echo $answer;
          
?>

Measured memory_bytes: 5240
#include <iostream>

using namespace std;

int main() 
{
    int w, h, x, y, r;
    cin >> w >> h >> x >> y >> r;
    if(x-r >= 0 && y-r >= 0 && x+r<=w && y+r<=h)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}


Measured memory_bytes: 3116
n = gets.chomp.to_i
aa = []
bb = []
 
n.times do
  a, b = gets.chomp.split(" ").map(&:to_i)
  aa << a
  bb << b
end
 
ret = 0
 
(n-1).downto(0).each do |i|
  if bb[i] == 1 || aa[i] == 0 then
    c = 0
  elsif aa[i] >= bb[i] && aa[i] % bb[i] == 0
    c = 0
  elsif  aa[i] > bb[i] then
    c =  (aa[i] / bb[i] + 1) * bb[i] - aa[i]
  else
    c = bb[i] - aa[i]
  end
  ret += c
  aa[i] += c
  aa[i-1] += ret if i > 0
end
 
puts ret

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

const long long INF = 1000000000;

typedef long long ll;

#define writeln(n) cout<<n<<"\n"
#define rep(i,n) for(int i=0; i<(n); ++i)

typedef pair<int, int> P;
typedef pair<string, int> Psi;


ll d[6];

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


	ll n;cin>>n;

	ll mi =10000000000000000;

	rep(i,5){
		ll tmp; cin>>tmp;

		mi = min(mi,tmp);

		d[i] =tmp;
	}

	if((n-mi)%mi && n >mi){
		writeln(5+1+(n-mi)/mi);
	}else {
		writeln(5+(n-mi)/mi);
	}


}



Measured memory_bytes: 256
/*
**   Contest : AtCoder Beginner Contest 165
**   Problem : C - Many Requirements

**    Author : Dhiraj Govindvira
**      Date : 02-May-2020 ~ Saturday
**      Time : 08:39:31 PM
*/

#if __has_include("D:/dhiraj/Programming/debug.h")
    #include "D:/dhiraj/Programming/debug.h"
#else
    #include <bits/stdc++.h>
    using namespace std;
    #define d(...) 11
#endif

// Loops --------------------------------------------------------------------

#define loop(i,s,e)         for(ll i=(s); i<(e); i++)
#define rloop(i,s,e)        for(ll i=(s); i>=(e); i--)
#define iter(it,var)        for(auto it=var.begin(); it!=var.end(); it++)
#define riter(it,var)       for(auto it=var.rbegin(); it!=var.rend(); it++)

// Extra --------------------------------------------------------------------

#define ull                 unsigned long long int
#define ll                  long long int
#define ld                  long double
#define endl                '\n'
#define all(x)              x.begin(),x.end()
#define rall(x)             x.rbegin(),x.rend()

// Template -----------------------------------------------------------------

template <typename T> 
inline bool inrange(T a, T l, T r) {
    if(l>r) swap(l,r);
    return (a>=l and a<=r);
}
template <typename T, typename U> 
inline bool exist(T val, U &any) {
    return (any.find(val) != any.end());
}
// multiple input
template <typename T> 
inline void inp(T &any) {
    cin >> any;
}
template <typename T, typename... U> 
inline void inp(T &a, U &...b) {
    cin >> a; inp(b...);
}
// scan vector
template <typename T> 
inline istream &operator>>(istream &in, vector<T> &a) {
    for(auto &x : a) in >> x;
    return in;
}
// scan pair
template <typename T, typename U> 
inline istream &operator>>(istream &in, pair<T,U> &a) {
    in >> a.first >> a.second; 
    return in;
}

// Solve --------------------------------------------------------------------

void solve(ll &T)
{
    ll n, m, q;
    std::cin>>n>>m>>q;

    vector<ll> a(q), b, c, d;
    b = c = d = a;
    loop(i,0,q) {
        std::cin>>a[i]>>b[i]>>c[i]>>d[i];
        a[i]--, b[i]--;
    }

    vector<ll> A;
    ll ans = 0;
    function<void(int)> dfs = [&](ll val)
    {
        if(A.size()==n)
        {
            d(A);
            ll pt = 0;
            loop(i,0,q) {
                if(A[b[i]]-A[a[i]]==c[i]) {
                    pt += d[i];
                }
            }
            ans = max(ans, pt);
            return;
        }

        loop(i,val,m+1)
        {
            A.push_back(i);
            dfs(i);
            A.pop_back();
        }
    };
    dfs(1);

    std::cout<<ans<<endl;
}

// Main ---------------------------------------------------------------------

int main()
{
    #ifdef Dhiraj
        freopen("D:/dhiraj/Programming/i1.txt","r",stdin);
        freopen("D:/dhiraj/Programming/o1.txt","w",stdout);
    #endif

    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    int t = 1;
    loop(i,1,t+1)
    {
        cerr<<"Case #"<<i<<"\n";
        solve(i);
    }
    return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
	using namespace std;
	typedef long long int ll;
	int main() {
		// #ifndef ONLINE_JUDGE
		// 	// for getting input from input.txt
		// 	freopen("input.txt", "r", stdin);
		// 	// for writing output to output.txt
		// 	freopen("output.txt", "w", stdout);
		// #endif
		ll a,b;
		char x;
	  cin>>a>>x>>b;
	  if(x == '+'){
	  cout<<a+b<<"\n";
	  }
	  else{
	  cout<<a-b<<"\n";
	  }
		return 0;
		}	

Measured memory_bytes: 384
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        Map<String, Integer> map = new HashMap<String, Integer>();
        
        int N = Integer.parseInt(sc.next());
        
        for(int n=0; n<N; n++){
            String s = sc.next();
            if(map.get(s) == null){
                map.put(s, 1);
            }else{
                map.put(s, map.get(s) + 1);
            }
        }
        
        int M = Integer.parseInt(sc.next());
        for(int m=0; m<M; m++){
            String t = sc.next();
            if(map.get(t) == null){
                map.put(t, -1);
            }else{
                map.put(t, map.get(t) -1);
            }
        }
        
        int answer = 0;
        for(String key : map.keySet()){
            int value = map.get(key);
            if(value > answer){
                answer = value;
            }
        }
        
        System.out.println(answer);
    }
}

Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int N = 2e5 + 10;
int n;
map<string, int> mp;
bool cmp(pair<string, int> a, pair<string, int> b) {
    return a.second < b.second;
}
int main() {
    string str;
    scanf("%d", &n);
    int maxcnt = 0;
    for (int i = 0; i < n; ++i) {
        cin >> str;
        mp[str]++;
        maxcnt = max(maxcnt, mp[str]);
    }
    vector<pair<string, int>> v;
    vector<string> ans;
    for (auto it = mp.begin(); it != mp.end(); ++it) {
        v.push_back(pair<string, int>(it->first, it->second));
    }
    sort(v.begin(), v.end(), cmp);
    for (auto it = v.begin(); it != v.end(); ++it) {
        if (it->second == maxcnt) ans.push_back(it->first);
    }
    sort(ans.begin(), ans.end());
    for (int i = 0; i < ans.size(); ++i) {
        cout << ans[i] << '\n';
    }
    return 0;
}

Measured memory_bytes: 32496
#include "bits/stdc++.h"
using namespace std;

const int N=2e5+20,MOD=998244353;

int n,m,k,f[N],ie[N];
long long ans;

int power(int a,int b)
{
	int num=a,ans=1;
	for(int i=0;i<31;i++)
	{
		if(b&(1<<i)) ans=(1ll*ans*num)%MOD;
		num=(1ll*num*num)%MOD;
	}
	return ans;
}

int inverse_euler(int n)
{
	return power(n,MOD-2);
}

int ncr(int n,int r)
{
	return (1LL*f[n]*((1LL*ie[r]*ie[n-r])%MOD))%MOD;
}

void precompute()
{
	f[0]=1;
	for(int i=1;i<N;i++) f[i]=(1LL*f[i-1]*i)%MOD;
	for(int i=0;i<N;i++) ie[i]=inverse_euler(f[i]);
}

int main()
{
	scanf("%d%d%d",&n,&m,&k);

	precompute();
	for(int i=0;i<=k;i++)
	{
		long long pv=(1ll*m*power(m-1,n-i-1))%MOD;
		ans+=(1ll*pv*ncr(n-1,i))%MOD;
		ans%=MOD;
	}
	cout<<ans;
}

Measured memory_bytes: 5324
X=int(input())
if X<=599:
  print(8)
elif 600<=X<=799:
  print(7)
elif 800<=X<=999:
  print(6)
elif 1000<=X<=1199:
  print(5)
elif 1200<=X<=1399:
  print(4)
elif 1400<=X<=1599:
  print(3)
elif 1600<=X<=1799:
  print(2)
elif 1800<=X<=1999:
  print(1)

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


int main(){
  int N;
  cin >> N;
  vector<int> H(N);
  for(auto& h : H){
    cin >> h;
  }
  int ans = 0;
  int pre_h = -1;
  int count = 0;
  for(auto& h : H){
    if(h <= pre_h){
      count++;
    }else{
      ans = max(ans, count);
      count = 0;
    }
    pre_h = h;
  }
  ans = max(ans, count);
  cout << ans << endl;
  return 0;
}


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

int C[100005];

void CountingSort(vector<int> &A, vector<int> &B, int k)
{
	for(int i = 0; i <= k; ++i)
	{
		C[i] = 0;
	}
	
	for(int j = 0; j < A.size(); ++j)
	{
		++C[A[j]];
	}

	for(int i = 1; i <= k; ++i)
	{
		C[i] += C[i - 1];
	}
	
	for(int j = A.size() - 1; j >= 0; --j)
	{
		
		--C[A[j]];
		B[C[A[j]]] = A[j];
	}
}

int main()
{
	int N, temp, max = 0;
	vector<int> A, B;
	
	cin >> N;
	for(int i = 0; i < N; ++i)
	{
		cin >> temp;
		A.push_back(temp);
		B.push_back(temp);
		
		if(temp > max)
		{
			max = temp;
		}
	}
	
	CountingSort(A, B, max);
	
	for(int i = 0; i < B.size(); ++i)
	{
		if(i != 0)
		{
			cout << " ";
		}
		
		cout << B[i];
	}
	cout << endl;

    return 0;
}



Measured memory_bytes: 18708
#include <stdio.h>
void print(char *str, char *text)
{
    char word[100];
    int x, y;
    int j;
    sscanf(text, "%s %d %d", word, &x, &y);
    for(j = x; j <= y; j++){
        printf("%c", *(str + j));
    }
    printf("\n");
}

void reverse(char *str, char *text)
{
    char word[20];
    char aaa[10];
    int x, y;
    //int j;
    sscanf(text, "%s %d %d", word, &x, &y);
    while(x != y){
        aaa[0] = *(str + x);
        *(str + x) = *(str + y);
        *(str + y) = aaa[0];
        if(x - y == 1 || y - x == 1)
            break;
        x++;
        y--;
    }
}

void replace(char *str, char *text)
{
    char word[20];
    char vfx[1001];
    int x, y, z;
    int j;
    sscanf(text, "%s %d %d %s", word, &x, &y, vfx);
    for(j = 0; x <= y; j++, x++){
        *(str + x) = vfx[j];
    }
}

int main(void){
    char str[1010];
    char number[111];
    char text[1111];
    int n;
    //int x, y, z;
    int j, q, k, a;
    fgets(str, 1010, stdin);
    fgets(number, 111, stdin);
    sscanf(number, "%d", &n);
    for(j = 0; j < n; j++){
        fgets(text, 1111, stdin);
        if(text[3] == 'n'){
            print(str, text);
        }else if(text[3] == 'e'){
            reverse(str, text);
        }else{
            replace(str, text);
        }
    }
    return 0;
}


Measured memory_bytes: 2144
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef pair<double, long long> pdl;

const long double pi = 3.141592653589793;

#define debug(x) cout << #x << " = " << (x) << endl;
#define rep(i, n) for(int i = 0;i < n;i++)
#define pb push_back
#define mp make_pair
#define mod 1000000007

ll solve(pll U, pll V) {
    if(U.first > V.first) swap(U, V);

    if(V.first > U.second) {
        return V.second-V.first+1+U.second-U.first+1;
    }

    return V.second-U.first+1;
}

int main() {
  std::ios::sync_with_stdio(false);
  //freopen("input.in","r",stdin);
  //freopen("output.out","w",stdout);
  ll A, B;cin>>A>>B;
  if(A == B) {
      cout<<1<<endl;
      return 0;
  }

  pll U, V;

  int nba = -1, nbb = -1;
  ll x = A;
  while(x != 0) {
      x = x>>1;
      nba++;
  }

  x = B;
  while(x != 0) {
      x = x>>1;
      nbb++;
  }

  ll maxm = max(nba, nbb), r;
  //debug(maxm);

  for(r = maxm;r >= 0;r--) {
      if(((1LL<<r) & A) ^ ((1LL<<r) & B))  {
          A = ((1LL<<(r+1))-1) & A;
          B = ((1LL<<(r+1))-1) & B;
          break;
      }
  }

  //cout<<A<<" "<<B<<" "<<r<<endl;

  ll answer = (1LL<<r)-A;
  int k = -1;
  for(int i = r-1;i >= 0;i--) {
      if(1LL<<i & B) {
          k = i;break;
      }
  }

  U.first = (1LL<<r);
  U.second = (1LL<<r) + (1LL<<(k+1)) - 1;

  V.first = (1LL<<r) + A;
  V.second = (1LL<<(r+1)) - 1;

  cout<<answer+solve(U, V)<<endl;

  return 0;
}


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

int main()
{
  int n;
  cin >> n;
  vector<uint64_t> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(begin(a), end(a), greater());
  uint64_t ans = a[0];
  for (int i = 1; i < n - 1; i++) {
    ans += a[(i + 1) / 2];
  }
  cout << ans << endl;
}


Measured memory_bytes: 4852
#pragma region noncode
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll INF = 1'010'000'000'000'000'017LL;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define SORT(v) sort(all(v))
#define TROS(v) sort(all(v), std::greater<Type>());
#pragma endregion

int main() {
    // template
    string s;cin>>s;
    if(s[0]=='R' && s[1]=='R' && s[2]=='R') cout<<3;
    else if((s[0]=='R' && s[1]=='R') || (s[1]=='R' && s[2]=='R')) cout<<2;
    else if(s[0]=='S' && s[1]=='S' && s[2]=='S') cout<<0;
    else cout<<1;
}


Measured memory_bytes: 3596
#define _USE_MATH_DEFINES
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<iomanip>
#include<cassert>
#include<functional>

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

	int hight;
	int width;
	int counter = 0;
	std::string current_str;//その時見ている行
	std::string current_str2;


	//入力
	std::cin >> hight >> width;
	std::vector<std::string> input(hight);
	for (int i = 0; i < hight; i++){
		std::cin >> input[i];
	}

	//行の消去
	for (int i = 0; i < hight; i++){
		current_str = input[i];//見ている行を更新
		counter = 0;//counter初期化

		for (int j = 0; j < width; j++){
			if (current_str[j] == '.'){
				counter++;
			}
		}

		if (counter == width){//input[i]が全部'.'だったら
			for (int k = i; k < hight - 1; k++){//今見ている行以降を更新（移動）
				input[k] = input[k + 1];
			}
			hight--;//高さを減らす
			i--;//移動したからもう一度同じ行を見る
		}
	}

	//列の消去
	for (int i = 0; i < width; i++){
		current_str = input[0];//1行目で'.'のある列のみ調べればよい
		counter = 0;

		if (current_str[i] == '.'){
			counter++;
			for (int j = 1; j < hight; j++){
				current_str2 = input[j];
				if (current_str2[i] == '.'){
					counter++;
				}
			}
		}

		if (counter == hight){//i列目がすべて'.'のとき
			for (int j = 0; j < hight; j++){
				current_str2 = input[j];//行を取出し
				for (int k = i; k < width - 1; k++){
					current_str2[k] = current_str2[k + 1];//移動
				}
				input[j] = current_str2;//更新（元に戻す）
			}

			width--;
			i--;
		}
	}

	for (int i = 0; i < hight; i++){
		current_str = input[i];
		for (int j = 0; j < width; j++){
			std::cout << current_str[j];
		}
		std::cout << '\n';
	}

	return 0;
}

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

for i in range(N):
    A = int(input())
    if i == 0:
        top_val = A
        top_i = 0
    elif i == 1:
        if top_val < A:
            second_val = top_val
            second_i = top_i
            top_val = A
            top_i = i
        else:
            second_val = A
            second_i = i
    else:
        if top_val < A:
            second_val = top_val
            second_i = top_i
            top_val = A
            top_i = i
        elif second_val < A:
            second_val = A
            second_i = A

for i in range(N):
    if top_i == i:
        print(second_val)
    else:
        print(top_val)

Measured memory_bytes: 4540
#include <bits/stdc++.h>
using namespace std;
const int maxn = 6e5+5;
int n, m;
struct Tree {
    int ls, rs, val; 
}tre[maxn*40];
int idx = 0, root[maxn];
int build(int l, int r) {
    int nod = ++idx;
    tre[nod].val = 0;
    if (l == r) return nod;
    int mid = (l + r) >> 1;
    tre[nod].ls = build(l, mid);
    tre[nod].rs = build(mid+1, r);
    return nod;
}
int update(int pre, int l, int r, int pos, int v) {
    int nod = ++idx;
    tre[nod] = tre[pre]; tre[nod].val += v;
    if (l == r) return nod;
    int mid = (l + r) >> 1;
    if (pos <= mid) tre[nod].ls = update(tre[pre].ls, l, mid, pos, v);
    else tre[nod].rs = update(tre[pre].rs, mid+1, r, pos, v);
    return nod;
}
int query(int id, int l, int r, int pos) {
    if (l == r) return tre[id].val;
    int mid = (l + r) >> 1;
    if (pos <= mid) {
        return tre[tre[id].rs].val + query(tre[id].ls, l, mid, pos);
    }
    else return query(tre[id].rs, mid+1, r, pos);
}
int a[maxn], vis[maxn*40];
int main() {
    scanf("%d%d", &n, &m);;
    for (int i = 1 ; i <= n ; i ++) {
        scanf("%d", a+i);
    }
    root[0] = build(1, n);   
    for (int i = 1 ; i <= n ; i ++) {
        if (!vis[a[i]])
            root[i] = update(root[i-1], 1, n, i, 1);
        else {
            int t = update(root[i-1], 1, n, vis[a[i]], -1);
            root[i] = update(t, 1, n, i, 1);
        }
        vis[a[i]] = i;
    }
    while (m--) {
        int l, r; scanf("%d%d", &l, &r);
        int tmp = query(root[r], 1, n, l);
        printf("%d\n", tmp);
    }
}

Measured memory_bytes: 252968
import java.util.*;
public class Main {
    public static void main(String args[]) {
		Scanner s = new Scanner(System.in);
		int N,K;
      	N = s.nextInt();
      	K = s.nextInt();
		
      findNumberOfDigits(N,K);

    }
  
  static void findNumberOfDigits(long n, int base) 
    { 
          
        // Calculating log using base changing 
        // property and then taking it  
        // floor and then adding 1. 
        int dig = (int)(	Math.floor( Math.log(n) / Math.log(base)	)  + 1);  
          
          
        // printing output 
        System.out.print(dig); 
    } 
  
}

Measured memory_bytes: 21844
fun longList() = readLine()?.split(" ")?.map(String::toLong) ?: TODO()
tailrec fun gcd(a: Long, b: Long): Long {
    return if (b == 0L) {
        a
    } else {
        gcd(b, a % b)
    }
}

fun main(args: Array<String>) {
    val (n, k) = longList()
    val a = longList()
    var g = a.first()
    val max = a.max()!!
    if (max < k) {
        println("IMPOSSIBLE")
        return
    }
    1.until(n.toInt()).forEach {
        g = gcd(g, a[it])
    }
    if (k % g == 0L) {
        println("POSSIBLE")
    } else {
        println("IMPOSSIBLE")
    }
}

Measured memory_bytes: 52936
#include <iostream>
#include <set>
#include <algorithm>

#define DEBUG(x) cout << #x << ": " << x << endl;
#define MOD 1000000007

using namespace std;

int main() {
  int n, an, bn, cn;
  cin >> n;
  set<int> A;
  set<int> B;
  set<int> C;

  cin >> an;
  for (int i = 0; i < an; i++) {
    int t;
    cin >> t;
    A.insert(t);
  }

  cin >> bn;
  for (int i = 0; i < bn; i++) {
    int t;
    cin >> t;
    B.insert(t);
  }

  cin >> cn;
  for (int i = 0; i < cn; i++) {
    int t;
    cin >> t;
    C.insert(t);
  }

  set<int> AiB;
  set_intersection(A.begin(), A.end(),
                  B.begin(), B.end(),
                  inserter(AiB, AiB.end()));
  set<int> AiBiC;
  set_intersection(AiB.begin(), AiB.end(),
                  C.begin(), C.end(),
                  inserter(AiBiC, AiBiC.end()));
  set<int> CdA;
  std::set_difference(C.begin(), C.end(),
                      A.begin(), A.end(),
                      inserter(CdA, CdA.end()));
  
  set<int> R;
  set_union(begin(AiBiC), end(AiBiC),
                 begin(CdA), end(CdA),
                 inserter(R, end(R)));


  cout << R.size() << endl;
}

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

int main(){
	int n;
	cin >> n;
	for(int i=0;i<n;i++){
		int r[3];
		cin >> r[0] >> r[1] >> r[2];
		sort(r, r+3);
		if(r[0]*r[0]+r[1]*r[1]==r[2]*r[2]){
			cout << "YES" << endl;
		}else{
			cout << "NO" << endl;
		}

	}
}

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

int main()
{
    int N;
    cin >> N;
    if ((N / 10) % 111 == 0 || (N % 1000) % 111 == 0)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 3652