akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <string>
#include <thread>
#include <random>
#include <deque>
#include <queue>
using namespace std;
using ll = long long;
using ull = unsigned long long;
int main() {
	int x[32] = { 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51 };
	int k;
	cin >> k;
	cout << x[k - 1] << endl;
	return 0;
}


Measured memory_bytes: 256
#!/usr/bin/python3
# -*- coding: utf-8 -*-
n = int(input())
S = input()
# alpha2num = lambda c: ord(c) - ord('A') + 1
moji_dict = {'A':1, 'B':2, 'C':3, 'D':4, 'E':5, 'F':6, 'G':7, 'H':8, 'I':9, 'J':10, 'K':11, 'L':12, 'M':13, 'N':14, 'O':15, 'P':16, 'Q':17, 'R':18, 'S':19, 'T':20, 'U':21, 'V':22, 'W':23, 'X':24, 'Y':25, 'Z':26}
num_dict = {1:'A', 2:'B', 3:'C', 4:'D', 5:'E', 6:'F', 7:'G', 8:'H', 9:'I', 10:'J', 11:'K', 12:'L', 13:'M', 14:'N', 15:'O', 16:'P', 17:'Q', 18:'R', 19:'S', 20:'T', 21:'U', 22:'V', 23:'W', 24:'X', 25:'Y', 26:'Z'}
for s in S:
    # print("'" + s + "'" + ":" + str(alpha2num(s)), end = ", ")
    # print(str(alpha2num(s)) + ":" + "'" + s + "'", end = ", ")
    res = moji_dict[s] + n
    if res > 26:
        print(num_dict[res - 26],end="")
    else:
        print(num_dict[res],end="")

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

int main()
{
  int N, R;
  cin >> N >> R;

  int I;
  if (N >= 10)
  {
    I = R;
  }

  else
  {
    I = R + 100 * (10 - N);
  }

  cout << I << endl;
}

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

int adj[101][101],d[101],f[101], n;

int step;
void dfs(int start){
	stack<int> S;
	S.push(start);

	++step;
	d[start]=step;

	while(S.size()){
		int u=S.top();

		int v=0;
		for(int i=1;i<=n;i++){
			if(adj[u][i]==1 && d[i]==0){
				v=i;	break;
			}
		}

		++step;
		if(v==0){
			f[u]=step;
			S.pop();
		}else{
			d[v]=step;
			S.push(v);
		}
	}
}

int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		int u,k;	cin>>u>>k;
		for(int j=0;j<k;j++){
			int v;	cin>>v;
			adj[u][v]=1;
		}
	}

	step=0;
	for(int i=1;i<=n;i++){
		if(d[i]==0)dfs(i);
	}

	for(int i=1;i<=n;i++){
		printf("%d %d %d\n",i,d[i],f[i]);
	}

	return 0;
}



Measured memory_bytes: 3232
#include<stdio.h>

int main(){
	double f;
	int a,b,d,r;
	scanf("%d %d",&a, &b);
	
	d = (int)a / b;
	r = (int)a % b;
	f =(double)a / b;
	
	printf("%d %d %f\n",d,r,f);

	return 0;
}

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

int main() {
  
  int N, K;
  cin >> N >> K;
  
  long long h[N];
  for (int i = 0; i < N; i++) {
    cin >> h[i];
  }
  
  sort(h, h+N);
  
  long long totaldiff = 1e15;
  for (int i = 0; i < N-K+1; i++) {
    totaldiff = min(totaldiff,h[i+K-1]-h[i]);
  }
  
  cout << totaldiff << endl;
  
  return 0;
}

Measured memory_bytes: 1024
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = 0
amax = 0
samax = 0

for i in range(n):
    if samax + a[i]<=k:
        amax += 1
        samax += a[i]
    else:
        break
        
book = amax
ans = book
samax = sum(a[0:amax])
sbmax = 0

for j in range(m):
    sbmax += b[j]
    while samax + sbmax > k and amax >= 1:
        amax -= 1
        samax = samax - a[amax]
        book -= 1
    if samax + sbmax <= k:
        book += 1
        if book > ans:
            ans = book
    else:
        break

print(ans)

Measured memory_bytes: 42276
def main():
  N = int(input())
  A = list(map(int, input().split()))

  A.sort()

  m = 10 ** 18
  ans = A[0];

  if(A[0] == 0):
    ans = 0;
  else:
    for i in range(1, N):
      ans *= A[i]

      if(ans > m):
        ans = -1
        break

  print(ans)

if __name__ == "__main__":
  main()

Measured memory_bytes: 84816
#include <iostream>
using namespace std;
const int n = 12,m = 12;
char map[n][m+1];
void dfs(int x,int y){
	int dx[] = {-1,0,0,1},dy[] = {0,-1,1,0};
	map[x][y] = '0';
	for(int i=0;i<4;i++){
		int nx = x+dx[i],ny = y+dy[i];
		if (nx > -1 && nx < n && ny > -1 && ny < m && map[nx][ny] == '1') dfs(nx,ny);
	}
}
int main(){
	int count;
	while(1){
		count = 0;
		for(int i=0;i<n;i++){
			cin >> map[i];
		}
		if (cin.eof()) break;
		for(int i=0;i<n;i++){
			for(int j=0;j<m;j++){
				if(map[i][j] == '1'){
					dfs(i,j);
					count++;
				}
			}
		}
		cout << count << endl;
	}
	return 0;
}

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

int main() {
    string s;
    cin >> s;
    int n = s.size();
    int count = 0;
    for(int i=0; i<n / 2; i++) {
        if(s[i] != s[n-i-1]) {
            count++;
        }
    }

    cout << count << endl;
}

Measured memory_bytes: 3580
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.StringTokenizer;

public class Main {
	
	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		
		final int N = sc.nextInt();
		
		for(int i = 1; i < 10000; i++){
			
			int count = 0;
			for(int j = 1; j <= i; j++){
				if(i % j == 0){
					count++;
				}
			}
			
			//System.out.println(i + " : " + count);
		
			if(count == N){
				System.out.println(i);
				break;
			}
		}
		
		
	}

	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;

		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}

		private void getLine() throws IOException {
			while (!hasNext()) {
				tok = new StringTokenizer(br.readLine());
			}
		}

		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}

		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}

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

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

		public void close() throws IOException {
			br.close();
		}
	}
}

Measured memory_bytes: 24508
;; C - Tax Increase

(defun solve (a b)
  "floor(x * 0.08) == a, floor(x * 0.1) == b である x.
   1 <= a <= b <= 100"
  (or (cdr (assoc (cons a b)
             (loop for x from 1 to (/ 100 8/100)
                   collect (cons (cons (floor (* x 8/100))
                                       (floor (* x 1/10))) x))
             :test #'equal))
      -1))

(let ((a (read))
      (b (read)))
  (princ (solve a b)))


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

#define FOR(i,a,b) for (int i = a; i < b; ++i)
#define REP(i,n) FOR(i,0,n)

int N;
vector<int> d;

int main() {
  scanf("%d", &N);

  int buf;
  int count = 0;
  REP(i,N) {
    scanf("%d", &buf);
    if (find(d.begin(), d.end(), buf) == d.end()) {
      ++count;
      d.push_back(buf);
    }
  }

  printf("%d\n", count);
  return 0;
}

Measured memory_bytes: 256
import sys
def solve(X, Y, Z, V, E, A):
    dp = [[0.0] * 6001 for _ in range(Y + max(V) + 1)]
    dp[0][0] = 1.0
    for i in range(Y):
        for j in range(5001):
            if dp[i][j] <= 0.0:
                continue
            for k in V:
                t = i + k
                if t > Y:
                    dp[Y][j] += dp[i][j]/X
                elif E[t] == 1:
                    dp[min(Y, t+A[t])][j] += dp[i][j]/X
                else:
                    dp[t][max(0, j+A[t])] += dp[i][j]/X

    s = 0
    for i in range(5001):
        if dp[Y][i] <= 0.0:
            continue
        s += i * dp[Y][i]
    print(int(s))

while True:
    X, Y, Z = map(int, raw_input().split())
    if X | Y | Z == 0:
        sys.exit()
    V = map(int, raw_input().split())
    E = [0] * 100
    A = [0] * 100
    for _ in range(Z):
        n, e, a = map(int, raw_input().split())
        E[n] = e
        if e == 3:
            A[n] = -a
        else:
            A[n] = a
    solve(X, Y, Z, V, E, A)

Measured memory_bytes: 9652
#include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
#include<string>
#include<unordered_map>
#include<string.h>
#include<math.h>
using namespace std;
using ll = long long;
int main(){
    int M1, D1, M2, D2;
    cin >> M1 >> D1 >> M2 >> D2;
    if(M1 != M2)cout << 1;
    else cout << 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);(i)++)
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);(i)--)
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);(i)--)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; }return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; }return 0; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T> inline istream& operator>>(istream& input, vector<T>& v) { for (auto& elemnt : v)input >> elemnt; return input; }

int main() {
    init();
    
    int a, b, c;
    cin >> a >> b >> c;
    cout << a + b + c << "\n";
}


Measured memory_bytes: 3160
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
using namespace std;

int main()
{
    int n , max , min , sa;
    string s;
    cin >> n;
    while(n--){
        cin >> s;
        sort(s.begin() , s.end());
        min=atoi(s.c_str());
        reverse(s.begin() , s.end());
        max=atoi(s.c_str());
        sa=max-min;
        cout << sa << endl;
    }
	return 0;
}

Measured memory_bytes: 1228
import java.util.Scanner;

import static java.lang.System.in;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(in);
        double[][][] dp = new double[301][301][301];
        int n = scanner.nextInt();
        int[] arr = new int[n];
        int[] count = new int[4];
        for (int i = 0; i < n; i++) {
            arr[i] = scanner.nextInt();
            count[arr[i]]++;
        }
        System.out.println( solve(count[1],count[2],count[3],n,dp) );
    }
    private static double solve(int a,int b,int c,int n,double[][][] dp){
        if(a==0 && b==0 && c==0) return 0;
        if(a<0 || b<0 || c<0) return 0;
        if(dp[a][b][c]>0) return dp[a][b][c];
        double remaining = (a+b+c);
        double expVal = n + a*solve(a-1,b,c,n,dp) + b*solve(a+1,b-1,c,n,dp) + c*solve(a,b+1,c-1,n,dp);
        return dp[a][b][c] = expVal/remaining;
    }
}


Measured memory_bytes: 281332
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <algorithm>

#define REP(i, n) for (long long i = 0; i < (n); i++) 
#define ll long long

using namespace std;
//        tmp = stoi(S.substr(i,3));
int main(){

    ll N,M,K,p;


    cin >> N >> M;

    vector<int> res(M+1, 0);

    REP(i,N)
    {
        cin >> K;
        REP(j, K)
        {
            cin >> p;
            res[p]++;
        }
    }
    ll cnt = 0;
    REP(i,M+1)
    {
        if(res[i] == N)cnt++;
    }

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i,s,n)for(ll i=s;i<n;i++)

map<ll, ll> mp;
int main() {
	ll n; cin >> n;
	rep(i, 0, n) {
		ll a; cin >> a;
		mp[a]++;
	}

	ll ans = 0;
	for (map<ll, ll>::iterator it = mp.begin(); it != mp.end(); it++) {
		if (it->second & 1) ans++;
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,m=10000000,ans=0;
  cin >> N;
  for(int i=0; i<N; i++){
  	int a;
    cin >> a;
    if(a<m)ans++;
    m=min(a,m);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstring>
#include <cstdio>
#define INF 1e9
#define eps 1e-6
typedef long long ll;

char c[210];
int k, n, dp[110][20][5][2];

int dfs(int now, int las, int cnt, bool have0){
	//printf("%d %d %d %d\n", now, las, cnt, have0);
	if(now == n + 1)
		return cnt == k;
	if(cnt > k) return 0;
	if(dp[now][las][cnt][have0] >= 0 && !have0)
		return dp[now][las][cnt][have0];
	int maxx = have0 ? c[now] - '0' : 9, sum = 0;
	for(int i = 0; i <= maxx; i++)
		sum += dfs(now + 1, i, cnt + (i != 0), have0 && (i == maxx));
	return dp[now][las][cnt][have0] = sum;
}

int main(){

	memset(dp, -1, sizeof(dp));
	scanf("%s\n%d", c + 1, &k);
	n = strlen(c + 1);
	printf("%d\n", dfs(1, 0, 0, 1));

	return 0;
}


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

int main() {
  int A, B, M;
  cin >> A >> B >> M;
  vector<int> ai(A);
  for (int i=0; i<A; i++) cin >> ai.at(i);
  vector<int> bj(B);
  for (int j=0; j<B; j++) cin >> bj.at(j);
  vector<int> sum(M);

  int xk, yk, ck;
  for (int k=0; k<M; k++) {
  cin >> xk >> yk >> ck;
  sum.at(k) = ai.at(xk-1) + bj.at(yk-1) - ck;
  }
  sort(sum.begin(),sum.end());

  sort(ai.begin(),ai.end());
  sort(bj.begin(),bj.end());
  int sum_min=ai.at(0)+bj.at(0);

  cout << min(sum.at(0), sum_min) << endl;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using pii=pair<int,int>;
#define all(c) begin(c),end(c)
#define rall(c) rbegin(c),rend(c)
#define fore(x,c) for(auto &&x:c)
#define rep(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define rrep(i, a, n) for(int i=(int)(n-1);i>=a;--i)
#define sz(c) ((int)c.size())
#define contains(c,x) (c.find(x)!=end(c))
#define inseg(l,x,r) ((l)<=(x)&&(x)<(r))
#define dump(...)
#define pb push_back
#define _ 0
const signed INF_=1001001001; const long long INF=1001001001001001001LL;
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    for (auto i = begin(v); i != end(v); i++) os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    for (auto i = begin(v); i != end(v); i++) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T, class U> bool chmax(T &a,const U &b){return a<b?a=b,1:0;}
template<class T, class U> bool chmin(T &a,const U &b){return a>b?a=b,1:0;}
template <class T> void psum(T& c) {partial_sum(begin(c), end(c), begin(c));}
template<class T> using heap=priority_queue<T,vector<T>,greater<T>>;
struct before_main_function {
    before_main_function() {
        cin.tie(0); ios::sync_with_stdio(0);
        cout << setprecision(15) << fixed;
        // #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    int N, K;
    cin >> N >> K;
    string S;
    cin >> S;
    for (auto &x : S) {
        if (x == '0') x = 0;
        else x = 1;
    }
    if (count(all(S), 0) == N || count(all(S), 0) == 0) {
        cout << N << endl;
        return 0;
    }
    
    vector<int> L, R;
    if (S[0] == 0) {
        L.pb(0);
        R.pb(0);
    }
    rep(i, 0, N) {
        if (S[i] && (i == 0 || S[i - 1] != S[i])) {
            L.pb(i);
        }
        if (S[i] && (i == N - 1 || S[i] != S[i + 1])) {
            R.pb(i);
        }
    }
    if (S[N - 1] == 0) {
        L.pb(N - 1);
        R.pb(N - 1);
    }
    dump(L);
    dump(R);
    int l = 0, r = 0;
    while (r + 1 < sz(R) && r < K) {
        r++;
    }
    int ans = R[r] - L[l] + 1;
    dump(r, l, ans);
    while (1) {
        r++;
        l++;
        if (r >= sz(R) || l >= sz(L)) break;
        chmax(ans, R[r] - L[l] + 1);
    }
    cout << ans << endl;
}



Measured memory_bytes: 1372
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

int main(){

    ll N, x;
    cin >> N >> x;
    vector<ll>a(N);
    for(int i = 0; i < N; i++)cin >> a[i];
    sort(a.begin(), a.end());
    ll ans = 0;
    for(int i = 0; i < N; i++){
        if(i+1==N && x != a[i])break;
        if(x >= a[i]){
            x -=a[i];
            ans++;
        }
        else break;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#import sys
MOD = 10 ** 9 + 7
#input = sys.stdin.readline
import math
import itertools

#import bisect

def sosuhante(n):
    for k in range(2, int(math.sqrt(n))+1):
        if n% k ==0:
            return False
    return True
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def kingaku(a,b,n):
    keta=len(str(n))
    return a*n+b*keta

def my_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default


def main():
#    h,w,a,b = map(int, input().split())
#    c = [[0 for j in range(n)] for i in range(n)]

    n = int(input())
    xy = [[] for i in range(n)]
    for i in range(n):
        a=int(input())
        for j in range(a):
            xy[i].append(list(map(int,input().split())))
    b=[-1 for i in range(n)]
    count=0
    for c in itertools.product(range(2),repeat=n):
        k=0
        for i in range(n):
            if c[i]==1 and k==0:
                for j in xy[i]:
                    if c[j[0]-1]!=j[1]:
                        k=1
                        break
        if k==0:
            count=max(count,sum(c))




    print(count)




#  print(c)




            #    print(n,kingaku(a,b,x))

if __name__ == "__main__":
    main()

Measured memory_bytes: 3188
k=int(input())
flag=1
ans=1
r=7%k
p=r
if k%2==0:
    print(-1)
    exit()
if k%5==0:
    print(-1)
    exit()
while flag!=0:
    if r%k==0:
        flag=0
    else:
        ans+=1
        p=(p*10)%k
        r+=p
print(ans)


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

int main(){
    int N,M,Q,data[505][505];
    cin>>N>>M>>Q;
    for(int i=0;i<M;i++){
        int x,y;
        cin>>x>>y;
        data[x][y]++;
    }

    for(int i=1;i<=N;i++){
        for(int j=1;j<=N;j++) data[i][j]+=data[i-1][j];
    }
    for(int i=1;i<=N;i++){
        for(int j=1;j<=N;j++) data[i][j]+=data[i][j-1];
    }

    for(int i=0;i<Q;i++){
        int L,R;
        cin>>L>>R;
        cout<<data[R][R]+data[L-1][L-1]-data[R][L-1]-data[L-1][R]<<endl;
    }

}

Measured memory_bytes: 1920
#include <iostream>

using namespace std;

int main()
{
	unsigned long long N,A,B;
  	cin>>N>>A>>B;
  
  unsigned long long syuuki = A+B;
  unsigned long long kai = N/syuuki;
  unsigned long long sum = 0;
  sum += kai*A;
  unsigned long long amari = N - kai*syuuki;
  
  if(amari > A)
    sum+=A;
  else
    sum+=amari;
  
  cout<<sum<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
using namespace std;
int X, Y, A, i, j;
int main() {
	while (true) {
		cin >> A; if (A == 0) { break; }
		for (i = A; i >= 2; i--) { for (j = 2; j <= sqrt(i); j++) { if (i%j == 0) { goto E; } }X = i; goto F; E:; }
	F:; for (i = A; i < 99999999; i++) { for (j = 2; j <= sqrt(i); j++) { if (i%j == 0) { goto G; } }Y = i; goto H; G:; }
	H:; cout << Y - X << endl;
	}
}

Measured memory_bytes: 1160
object Main extends App {
  val N = Scanner.nextInt
  val K = Scanner.nextLong
  val A = (0 until N).map(i => (Scanner.nextInt, Scanner.nextLong)).sortBy(t => t._1)
  def go(list: Seq[(Int, Long)], acc: Long = 0): Int = list match {
    case head +: tail =>
      if (acc + head._2 >= K) head._1
      else go(tail, acc + head._2)
  }
  println(go(A))
}

object Scanner {
  private val buf = new Array[Byte](1024)
  private var ptr = 0
  private var len = 0

  @inline private def isPrintableChar(c: Int): Boolean = 33 <= c && c <= 126
  @inline private def hasNextByte: Boolean = if (ptr >= len) {
      ptr = 0
      len = System.in.read(buf)
      len > 0
    } else {
      true
    }
  @inline private def hasNext: Boolean = {
    while (hasNextByte && !isPrintableChar(buf(ptr))) ptr += 1
    hasNextByte
  }
  @inline private def readByte: Byte = {
    if (hasNextByte) {
      val res = buf(ptr)
      ptr += 1
      res
    } else {
      -1
    }
  }

  def next: String = {
    if(!hasNext) ???
    val sb = new StringBuilder
    var b = readByte
    while (isPrintableChar(b)) {
      sb.append(b.toChar)
      b = readByte
    }
    sb.toString
  }
  def nextInt: Int = {
    val n = nextLong
    if (n < Int.MinValue || Int.MaxValue < n) ???
    n.toInt
  }
  def nextLong: Long = {
    if(!hasNext) ???
    var minus = false
    var b = readByte
    if (b == '-') {
      minus = true
      b = readByte
    }
    def go (b: Byte, n: Long = 0): Long =
      if ('0' <= b && b <= '9') go(readByte, n * 10 + b - '0')
      else if (minus) -n
      else n
    go(b)
  }
  def nextDouble: Double = next.toDouble
}

Measured memory_bytes: 72244
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	
	public static void main(String[] args) throws java.lang.Exception {
	      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	      String input[] = br.readLine().split(" ");
	      long a = Long.parseLong(input[0]);
	      long b = Long.parseLong(input[1]);
	      
	      if(a == 1 || b ==1) {
	    	  System.out.println("1");
	    	  return;
	      }
	      else {
	    	  long res = (a * b + 1)/2;
	    	  System.out.println(res);
	      }
	}

}


Measured memory_bytes: 22356
#include <bits/stdc++.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;

int main() {
	
	int a, b, c, d, e, f;
	cin >> a >> b >> c >> d >> e >> f;
	set<int> mizu, sato;
	
	for(int i = 0; a * i * 100 <= f; i++){
		for(int j = 0; b * j * 100 <= f - a * i * 100; j++){
			if(i == 0 && j == 0) continue;
			int tmp = a * i * 100 + b * j * 100;
			mizu.insert(tmp);
		}
	}
	for(int i = 0; c * i <= f; i++){
		for(int j = 0; d * j <= f - c * i; j++){
			if(i == 0 && j == 0) continue;
			int tmp = c * i + d * j;
			sato.insert(tmp);
		}
	}
	double mx = 0.0;
	int ans_m = *mizu.begin(), ans_s = 0;
	for(auto m: mizu){
		for(auto s: sato){
			if(m + s > f) continue;
			if(s > m / 100 * e) continue;
			double nodo = s / (double) (m + s);
			if(nodo > mx){
				mx = nodo;
				ans_m = m;
				ans_s = s;
			}
		}
	}
	cout << (ans_m + ans_s) << " " << ans_s << endl;
	return 0;
}

Measured memory_bytes: 384
#include <iostream>

using namespace std;

main(int argc, char const *argv[])
{
    int a, b, ans;
    scanf("%d %d",&a, &b);
    ans = a + b;
    if(ans >= 24){
        ans -= 24;
        printf("%d\n", ans);
        return 0;
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {
	public static void main(String[] args) {
		BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder output = new StringBuilder();
		int c;
		try {
			while ((c = buf.read()) != (int)'\n') {
				if (Character.isUpperCase((char) c)) {
					output.append(Character.toLowerCase((char) c));
				} else if (Character.isLowerCase((char) c)) {
					output.append(Character.toUpperCase((char) c));
				} else {
					output.append((char) c);
				}
			}
			System.out.println(output);
		} catch (IOException e) {
			System.out.println(e);
		}
	}
}

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

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
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; }
typedef long long ll;

const long long INF = 1LL << 60;

int main()
{
    int A, B, K;
    cin >> A >> B >> K;

    for (int i = min(A, B); i > 0; i--) {
        if (A % i == 0 && B % i == 0) K--;
        if (K == 0) {
            cout << i << endl;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using static System.Console;
using static System.Convert;
using static System.Math;
using static Extentions;

class IO
{
    int idx;
    string[] input = In.ReadToEnd().Split(new[] { " ", "\n", "\r" },
        StringSplitOptions.RemoveEmptyEntries);

    T Get<T>(Func<string, T> parser) => parser(input[idx++]);

    public string S => Get(s => s);
    public char C => Get(char.Parse);
    public int I => Get(int.Parse);
    public long L => Get(long.Parse);
    public double F => Get(double.Parse);
    public decimal D => Get(decimal.Parse);
    public BigInteger B => Get(BigInteger.Parse);

    T[] Gets<T>(int n, Func<string, T> parser)
        => input.Skip((idx += n) - n).Take(n).Select(parser).ToArray();

    public string[] Ss(int n) => Gets(n, s => s);
    public char[] Cs(int n) => Gets(n, char.Parse);
    public int[] Is(int n) => Gets(n, int.Parse);
    public long[] Ls(int n) => Gets(n, long.Parse);
    public double[] Fs(int n) => Gets(n, double.Parse);
    public decimal[] Ds(int n) => Gets(n, decimal.Parse);
    public BigInteger[] Bs(int n) => Gets(n, BigInteger.Parse);

    public void Write<T>(params T[] xs) => WriteLine(string.Join(" ", xs));
    public void Write(params object[] xs) => WriteLine(string.Join(" ", xs));
}

static class Extentions
{
}

static class Program
{
    public static void Main()
    {
        var sw = new StreamWriter(OpenStandardOutput()) { NewLine = "\n" };
#if DEBUG
        sw.AutoFlush = true;
#else
        sw.AutoFlush = false;
#endif
        SetOut(sw);
        Solve(new IO());
        Out.Flush();
    }

    static void Solve(IO io)
    {
        var n = io.I;
        var d = io.Is(n);
        var m = io.I;
        var t = io.Is(n);

        var ddic = new Dictionary<int, int>();
        foreach (var x in d) if (ddic.ContainsKey(x)) ddic[x]++; else ddic[x] = 1;

        var tdic = new Dictionary<int, int>();
        foreach (var x in t) if (tdic.ContainsKey(x)) tdic[x]++; else tdic[x] = 1;

        var ans = true;

        foreach (var x in tdic)
        {
            int y;
            if (ddic.TryGetValue(x.Key, out y)) { if (y < x.Value) { ans = false; break; } }
            else { ans = false; break; }
        }

        io.Write(ans ? "YES" : "NO");
    }
}

Measured memory_bytes: 57248
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <limits>
#include <cmath>
using namespace std;
using ll = long long;
const ll INF = 1<<30;
const ll MOD = (ll)1e9 + 7;
const ll MAX_N = (ll)1e5 + 5;
#define debug(x) cout << #x << ": " << x << endl

signed main(void)
{
    ll n; cin >> n;
    vector<vector<pair<ll, ll>>> v(n);
    for(ll i = 0; i < n; i++)
    {
        ll m; cin >> m;
        for(ll j = 0; j < m; j++)
        {
            ll x, y; cin >> x >> y;
            x--;
            v[i].push_back(make_pair(x, y));
        }
    }
    ll ans = 0;
    for(ll bit = 0; bit < (1<<n); bit++)
    {
        ll flag = bit;
        bool ok = true;
        for(ll i = 0; i < n; i++)
        {
            if(not flag & (1<<i)) continue;
            for(ll j = 0; j < v[i].size(); j++)
            {
                if(flag & (1<<i))
                {
                    if(v[i][j].second == 0)
                    {
                        flag &= ~(1<<v[i][j].first);
                    }
                    else
                    {
                        flag |= (1<<v[i][j].first);
                    }
                }
                if(bit != flag) ok = false;
            }
        }
        if(ok)
        {
            ll cnt = __builtin_popcount(bit);
            ans = max(ans, cnt);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Scanner;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        HashMap<Integer,Integer> map = new HashMap<>();
        for(int i = 0; i < n; i++){
            int cur = sc.nextInt();
            if(map.containsKey(cur)){
                map.put(cur, map.get(cur) + 1);
            }else{
                map.put(cur, 1);
            }
        }
        ArrayList<Integer> list = new ArrayList<>(map.values());
        Collections.sort(list);
        int diversity = list.size();
        int sum = 0;
        for(int i = 0; i < diversity - k; i++){
            sum += list.get(i);
        }
        System.out.println(sum);
    }
}

Measured memory_bytes: 101288
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); ++i)
#define rep2(i,n) for(int i=1; i<=(n); ++i)
#define all(x) (x).begin(),(x).end()
#define sort_u(x) sort((x).begin(),(x).end())
#define sort_d(x) sort((x).begin(),(x).end(), greater<int>())
#define pb push_back
#define INF ((1LL<<62)-(1LL<<31))  // 浮動小数点型
#define bit(n,m)(((n)>>(m))&1)  // nのmビット目が1
#define MOD 1000000007
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<P>>;

int main() {
    int n; cin >> n;
    Graph p(n);
    rep(i,n){
        int a; cin >> a;
        rep(j, a){
            int x, y; cin >> x >> y;
            x--;
            p[i].pb(P(x,y));
        }
    }
    int ans = 0;
    rep(s, 1<<n){
        vector<int> flg(n, -1);
        bool flg2 = false;
        int a = 0;
        rep(i,n){
            if(bit(s,i)){
                if(flg[i] == -1) flg[i] = 1;
                if(flg[i] != 1) {
                    flg2 = true;
                    break;
                }
                a++;
                for(auto q : p[i]){
                    if(flg[q.first] == -1) flg[q.first] = q.second;
                    if(flg[q.first] != q.second){
                        flg2 = true;
                        break;
                    }
                }
            }else{
                if(flg[i] == -1) flg[i] = 0;
                if(flg[i] != 0) {
                    flg2 = true;
                    break;
                }
                // for(auto q : p[i]){
                //     int q2 = 1;
                //     if(q.second == 1) q2 = 0;
                //     if(flg[q.first] == -1) flg[q.first] = q2;
                //     if(flg[q.first] == q.second){
                //         flg2 = true;
                //         break;
                //     }
                // }
            }
            if(flg2) break;
        }
        if(!flg2) ans = max(a,ans);
    }
    cout << ans << endl;
    
}

/*
g++ c.cpp
./a.out


oj d
g++ c.cpp
oj t
*/


Measured memory_bytes: 3640
#include<cstdio> 
#include<algorithm>
#include<cstring>
#include<cmath>
#include<map>
using namespace std;
#define fo(i,j,k) for(i=j;i<=k;i++)
#define fd(i,j,k) for(i=j;i>=k;i--)
#define cmax(a,b) (a=(a>b)?a:b)
#define cmin(a,b) (a=(a<b)?a:b)
typedef long long ll;
typedef double db;
const int N=2e5+5;
int b[N],nxt[N],fst[N],tt,pd[N],vis[N],du[N],n,a[N],i,j;
void cr(int x,int y)
{
	tt++;
	du[y]++;
	b[tt]=y;
	nxt[tt]=fst[x];
	fst[x]=tt;
}
int gcd(int a,int b)
{
	if (!b) return a;
	return gcd(b,a%b);
}
void dfs(int x)
{
	pd[x]=1;
	int i;
	fo(i,1,n)
	if (!pd[i]&&gcd(a[i],a[x])>1)
	{
		cr(x,i);
		dfs(i);
	}
}
int main()
{
	scanf("%d",&n);
	fo(i,1,n) scanf("%d",a+i);
	sort(a+1,a+1+n);
	fo(i,1,n) if (!pd[i])
		dfs(i);
	fo(i,1,n)
	{
		fd(j,n,1)
		if (!du[j]&&!vis[j])
		{
			printf("%d ",a[j]);
			vis[j]=1;
			for(int p=fst[j];p;p=nxt[p]) du[b[p]]--;
			break;
		}
	}
}

Measured memory_bytes: 2304
#include <iostream>
#include <string>

using namespace std;

int main(void)
{
    // 入力
    string input;
    cin >> input;
    // 判定用のフラグ
    bool is_good = true;
    // 隣り合う文字を比較して判定
    int i;
    for (i = 0; i < 3; i++)
    {
        if (input[i] == input[i + 1])
        {
            is_good = false;
        }
    }
    // 結果の出力
    if (is_good == true)
    {
        cout << "Good" << endl;
    }
    else
    {
        cout << "Bad" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		String line = sc.nextLine();
		String[] abc = line.split(" ");
		int a = Integer.parseInt(abc[0]);
		int b = Integer.parseInt(abc[1]);
		int c = Integer.parseInt(abc[2]);

		if (a < b && b < c) {
			System.out.println("Yes");

		} else {
			System.out.println("No");

		}

	}

}



Measured memory_bytes: 26260
#include <bits/stdc++.h>
using namespace std;
double arr[3010], dp[3010][3010], n;
double fun(long long x, long long y)
{
    // cout << x << endl;
    if (y > x)
        return 0;
    if (x < 0 || y < 0)
        return 0;
    if (x == 0 && y == 0)
        return 1;
    if (dp[x][y] > -1)
        return dp[x][y];
    return dp[x][y] = arr[x] * fun(x - 1, y - 1) + (1 - arr[x]) * fun(x - 1, y);
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    double ans;
    long long x, y;
    cout.precision(15);
    cin >> n;
    for (x = 1; x <= n; x++)
        cin >> arr[x];
    for (x = 0; x < 3010; x++)
        for (y = 0; y < 3010; y++)
            dp[x][y] = -100.1;
    ans = 0;
    for (x = n / 2 + 1; x <= n; x++)
    {
        ans = ans + fun(n, x);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 71296
N, M = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(N)]

ab.sort()

s = 0
ans = 0
for x, y in ab:
    if s+y>=M:
        ans += (M-s)*x
        break
    else:
        s += y
        ans += x*y
print(ans)

Measured memory_bytes: 27760
/*
  Contest 097
  A - Colorful Transceivers
  Rakesh Kumar --> 23/09/2020
 */

#include <bits/stdc++.h>

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

    int a = 0, b = 0, c = 0, d = 0;
    std::cin >> a >> b >> c >> d;
    if ((std::abs(a - b) <= d && std::abs(b - c) <= d) ||
        std::abs(a -c ) <= d)
        std::cout << "Yes" << std::endl;
    else
        std::cout << "No" << std::endl;

    return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
#include <algorithm>
#include <array>
#include <bitset>
#include <chrono>
#include <climits>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <random>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
constexpr ll MOD = 1000000007;

uint N;
vector<int> sum, zero;
vector<int> get_zero(const vector<int>& l)
{
	vector<int> z(l.size() - 1);
	for (uint i = 0; i + 1 < l.size(); i++) z[i] = zero[l[i + 1]] - zero[l[i]];
	return z;
}
map<int, vector<int>> indexes(const vector<int>& x)
{
	map<int, vector<int>> dic;
	for (uint i = 0; i < x.size(); i++) dic[x[i]].emplace_back(i);
	return dic;
}
vector<ll> calc(const vector<int>& zs)
{
	auto L = zs.size();
	vector<ll> dp(L + 1, 1);
	ll sum = 1;
	for (uint j = 0; j < L; j++)
	{
		dp[j + 1] = (dp[j] + zs[j] * sum % MOD) % MOD;
		sum = (sum + dp[j + 1]) % MOD;
	}
	return dp;
}
ll pow(ll a, ll b, ll mod)
{
	ll p = 1, x = a;
	while (b > 0)
	{
		if ((b & 1L) == 1L) p = p * x % mod;
		b >>= 1;
		x = x * x % mod;
	}
	return p;
}

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> N;
	vector<int> A(N);
	for (uint i = 0; i < N; i++) cin >> A[i];
	sum = vector<int>(N + 1, 0);
	for (uint i = 0; i < N; i++) sum[i + 1] = sum[i] ^ A[i];
	zero = vector<int>(N + 2, 0);
	for (uint i = 0; i <= N; i++) zero[i + 1] = zero[i] + (sum[i] == 0 ? 1 : 0);
	auto dic = indexes(sum);
	if (sum[N]) cout << calc(get_zero(dic[sum[N]])).back() << endl;
	else
	{
		ll ans = pow(2, zero[N + 1] - 2, MOD);
		for (auto&& x: dic) if (x.first) for (auto v : calc(get_zero(x.second))) ans += v;
		cout << ans % MOD << endl;
	}
	cout << flush;
	return 0;
}


Measured memory_bytes: 38132
n = int(input())

dic = {}
dic["AC"] = 0
dic["WA"] = 0
dic["TLE"] = 0
dic["RE"] = 0

for e in range(n):
	entrada = input()
	if entrada == "AC":
		dic["AC"] += 1
	elif entrada == "WA":
		dic["WA"] += 1
	elif entrada == "TLE":
		dic["TLE"] += 1
	elif entrada == "RE":
		dic["RE"] += 1
		
print("AC x %d"% dic["AC"])
print("WA x %d"% dic["WA"])
print("TLE x %d"% dic["TLE"])
print("RE x %d"% dic["RE"])


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


#define _USE_MATH_DEFINES_
#define ll long long
#define ld long double
#define Accepted 0
#define pb push_back
#define mp make_pair
#define sz(x) (int)(x.size())
#define every(x) x.begin(),x.end()
#define F first
#define S second
#define For(i,x,y)  for (ll i = x; i <= y; i ++) 
#define FOr(i,x,y)  for (ll i = x; i >= y; i --)
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0)
// ROAD to...                                                                                                                                                                                                                Red

using namespace std;

inline bool isvowel (char c) {
	c = tolower(c);
    if (c == 'a' || c == 'e' || c == 'i' || c == 'y' || c == 'o' || c == 'u') return 1;
    return 0;
}

const double eps = 0.000001;
const ld pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const ll MOD = 1e18 + 9;
const ll INF = 1e18 + 123;
const int inf = 2e9 + 11;
const int mxn = 1e6 + 9;
const int N = 6e5 + 123;                                          
const int M = 22;
const int pri = 997;
const int Magic = 2101;

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

int main () {
    cin >> n;
    For (i, 1, n) {
        cin >> a[i];
    }
    int ans = 0;
    For (i, 1, n) {
        int j = i;
        ++ ans;
        while (j < n) {
            int l = j;
            while (j + 1 <= n && a[j + 1] == a[j]) j ++;
            while (j + 1 <= n && a[j] < a[j + 1]) j ++;
            if (l == j) break;
        }
        
        int cur = j - i + 1;
        j = i;
        while (j < n) {
            int l = j;
            while (j + 1 <= n && a[j + 1] == a[j]) j ++;
            while (j + 1 <= n && a[j] > a[j + 1]) j ++;
            if (j == l) break;
        }
        if (j - i + 1 > cur) i = j;
        else i += (cur - 1);
    }
    cout << ans << '\n';
	return Accepted;
}

// Coded By OB

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define endl '\n'
#define N 1000001
#define mod 1e9+7
using namespace std;
typedef long long ll;
double p[3000];
double dp[3000][3000];
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll n;
	cin>>n;
	for(ll i=0;i<n;i++){
	    cin>>p[i];
	}
	dp[0][0]=1;
	for(ll i=1;i<=n;i++){
	    for(ll j=0;j<=i;j++){
	        if(j)dp[i][j]+=dp[i-1][j-1]*p[i-1];
	        dp[i][j]+=dp[i-1][j]*(1-p[i-1]);
	    }
	}
	double ans=0;
	for(ll i=0;i<=n;i++){
	    if(i>n-i)ans+=dp[n][i];
	}
	printf("%.12f",ans);
	return 0;
}


Measured memory_bytes: 49864
//   _/                _/                 _/_/_/   _/
//_/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
// _/     _/    _/   _/     _/    _/  _/_/_/     _/
//_/     _/    _/   _/     _/    _/  _/    _/   _/
// _/_/   _/_/       _/_/   _/_/      _/_/     _/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=2e9;
const ll INF=9e18;
typedef pair<int,int> P;
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  int n,ans=-inf,cnt=0,f[105][10]={},p[105][11]={},c1=0;
  cin >> n;
  for(int i=0; i<n; i++) {
    for(int j=0; j<10; j++) {
      cin >> f[i][j];
    }
  }
  for(int i=0; i<n; i++) {
    for(int j=0; j<11; j++) {
      cin >> p[i][j];
    }
  }
  for(int i=1; i<(1<<10); i++) {
    cnt=0;
    for(int j=0; j<n; j++) {
      c1=0;
      for(int k=0; k<10; k++) {
        if(i&(1<<k)&&f[j][k]) {
          c1++;
        }
      }
      cnt+=p[j][c1];
    }
    ans=max(ans,cnt);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mem(x,y) memset(x,y,sizeof(x))
#define left (2*pos)
#define right (2*pos+1)
#define M ((L+R)/2)
#define sz 1000005
ll seg[1000005], se[sz], posi[sz], num[sz];
map<ll,ll>mp;
int main()
{
    ios_base:: sync_with_stdio(0), cin.tie(0), cout.tie(0);

    ll i,j,k,s,d,r,m,n;
    cin>>n;
    for(i=1; i<=n; i++) cin>>num[i], se[i] = num[i];

    sort(num+1, num+n+1);
    for(i=1; i<=n; i++) mp[num[i]] = i;
    for(i=1; i<=n; i++) se[i] = mp[se[i]], posi[se[i]] = i;
    s=0;
    for(i=n; i>=1; i--)
    {
        if(i%2 != posi[i]%2) s++;
    }
    cout<<s/2<<endl;
}




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

#define pb push_back
#define pf push_front
#define ssort(e) sort(e.begin(), e.end())
#define ll long long int
#define ull unsigned long long

typedef vector<int> VII;
typedef vector<string> VSS;
typedef vector<char> VCC;
typedef pair<int, int> PII;
typedef vector<PII> VP;
typedef map<int, int> MII;
typedef stack<int> STI;
typedef queue<int> QUI;
typedef set<int> SII;
typedef set<char> SCC;

string to_String(double num)
{
    ostringstream ss;
    ss << num;
    return ss.str();
}

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

    string s, t;

    cin >> s >> t;

    ssort(s);
    ssort(t);
    reverse(t.begin(), t.end());

    if (s < t) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
using namespace std;
 
typedef long long ll;
#define rep(i, n) for(int i = 0; i < n; i++)
 
ll func(ll num){
    return (ll)(num * (num - 1)) / 2;
}
 
int main(){
    int N;
    cin >> N;
    int A[N];
    rep(i, N) cin >> A[i];
    map<ll, ll> mp;
    rep(i, N) mp[A[i]]++;
    ll sum = 0;
    for(auto p : mp) sum += func(p.second);
    for(ll i = 0; i < N; i++){
        ll res = sum;
        ll value = mp[A[i]];
        res -= (value-1);
        cout << res << endl;
    }
    return 0;
}

Measured memory_bytes: 11904
import java.util.Scanner

fun main(args: Array<String>){
    val scanner = Scanner(System.`in`)
    val result = D1015B(
                    numberOfBall  = scanner.nextInt()
                   ,numberOfPaint = scanner.nextInt()
                 ).judge()
    println(result)
}

class D1015B(
  val numberOfBall:  Int
 ,val numberOfPaint: Int
){
    fun judge(): Int{
        return numberOfPaint * 
               Math.pow(numberOfPaint - 1.toDouble(), numberOfBall-1.toDouble())
                   .toInt()
    }
}

Measured memory_bytes: 31392
from sys import stdin
def main():
    #入力
    readline=stdin.readline
    q,h,s,d=map(int,readline().split())
    n=int(readline())

    if n%2==0:
        print(min(4*q*n,2*h*n,s*n,d*n//2))
    else:
        tmp1=min(4*q*(n-1),2*h*(n-1),s*(n-1),d*(n-1)//2)
        tmp2=min(4*q,2*h,s)
        print(tmp1+tmp2)
        
if __name__=="__main__":
    main()

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
typedef pair<int, pair<int, int>> PP;
typedef pair<P, int> PPi;
constexpr double PI = 3.1415926535897932;   // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1e+9 + 7;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define chadd(x, y) x = (x + y) % mod

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

    string s;
    cin >> s;
    int n = s.length();
    for(int i = 0; i < n / 2; ++i){
        if(s[i] != s[n - i - 1]){
            cout << "No\n";
            return 0;
        }
    }
    int ub = (n - 1) / 2;
    for(int i = 0; i < ub / 2; ++i){
        if(s[i] != s[ub - i - 1]){
            cout << "No\n";
            return 0;
        }
    }
    string t = s.substr((n + 3) / 2 - 1, n);
    int nt = t.length();
    for(int i = 0; i < nt / 2; ++i){
        if(t[i] != t[nt - i - 1]){
            cout << "No\n";
            return 0;
        }
    }
    cout << "Yes\n";
}

Measured memory_bytes: 256
#include<cstdio>
#include<functional>
#include<algorithm>
using namespace std;
int main(void)
{
	int x;
	char s[7][4]={"thu","fri","sat","sun","mon","tue","wed"};
	scanf("%d",&x);
	printf("%s\n",s[x%7]);
	return 0;
}


Measured memory_bytes: 2684
#include<iostream>
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
const int N=1e6+2;
int trie[N][27], nxt, freq[N], first[30] , n;
ll ans;
void solve(string & s)
{
    int sz=s.size();
    for(int i=0; i<26; i++)
        first[i]=1e7;
    for(int i=0; i<sz; i++)
        first[s[i]-'a']=min(first[s[i]-'a'],i);
    int node=0;
    for(int i=sz-1; i>=0; i--)
    {
        for(int j=0; j<26; j++)
            if(first[j]<=i)
                ans+=freq[trie[node][j]];
        node=trie[node][s[i]-'a'];
    }
}
vector<string> v;
int main()
{
    IO
    cin>>n;
    while(n--)
    {
        string s;
        cin>>s;
        int sz=s.size();
        v.push_back(s);
        int node=0;
        for(int i=sz-1; i>=0; i--)
        {
            if(trie[node][s[i]-'a']==0)
                trie[node][s[i]-'a']=++nxt;
            node=trie[node][s[i]-'a'];
        }
        freq[node]++;
        ans-=freq[node];
    }
    for(auto &i : v)
        solve(i);
    cout<<ans;
}


Measured memory_bytes: 112864
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
using namespace std;

string s;

int main(){
	cin>>s;
	for(int i=0;i<s.length()-1;i++)
		if(s[i]==s[i+1]){
			cout<<i+1<<" "<<i+2;
			return 0;
		}
	for(int i=0;i<s.length()-2;i++)
		if(s[i]==s[i+2]){
			cout<<i+1<<" "<<i+3;
			return 0;
		}
	cout<<-1<<" "<<-1;
	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
const int N=200010;
int head[N],cnt; //----------------------------------------------------------------------Graph
struct edge
{
	int x,y,dis;
	bool operator < (const edge a)const
	{
		return dis<a.dis;
	}
}e[N<<3];
int n,m,k;long long ans;
int a[N];
int fa[N];
int gf(int k)
{
	return fa[k]==k?k:fa[k]=gf(fa[k]);
}
int main()
{
	int u,v,w;
	scanf("%d%d",&n,&m);
	memset(a,127,sizeof(a));
	for(int i=1;i<=m;i++)
	{
		scanf("%d%d%d",&e[i].x,&e[i].y,&e[i].dis);
		a[e[i].x]=min(e[i].dis+1,a[e[i].x]);
		a[e[i].y]=min(e[i].dis+2,a[e[i].y]);
	}
	cnt=m;
	int s=2000000000;
	for(int i=0;i<2*n;i++)
    {
		s=min(s+2,a[i%n]);
		if(i>=n)
			e[++cnt].x=i%n,e[cnt].y=(i+1)%n,e[cnt].dis=s;
	}
	sort(e+1,e+cnt+1);
	for(int i=0;i<n;i++)
		fa[i]=i;
	for(int i=1;i<=cnt;i++)
	{
		u=e[i].x,v=e[i].y;
		if(gf(u)==gf(v))continue;
		ans+=e[i].dis;
		fa[gf(u)]=gf(v);
	}
	printf("%lld",ans);
	return 0;
}


Measured memory_bytes: 13568
s = int(input())
count = 1
A = [s]
while True:
    if s % 2 == 0:
        s = s // 2
    else:
        s = 3 * s + 1
    count += 1
    if s not in A:
        A.append(s)
    else:
        break
print(count)


Measured memory_bytes: 38384