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

using namespace std;

#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back

const int maxn = 2e5 + 5;

int n;
int can[maxn];
int d[maxn];
vector<int> adj[maxn];

void dfs(int u, int p) {
    for (auto v : adj[u]) {
        if (v == p) continue;
        d[v] = d[u] + 1;
        dfs(v, u);
    }
}

int main() {
    cin >> n;

    can[1] = 1;
    can[2] = 0;

    rep(i, 3, maxn) {
        if (!can[i - 1] || !can[i - 2]) can[i] = 1;
        else can[i] = 0;
    }

    rep(i, 0, n - 1) {
        int x, y;
        cin >> x >> y;
        x--; y--;
        adj[x].pb(y);
        adj[y].pb(x);
    }

    d[0] = 1;
    dfs(0, -1);

    int found = -1;
    rep(i, 0, n) {
        if (!~found || d[found] < d[i]) {
            found = i;
        }
    }
    d[found] = 1;
    dfs(found, -1);
    int res = -1;
    rep(i, 0, n) {
        res = max(res, d[i]);
    }

    cout << (can[res] ? "First" : "Second");

    return 0;
}


Measured memory_bytes: 22144
#include <stdio.h>
#include <string.h>
 
int main (){
 
    int n;
    scanf("%d", &n);
    char arr[10000];
    scanf("%s", arr);
    for(int i = 0; i < strlen(arr); i++){
        arr[i] = arr[i] + n;
        if(arr[i] >= 91) arr[i] -= 26;
    }
 
    printf("%s", arr);
 
 	return 0;
}

Measured memory_bytes: 1740
N, A, B = map(int, input().split())
def str_sum(strings):
    n_len = len(strings)
    res = 0
    for i in range(n_len):
        res += int(strings[i])
    return res
result = 0
for i in range(1, N+1):
    now = str(i)
    if (A <= str_sum(now)) and (str_sum(now) <= B):
        result +=int(now)
print(result)

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

using namespace std;
vector<long long> factors;
#define ll long long




#define pii pair<int,int>
#define pll pair<ll,ll>
#define _ <<'\n'
#define __ << ' '
#define all(x) (x).begin(), (x).end()
#define gcd __gcd
int IT_MAX = 1 << 17;
int MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-1);
const double ERR = 1e-10;
#define szz(x) (int)(x).size()
#define IOS ios_base::sync_with_stdio(false); cout.tie(0);cin.tie(0);
#define flush fflush(stdout)

template<typename T>
int BS(vector<T>& mas,T val){
	int l,r;
	l = 0;
	r = mas.size() - 1;
	while(r - l > 1){
		int mid = l + (r - l)/2;
		if(mas[mid] < val){
			l = mid;
		} else
			r = mid;
	}
	if(mas[r] == val)
		return r;
	if(mas[l] == val)
		return l;
	return -1;
}

ll mod(ll a, ll m)
{ return (a + (abs(a) / m) * m + m) % m; }



int main()
{
	IOS

	int n,a,b;
	cin >> n >> a >> b;

	cout << min(a,b) << ' ';
	int k;
	k =(a + b) - n;
	if(k <= 0)
		cout << 0;
	else
		cout << k;

	return 0;
}
/*
4
 F
 F
 F
 F
 */
/*
4
 C
 C
 3
 3
 */
/*
 12
 FC0
 FC0
 FC0
 FC0
 FC0
 FC0
 FC0
 FC0
 FC0
 FC0
 FC0
 FC0

 */

Measured memory_bytes: 256
#include<map>
#include<bitset>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<stack>

#define REP(i,x,y) for(ll i=x;i<=y;i++)
typedef long long ll;
using namespace std;

ll a[60];

bool ok(ll x, ll n) {
	if (x < 0) {
		return false;
	}
	ll b[60];
	REP(i, 1, n) {
		b[i] = a[i] + x;
	}
	ll cnt = 0;
	REP(i, 1, n) {
		ll t = a[i] + x - n + 1;
		if (t >= 0) {
			if (t%(n+1) == 0) {
				cnt += t / (n+1);
			}
			else {
				cnt += t / (n+1) + 1;
			}
		}
	}
	return cnt <= x;
}

int main() {
	ll n;
	cin >> n;
	bool flag = 1;
	REP(i, 1, n) {
		cin >> a[i];
		if (a[i] > n - 1) {
			flag = 0;
		}
	}
	if (flag) {
		cout << 0 << endl;
		return 0;
	}
	ll lb = 0; ll ub = 1000000000000000000;
	while (ub - lb > 1)
	{
		ll mid = (ub + lb) / 2;
		if (ok(mid,n)) {
			ub = mid;
		}
		else {
			lb = mid;
		}
	}
	//cout << ub << endl;
	REP(i, -1000000, 1000000) {
		if (ok(ub + i, n)) {
			cout << ub + i << endl;
			return 0;
		}
	}
}

Measured memory_bytes: 384
from collections import defaultdict as dd
from itertools import combinations
from sys import exit
n = int(input())
if n == 1:
    print(1)
    exit()

Points = []
for i in range(n):
    Points.append(list(map(int, input().split())))

Vector = dd(lambda: 0)
for point1, point2 in combinations(Points, 2):
    if point1[0] > point2[0]:
        x_v = point1[0] - point2[0]
        y_v = point1[1] - point2[1]
    elif point1[0] == point2[0] and point1[1] >= point2[1]:
        x_v = point1[0] - point2[0]
        y_v = point1[1] - point2[1]
    else:
        x_v = point2[0] - point1[0]
        y_v = point2[1] - point1[1]
    Vector[(x_v, y_v)] += 1
#print(Vector)

print(max(n - max(Vector.values()), 1))



Measured memory_bytes: 39920
ma = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
tma = lambda :tuple(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
import collections
import math
import itertools
import heapq as hq

n = ni()
A = []
ans = 0
tmp=0
for i in range(n):
    a = ni()
    if a==0:
        ans+=tmp//2
        tmp=0
    else:
        tmp+=a
ans+=tmp//2
print(ans)


Measured memory_bytes: 9484
main = do
  line1 <- getLine
  line2 <- getLine
  let
    n  = head $ map read $ words line1 :: Int
    ls = map read $ words line2 :: [Int]
    l_max = foldl max 0 ls
    in
      if l_max * 2 < (sum ls) then putStrLn "Yes"
      else putStrLn "No"



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

const ll mx = 1e18;

int main() {
	int n;
 	cin >> n;
    ll ans = 1;
  	bool ng = false; 
	
    rep(i,n) {
    	ll a;
        cin >> a;
        
        if (a == 0) {
        	cout << 0 << endl;
          	return 0;
        }
        if (ng || a > mx/ans) {
          	ng = true;
        }
      	ans *= a;
    }
    
  	if (ng) {
    	cout << -1 << endl;
    } else {
	  	cout << ans << endl;
    }
	return 0;
}

Measured memory_bytes: 3632
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
//typedef __int64 LL;
//typedef long long int LL;
typedef pair<int,int> P;
//typedef pair<LL,LL> PL;

const int MOD=1000000007;

	
int main()
{
	int a,b,c,d;cin>>a>>b>>c>>d;
	int x=c-a,y=d-b;
	cout<<c-y<<" "<<d+x<<" "<<a-y<<" "<<b+x<<"\n";
}

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

main() {
  ll cookie[3];
  for (int i = 0; i < 3; i++) cin >> cookie[i];

  bool ok = false;
  int ans = 0;
  if (cookie[0] == cookie[1] && cookie[1] == cookie[2] && cookie[2] % 2 == 0) {
    ok = true;
    ans = -1;
  }
  while (!ok) {
    if (cookie[0] % 2 || cookie[1] % 2 || cookie[2] % 2) break;
    ans++;
    ll tmp[3]{};
    for (int i = 0; i < 3; i++) {
      if ((cookie[i] / 2) % 2 != (cookie[(i + 1) % 3] / 2) % 2) ok = true;
      tmp[i] = (cookie[i] + cookie[(i + 1) % 3]) / 2;
    }
    for (int i = 0; i < 3; i++) cookie[i] = tmp[i];
  }
  cout << ans << endl;
}


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

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N, M = MAP()

if N == M:
    Yes()
else:
    No()


Measured memory_bytes: 3064
#include <stdio.h>
#include <string.h>
#define ll long long int

int main(){
	int n, cek = 0;
	scanf("%d", &n);
	int num[n];
	for(int i = 0; i<n; i++){
		scanf("%d", &num[i]);
	}
	for(int i = 0; i<n; i++){
		for(int j = i + 1; j<n; j++){
			for(int k = j+1; k<n; k++){
				if((num[i] != num[j]) && (num[j] != num[k]) && (num[k] != num[i])){
					if((num[i] + num[j] > num[k]) && (num[j] + num[k] > num[i]) && (num[k] + num[i] > num[j])){
						cek++;
				}
			}
		}
	}
}
	printf("%d\n",	cek);
	
	return 0;
}

Measured memory_bytes: 1728
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	list := getStdinIntArr()
	A := list[0]
	B := list[1]
	C := list[2]
	K := list[3]

	A_N := A - K
	if A_N < 0 {
		K = K - A
		A_N = A
	} else {
		K = 0
		A_N = A - A_N
	}

	B_N := B - K
	if B_N < 0 {
		K = K - B
		B_N = B
	} else {
		K = 0
		B_N = B - B_N
	}

	C_N := C - K
	if C_N < 0 {
		K = K - C
		C_N = C
	} else {
		K = 0
		C_N = C - C_N
	}

	fmt.Printf("%d\n", A_N+(-1)*C_N)
}

func getStdin() string {
	sc.Scan()
	return sc.Text()
}
func getStdinInt() int {
	str := getStdin()
	rtn, _ := strconv.Atoi(str)
	return rtn
}
func getStdinIntArr() []int {
	str := getStdin()
	list := strings.Split(str, " ")
	rtn := make([]int, len(list))
	for idx, val := range list {
		rtn[idx], _ = strconv.Atoi(val)
	}
	return rtn
}


Measured memory_bytes: 1724
s = input()
s = list(s)


s = [int(x) for x in s]


leng = len(s)

# print(leng)
count = 0
if s[0]==0:
    for i in range(leng):
        if i%2==1 and s[i]==0:
            count +=1
        elif i%2==0 and s[i]==1:
            count +=1
else:#1スタート
    for i in range(leng):
        if i%2==1 and s[i]==1:
            count +=1
        elif i%2==0 and s[i]==0:
            count +=1

print(count)

Measured memory_bytes: 4652
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <queue>
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int dy[] = {1, 0, -1, 0};
const int dx[] = {0, 1, 0, -1};
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> v;
    for(int i = 0; i < n; i++)
    {
        int x;
        cin >> x;
        v.push_back(x);
    }
    int q;
    cin >> q;
    for(int i = 0; i < q; i++)
    {
        int b, e, k;
        cin >> b >> e >> k;
        int cnt = 0;
        for(int i = b; i < e; i++) if(v[i] == k) cnt++;
        cout << cnt << "\n";
    }
    return 0;
}




Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define fastIO (cin.tie(0), cout.tie(0), ios::sync_with_stdio(false))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define precise(i) fixed << setprecision(i)
using lint = long;
using llint = long long;
using namespace std;

int main() {
    fastIO;
    int n, l;
    cin >> n >> l;
    vector<string> s(n);
    rep(i, n) cin >> s.at(i);
    sort(s.begin(), s.end());
    for (auto line : s) cout << line;
    cout << endl;
}


Measured memory_bytes: 3668
li = input().split()
l = list(map(int,li))
W,H,x,y,r = l
flag = 1
if x + r > W or x-r < 0:
    flag = 0
if y + r > H or y - r < 0:
    flag = 0
if flag == 1:
    print("Yes")
if flag == 0:
    print("No")


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

int main(){
  int n;
  cin >> n;
  vector<int> t(n);
  int ans = 0;
  for(int i = 0; i < n; i++){
    cin >> t[i];
  }
  for(int i = 0; i < n; i++){
    for(int j = 0; j < n; j++){
      if(i != j){
        ans += t[i] * t[j];
      }
    }
  }
  cout << ans / 2 << endl;
}

Measured memory_bytes: 3568
#include <iostream>
#include <complex>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
typedef complex<double> C;

#define EPS (1e-9)

double cross(C a, C b) {
  return a.real() * b.imag() - a.imag() * b.real();
}

int is_intersected(C a1, C a2, C b1, C b2) {
  return (cross(a2-a1, b1-a1) * cross(a2-a1, b2-a1) < EPS) &&
         (cross(b2-b1, a1-b1) * cross(b2-b1, a2-b1) < EPS);  
}

int t;
C s[100], e[100];
int o[100], l[100];

void solve() {
  double xa, ya, xb, yb;
  cin>>xa>>ya>>xb>>yb;
  C a(xa, ya), b(xb, yb);
  C ab = b - a;
  
  int n;
  cin>>n;
  for (int i = 0; i < n; i += 1) {
    cin>>s[i].real()>>s[i].imag();
    cin>>e[i].real()>>e[i].imag();
    cin>>o[i]>>l[i];
  }
  
  // ð_ÌWðßé
  // xÀWÆù¶Hüf[^ÌY
  vector<pair<double,int> > iss;
  for (int i = 0; i < n; i += 1) {
    if (!is_intersected(a, b, s[i], e[i])) continue;
    if (abs(cross(b-a, e[i]-s[i])) < EPS) continue;
    C ex = e[i] - s[i];
    //double d1 = abs(cross(ex, xa - s[i]));
    double d1 = abs(cross(ex, a - s[i]));
    //double d2 = abs(cross(ex, xb - s[i]));
    double d2 = abs(cross(ex, b - s[i]));
    double t = d1 / (d1 + d2);
    iss.push_back(make_pair(t, i));
  }
  
  sort(iss.begin(), iss.end());
  int res = 100;
  for (int z = 0; z < 2; z += 1) {
    int mode = z, tres = 0;
    for (int i = 0; i < iss.size(); i += 1) {
      int num = iss[i].second;
      
      bool flag = false;
      if (o[num] == 1 && l[num] != mode) {
        flag = true;
      } else if (o[num] == 0 && l[num] == mode) {
        flag = true;
      }
      
      if (flag) {
        tres++;
        mode = !mode;
        //mode = (mode == 1) ? 0 : 1 ;
      }
    }
    res = min(res, tres);
  }
  cout<<res<<endl;
}

int main (int argc, char const* argv[]) {
  cin>>t;
  
  for(int i=0;i<t;i++) solve();
  
  return 0;
}

Measured memory_bytes: 968
//teja349
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip> 
//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val

using namespace std;
#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >

//std::ios::sync_with_stdio(false);   
ll val1[212345],val2[212345];
ll a[212345],b[212345];
vl vec;
int main(){
    std::ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    ll i,j,haha;
    rep(i,n){
    	cin>>a[i];
    }
    rep(i,n){
    	cin>>b[i];
    }
    ll ans=0;
    ll cnt=0,previ=0;
    rep(i,30){
    	cnt=0;
    	haha=(1<<(i+1));
    	rep(j,n){
    		val1[j]=a[j]%(haha);
    		if(a[j]&(1<<i)){
    			cnt++;
    		}
    	}
    	rep(j,n){
    		val2[j]=b[j]%haha;
    		if(b[j]&(1<<i))
    			cnt++;
    		
    	}
    	cnt%=2;
    	cnt*=n;
    	cnt%=2;
    	cnt+=previ;
    	cnt%=2;
    	if(cnt){
    		ans+=(1<<i);
    	}
    	vec.clear();
    	rep(j,n){
    		vec.pb(val2[j]);
    	}
    	sort(all(vec));
    	previ=0;
    	rep(j,n){
    		previ+=vec.end()-lower_bound(vec.begin(),vec.end(),haha-val1[j]);
    		previ%=2;
    	}


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



Measured memory_bytes: 8948
#include<iostream>
#include<string>
#include<map>
using namespace std;

int main(){
	int N,K;
	cin>>N>>K;
	map<char,int>arr;
	char tmp;
	for(int i=0;i<K;++i){
		cin>>tmp;
		arr[tmp] = 1;
	}
	string Nstr;
	for(int i=N;i<100000000;++i){
		Nstr = to_string(i);
		int dame=0;
		for(int j=0;j<Nstr.size();++j){
			if(arr[Nstr[j]]==1){
				dame=1;
				break;
			}
		}
		if(dame==0){
			cout<<i<<endl;
			break;
		}
	}
}


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

int main(){
    using namespace std;
    constexpr unsigned long C = 26;
    unsigned long D;
    cin >> D;
    vector<unsigned long> c(C);
    for(auto&& i : c)cin >> i;
    vector v(D, vector<unsigned long>(C));
    for(auto&& i : v)for(auto&& j : i)cin >> j;

    vector<unsigned long> last(C);

    for(unsigned long i{0}; i < D; ++i){
        unsigned long mx{0}, mxi{0};
        for(unsigned long j{0}; j < C; ++j){
            unsigned long tmp{v[i][j] + c[j] * (i + 1 - last[j])};
            if(tmp > mx){
                mx = tmp;
                mxi = j;
            }
        }
        cout << mxi + 1 << endl;
        last[mxi] = i + 1;
    }

    return 0;
}

Measured memory_bytes: 3700
import java.io.*;

class Main{
        private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        private static void swap(int[] A, int i, int j){
                int tmp = A[i];
                A[i] = A[j];
                A[j] = tmp;
        }

        private static void printArray(int[] A){
                for(int i=0; i<A.length; i++){
                        System.out.print(A[i]);
                        if(i!=A.length-1)
                                System.out.print(" ");
                }
                System.out.println();
        }

        private static int selectionSort(int[] A){
                int count = 0;
                int mini = 0;

                for(int i=0; i<A.length-1; i++){
                        boolean doswap = false;
                        mini = i;
                        for(int j=i+1; j<A.length; j++)
                                if(A[j] < A[mini]){
                                        mini = j;
                                        doswap = true;
                                }
                        if(doswap){
                                swap(A, i, mini);
                                count++;
                        }
                }
                return count;
        }
        public static void main(String[] args) throws IOException{
                int N = Integer.parseInt(br.readLine());
                String[] iline = br.readLine().split(" ");
                int[] A = new int[N];

                for(int i=0; i<N; i++)
                        A[i] = Integer.parseInt(iline[i]);

                int count = selectionSort(A);

                printArray(A);
                System.out.println(count);
        }
}

Measured memory_bytes: 24300
#include <iostream>
using namespace std;
 
int main() {
    int n, ttl, cnt;
    int *a, *b, *c;
    ttl = 0;
    cnt = 0;

    cin >> n;

    a = new int[n];
    b = new int[n];
    c = new int[n-1];

    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    for(int i = 0; i < n; i++){
        cin >> b[i];
    }
    for(int i = 0; i < n-1; i++){
        cin >> c[i];
    }            

    for(int i = 0; i < n; i++){
        ttl = ttl + b[i];
        if(i >= 1 && (a[i] - a[i - 1]) == 1){
            ttl = ttl + c[a[i - 1]-1];
        }

    }

    cout << ttl << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main (){

	int a=0;
	int b=0;
	int c=0;
	
	cin>>a>>b>>c;
	int MIN=0;
	int MAX=0;
	int MID=0;
	
	MIN=min(min(a,b),c);
	MAX=max(max(a,b),c);
	MID=max( max(min(a,b), min(c,b)), min(a, c) );
	
	cout<<MIN<<" "<<MID<<" "<<MAX<<endl;
}


Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <tuple>

using ll = long long;
using namespace std;
#define modmod 1000000007

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,k,n) for(int i=k;i<n;i++)


int main(){
    int A,B,C;
    int X,Y;
    cin >> A >> B >> C >> X >> Y;
    int maxi, mini;
    bool Xbig = false;
    if(X>Y){
        maxi = X;
        mini = Y;
        Xbig = true;
    }else{
        maxi = Y;
        mini = X;
    }

    int result = 0;


    if(2*C < A and 2*C < B){
        result += maxi*2*C;
    }
    else if(2*C < A+B){
        result += 2*C*mini;
        if(Xbig){
            if(A <= 2*C){
                result += A*(maxi-mini);
            }else{
                result += 2*C*(maxi-mini);
            }
        }else{
            if(B <= 2*C){
                result += B * (maxi-mini);
            }else{
                result += 2*C * (maxi-mini);
            }
        }
    }else{
        result += A*X + B*Y;
    }

    cout << result << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.*;
class Main
{
  public static void main(String[] atgs)
  {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int cnt = 0;
    for(int i = 1; i <= N; i+=2){
      int tmp = 0;
      for(int j = 1; j <= i; j+=2){
        if(i % j == 0){
          tmp++;
        }
      }
      if(tmp == 8) cnt++;
    }
    System.out.println(cnt);
  }
}

Measured memory_bytes: 22996
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace 競プロCS {
    class ABC159B {
        static void Main() {
            string s = Console.ReadLine();
            int n = s.Length;

            Console.WriteLine(IsKaibun(s, 0, n) && IsKaibun(s, 0, n / 2) && IsKaibun(s, (n + 3) / 2, n) ? "Yes" : "No");
        }
        static bool IsKaibun(string s, int start, int end) {
            for (int i = start; i < end / 2; i++) {
                if (s[i] != s[end - i - 1]) return false;
            }
            return true;
        }
    }
}


Measured memory_bytes: 11092
#include<stdio.h>

int main(void)
{
        int a,b,c;
        int i;

        scanf("%d%d%d", &a,&b,&c);

        for(i = 0; i < 10; i++) {
                c = a * c - b;
                printf("%d\n", c);
        }
        return 0;

}


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

using ll=long long;
int main(){
    int n;
    cin>>n;
    vector<ll> a(n);
    vector<ll> b(n);
    for(int i=0;i<n;i++){
        cin>>a[i]>>b[i];
    }
    vector<ll> v(n);
    for(int i=0;i<n;i++){
        v[i]=a[i]+b[i];
    }
    sort(v.begin(),v.end(),greater<>());
    ll res=-accumulate(b.begin(),b.end(),0LL);
    for(int i=0;i<n;i+=2){
        res+=v[i];
    }
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 2560
#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>

const uint64_t mod = 1'000'000'000 + 7;

int main() {
  uint32_t N = 0;
  std::cin >> N;

  uint64_t sum = 0, sq_sum = 0;
  for (size_t i = 0; i < N; i++)
  {
    uint64_t a = 0;
    std::cin >> a;

    sum += a;
    sq_sum += (a*a) % mod;
    sum %= mod;
    sq_sum %= mod;
  }
  
  uint64_t result = (sum*sum) % mod;
  result += (result < sq_sum ? mod : 0);
  result -= sq_sum;

  result *= (mod+1)/2;
  result %= mod;

  std::cout << result << std::endl;

  return 0;
}

Measured memory_bytes: 3620
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
using namespace std;
int main()
{
	string s;
	cin>>s;
	int gen;
	scanf("%d",&gen);
	for(int i=0;i<s.size();i++)
	{
		int t=('z'-s[i]+1)%26;
		if(t<=gen)
		{
			s[i]='a';
			gen-=t;
		}
	}
	int x=(s[s.size()-1]-'a'+gen)%26;
	s[s.size()-1]=x+'a';
	cout<<s<<endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <math.h>
#include <iomanip>
using namespace std;


int main() {
  int l, r;
  cin >> l >> r;
/*
  for (int i = 0; i < r / 2019 + 10; i++) {
    if (l <= i * 2019 && r >= i * 2019) {
      cout << 0 << endl;
      return 0;
    }
  }*/

  if (r - l > 2019) {
    cout << 0 << endl;
    return 0;
  }

  int fans = 2000000000;
  for (int i = l; i <= r - 1; i++) {
    for (int j = i+1; j <= r; j++) {
      int ans = (1ll * i * j) % 2019;
      fans = min(fans, ans);
    }
    //int ll = l + i;
    //int ans = ((ll % 2019) * ((ll+1) % 2019)) % 2019;
    //fans = min(fans, ans);
  }

  cout << fans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {if(b>a) return b; else return a;}
int min(int a, int b) {if(b<a) return b; else return a;}


//***********************************
//mintを定義
//***********************************
const int mod = 1000000007;
struct mint {
  int x;
  mint(int x=0):x(x%mod){}   //メンバ変数xをx%modで初期化
  int get() const { return (int)x; }
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;           //thisは暗黙的に左辺のポインタ
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }

  //累乗
  mint mpow(int t) const {
    if (!t) return 1;
    mint a = mpow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  //除算
  mint minv() const {
    return mpow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.minv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

//標準出力
ostream& operator<<(ostream& st, const mint a) 
{ st << a.get(); return st; };
//--------------------------------------------------

//***********************************
//場合の数の計算
//***********************************
const int MAX = 200010;
mint fac[MAX], finv[MAX];

//前計算
inline void INIT_F(){
    fac[0] = finv[0] = 1;
    for(int i=1; i<MAX-1; i++) {
        fac[i] = (fac[i-1]*mint(i));
        finv[i] = (finv[i-1]/mint(i));
    }
}

//nCk
mint mcomb(int n, int k) {
    if(n<k || k<0) return 0;
    else return ((fac[n]*finv[k])*finv[n-k]);
}

//nHk
mint mhcomb(int n, int k) {
  return mcomb(n+k-1, k);
}
//--------------------------------------------------

signed main() {
    int n, a, b;
    cin >> n >> a >> b;
    INIT_F();

    mint res;
    mint t = 2;
    res = t.mpow(n) - 1;
    //cout << res << endl;

    
    mint aa = 1, bb = 1;
    rep(i, a) {
        aa *= n-i;
    }
    rep(i, b) {
        bb *= n-i;
    }
    //cout << aa << " " << fac[a] << endl;
    //cout << bb << " " << fac[b] << endl;
    aa /= fac[a]; bb /= fac[b];
    

    res -= aa;
    res -= bb;

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

Measured memory_bytes: 3328
S = input()
S_inv = S[::-1]

out = 0
for i in range(len(S)):
  if S[i] != S_inv[i]:
    out = out + 1

out = out // 2
#if out % 2 == 1:
#  out == out // 2 + 1
#else:
#  out == out // 2 
print(out)

Measured memory_bytes: 3060
A,B,C = map(int,input().split())
K = int(input())
if(A >= B and A >= C):
    print(A*pow(2,K)+B+C)
elif(B >= A and B >= C):
    print(A+B*pow(2,K)+C)
else:
    print(A+B+C*pow(2,K))


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define LL long long int
using namespace std;
int main() 
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 

    string S;
    string T;
    cin>>S;
    cin>>T;
    LL count=0;
    for(LL i=0;i<S.size();i++)
    {
        if(S[i]!=T[i])
            count++;
    }
    cout<<count;
}

Measured memory_bytes: 3816
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll ;
#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
 const ll inf=1e9+7;
string a,b,c;

ll mod(ll a)
{
	if(a<inf)return a;
	else 
	return a%inf;
}
 void test_cases()
{

char a,b;
cin>>a>>b;

if(a=='H')cout<<b;
else
{
	if(b=='H')cout<<"D";
	if(b=='D')cout<<"H";
}



}


int main()
{
    fast;
  ll t;
 // cin>>t;
 t=1;
  while(t--)
  test_cases();

  	
}

		
	
	
	
	


Measured memory_bytes: 3640
# encoding:utf-8
import copy
import numpy as np
import random

n = int(input())
X = []
U = []
for i in range(n):
    x,u = map(str,input().split())

    X.append(float(x))
    U.append(u)

ans = 0
for i in range(n):
    if U[i]=="JPY":
        ans += X[i]
    else:
        ans += X[i]*380000

print(ans)


Measured memory_bytes: 13356
#include<bits/stdc++.h>
using namespace std;
const int N = 101;
int a[N];
int add[N];
bool used[N];
signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif
    int n; cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }   
    vector <int> ans;
    for (int ii = 0; ii < n; ++ii) {
        int p = -1;
        for (int i = n - 1; i >= 0; --i) {
            if (used[i]) continue;
            if (a[i] + add[i] == i + 1) {
                p = i;
                break; 
            }   
            else {
                ++add[i];
            }   
        }   
        if (p == -1) {
            cout << "-1\n";
            exit(0);
        }
        ans.push_back(a[p]);
        used[p] = 1;  
    }
    reverse(ans.begin(), ans.end());
    for (int e : ans) cout << e << '\n';
}   

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int n,i,max,r[200000],result,j,flag=0,max_num,min_num;
  scanf("%d",&n);
   for(i=0;i<n;i++){
    scanf("%d",&r[i]);
    if(i==0){min_num=r[i];continue;}
    if(flag==0 && i==1){
      max=r[i]-r[i-1];
      if(min_num>r[i])min_num=r[i];
      flag=1;continue;}
     if(r[i]-min_num>max)max=r[i]-min_num;
    if(min_num>r[i])min_num=r[i];
   
  }
   printf("%d\n",max); 
  return 0;
}
      


    
    
    



Measured memory_bytes: 2580
let h, w = Scanf.scanf " %d %d" @@ fun a b -> a, b
let ss = Array.init h @@ fun _ -> Scanf.scanf " %s" @@ fun s -> s
let _ = for i = 0 to h - 1 do for j = 0 to w - 1 do if ss.(i).[j] = '#' then print_char '#' else print_int @@ List.fold_left (fun c (dy, dx) ->
  let y, x = i + dy, j + dx in if 0 <= y && y < h && 0 <= x && x < w && ss.(y).[x] = '#' then c + 1 else c) 0 [-1, 0; -1, -1; 0, -1; 1, -1; 1, 0; 1, 1; 0, 1; -1, 1] done; print_newline () done

Measured memory_bytes: 2560
#include<stdio.h>
#define MAX 100001
 
typedef struct{
  char pattern;
  int num;
  int id;
} Card;
 
int Partition(Card*,int,int);
void QuickSort(Card*,int,int);
 
int main(void){
  int i,n,judge;
  Card A[MAX];
  char space;
 
  scanf("%d%d", &n, &space);
  for(i=0;i<n;i++){
    scanf("%c%d%c", &A[i].pattern, &A[i].num, &space);
    A[i].id=i;
  }
  //??¢???????¨
  //for(i=0;i<n;i++) printf("%c%d\n", A[i].pattern, A[i].num);
  //printf("\n");
 
  judge=0;
  QuickSort(A,0,n-1);
 
  for(i=0;i<n;i++){
    if(A[i].num == A[i+1].num && A[i].id > A[i+1].id && judge == 0){
      printf("Not stable\n");
      judge=1;
      break;
    }
  }
  if(judge==0) printf("Stable\n");
 
  for(i=0;i<n;i++) printf("%c %d\n", A[i].pattern, A[i].num);
 
  return 0;
}
 
int Partition(Card *A,int p, int r){
  int i,j,x;
  Card tmp;
 
  x=A[r].num;
 
  i=p-1;
  for(j=p;j<=r-1;j++){
    if(A[j].num<=x){
      i++;
      tmp=A[i];
      A[i]=A[j];
      A[j]=tmp;
    }
  }
 
  tmp=A[i+1];
  A[i+1]=A[r];
  A[r]=tmp;
 
  return i+1;
}
 
void QuickSort(Card *A,int p, int r){
  int q;
 
  if(p<r){
    q=Partition(A,p,r);
    QuickSort(A,p,q-1);
    QuickSort(A,q+1,r);
  }
 
  return;
}

Measured memory_bytes: 1780
def main():
    N=int(input())
    S=input()
    D=[0]*(N+1)
    s=set()
    for i in range(N-1,-1,-1):
        s.add(S[i])
        D[i]=len(s)
    ans=0
    for i in range(10):
        ni=S.find(str(i))
        if ni<0: continue
        for j in range(10):
            nj=S.find(str(j),ni+1)
            if nj>=0:
                ans+=D[nj+1]
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 3316
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
int solve(vector<int> v){
    int n=v.size();
    int s=0;
    for(int i=0; i<n; i++) s+=v[i];
    vector<int> dp(s+1, -1e9);
    dp[0]=0;
    for(int i=0; i<n; i++){
        for(int j=s/v[i]; j>=1; j--){
            dp[j*v[i]]=max(dp[j*v[i]], dp[(j-1)*v[i]]+1);
        }
    }
    int ret=1;
    for(int i=1; i<=s; i<<=1) ret=max(ret, dp[i]);
    return ret;
}
int main()
{
    while(1){
        int n; cin>>n;
        if(n==0) return 0;
        int a[1010];
        for(int i=0; i<n; i++){
            cin>>a[i];
        }
        bool used[1010]={};
        int ans=1;
        for(int i=0; i<n; i++){
            if(!used[i]){
                used[i]=1;
                int x=a[i];
                int c0=0;
                while(x%2==0) x/=2, c0++;
                vector<int> v;
                v.push_back(1<<c0);
                for(int j=i+1; j<n; j++){
                    if(used[j]) continue;
                    int y=a[j];
                    bool ok=0;
                    int c=0;
                    int x1=x;
                    while(x1<=y){
                        if(x1==y){
                            ok=1;
                            break;
                        }
                        x1*=2;
                        c++;
                    }
                    if(ok){
                        used[j]=1;
                        v.push_back(1<<c);
                    }
                }
                ans=max(ans, solve(v));
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 3628
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
#define vec(s) vector

#define vvec(s) vector<vector
>
typedef vector<lli> vi;
typedef vector<vi> vvi;
typedef pair<lli,lli> pii;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YN(x) cout<<(x?"Yes":"No")<<endl;
#define out(s) cout<<s<<endl;
#define pb(s) push_back(s);
#define sp " ";
#define INF 2000000000
#define LINF 9000000000000000000
#define all(s) s.begin(),s.end()
void vout(vi v){
    for(int i=0;i<v.size();i++)
    cout<<v.at(i)<<endl;
}
int main(){
    lli n, k, m = LINF;
    cin >> n >> k;
    set<lli> p;
    (n > k ? n %= k : n += 0);
    while(!p.count(n)){
        p.insert(n);
        m = min(m, n);
        n = abs(n - k);
    }
    out(m);
}

Measured memory_bytes: 3604
#include <stdio.h>
int gcd(int a,int b){
	if(b==0){
		return a;
	}
	return gcd(b,a%b);
}

int main(){
	int N,max=0;
	scanf("%d",&N);
	int A[100001],b[100001],c[100001];
	for(int i=0;i<N;i++){
		scanf("%d",&A[i]);
	}
	b[0]=A[0];
	for(int i=1;i<N;i++){
		b[i]=gcd(b[i-1],A[i]);
	}
	c[N]=0;
	for(int i=N-1;i>=0;i--){
		c[i]=gcd(c[i+1],A[i]);
	}
	if(c[1]<b[N-2])max=b[N-2];
	else max=c[1];
	for(int i=1;i<N;i++){
		if(max<gcd(b[i-1],c[i+1]))max=gcd(b[i-1],c[i+1]);
	}
	printf("%d\n",max);
	return 0;
}

Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n; cin >> n;
    int a,b;
    a = n/100;
    b = n%100;
    if(a > 0 && a < 13 && b > 0 && b < 13){
        cout << "AMBIGUOUS" << endl;
    }else if(a >= 0 && b > 0 && b < 13){
        cout << "YYMM" << endl;
    }else if(a > 0 && a < 13 && b >= 0){
        cout << "MMYY" << endl;
    }else{
        cout << "NA" << endl;
    }
}

Measured memory_bytes: 256
import sys
N,L = map(int,input().split())

if not ( 2 <= N <= 200 and -100 <= L <= 100 ): sys.exit()

array = [ L+x for x in range(N)]
before = 100
for I in array:
    if abs(I) <= before: before = abs(I);position = array.index(I)
print(sum(array) - array[position])

Measured memory_bytes: 9152
import java.io.*
import java.util.*

fun solve(N: Int) {
    val primeSeq = PrimeUtils.generatePrimesBelow(55555).filter{ it % 5L == 1L }.take(N)
    println(primeSeq.joinToString(separator=" "))
    return
}


fun gcd(x: Int, y: Int): Int = if (y == 0) x else gcd(y, x % y)
fun gcd(x: Long, y: Long): Long = if (y == 0L) x else gcd(y, x % y)

fun Int.pow(x: Double): Double = Math.pow(this.toDouble(), x)
fun Long.pow(x: Double): Double = Math.pow(this.toDouble(), x)

fun isSquare(num: Long): Boolean {
    val sqrt = Math.sqrt(num.toDouble()).toLong()
    return sqrt * sqrt == num || (sqrt + 1L) * (sqrt + 1L) == num
}

object PrimeUtils {
    fun isPrime(num: Long): Boolean {
        if (num == 1L) return false
        if (num in listOf(2L, 3L)) return true
        if (num % 6 in listOf(0L, 2L, 3L, 4L)) return false
        val sqrt = Math.sqrt(num.toDouble()).toLong()
        for (n in 5..sqrt step 6) {
            if (num % n == 0L) return false
        }
        for (n in 7..sqrt step 6) {
            if (num % n == 0L) return false
        }
        return true
    }

    fun generatePrimesBelow(sup: Long): Sequence<Long> {
        if (sup < 2L) return sequenceOf()
        if (sup < 3L) return sequenceOf(2L)
        val seq = (0..sup / 6L)
                .asSequence()
                .flatMap { sequenceOf(6 * it + 5L, 6 * it + 7L) }
                .filter { it < sup }
        return sequenceOf(2L, 3L) + seq.filter { isPrime(it) }
    }

    fun primeFactorize(num: Long): Map<Long, Int> {
        var n = num
        val result = mutableMapOf<Long, Int>()
        val sqrt = Math.sqrt(num.toDouble()).toLong()
        val trialDivs = sequenceOf(2L) + (3..sqrt step 2).asSequence()
        for (trialDiv in trialDivs) {
            if (trialDiv > n) break
            val divideRes = iterateDivide(n, trialDiv)
            if (divideRes.first > 0) {
                result[trialDiv] = divideRes.first
                n = divideRes.second
            }
        }
        if (n != 1L) result[n] = 1
        return result
    }
}


fun iterateDivide(num: Long, divisor: Long): Pair<Int, Long> {
    var n = num
    var count = 0
    while (num != 0L && n % divisor == 0L) {
        n /= divisor
        count++
    }
    return Pair(count, n)
}

fun main(args: Array<String>) {
    fun StringArray(size: Int, init: (Int) -> String = { "\u0000" }): Array<String> {
        return Array<String>(size, init)
    }
    class Scanner(stream: InputStream) {
        private val reader = BufferedInputStream(stream).bufferedReader()
        private var st: StringTokenizer? = null
        fun next(): String {
            while (!(st?.hasMoreTokens() ?: false)) st = StringTokenizer(reader.readLine())
            return st!!.nextToken()
        }
    }
    val sc = Scanner(System.`in`)
    val N = sc.next().toInt()
    solve(N)
}


Measured memory_bytes: 35720
#include <bits/stdc++.h>
#define err(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)

typedef long long ll;

using namespace std;

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

	string s; cin >> s;
	
	int cnt = 0;
	ll ans = 0;
	
	for (int i = (int)s.size() - 1; i >= 0; i--) {
		if (s[i] == 'B') ans += cnt;
		else cnt++;
	}
	cout << ans << "\n";
	return 0;
}


Measured memory_bytes: 720
#include <stdio.h>

int main(){

int n,i,j,s,t,k;
t=0;
scanf("%d\n ",&n);

int a[n];

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

 for(k=0;k<n-1;k++){
 j=n-1;
 while(j>0){
  if(a[j]<a[j-1]){
   s=a[j-1];
   a[j-1]=a[j];
   a[j]=s;
  t++;
  }
  j--;
 }
}

for(k=0;k<n-1;k++){
  printf("%d ",a[k]);
 }
printf("%d\n",a[n-1]);
printf("%d\n",t);

return 0;
}


Measured memory_bytes: 2068
class Problem
  attr_accessor :a, :b, :n, :m, :h, :w, :ans, :c ,:x, :y
  def initialize
    @n = gets.to_s.to_i
    @m = Math.sqrt(n).to_i
  end

  def solve
    puts calc
  end

  def calc
    ans = 0
    each do |i,j|
      ans += j - 1 if i < j - 1
    end
    ans
  end

  def each
    i = 1
    while i * i <= n
      if n % i == 0
        yield n / i, i
        yield i, n / i
      end
      i += 1
    end
  end

end

pb = Problem.new
pb.solve


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

#define rep(i, n) for(int (i)=0;(i)<(n);(i)++)

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pii> vpii;

bool custom1 (pii a, pii b) {
  return a.first < b.first;
}

bool custom2 (pii a, pii b) {
  return a.second < b.second;
}

const int MOD = 1000000007;

int main() {
  int n;
  cin >> n;
  vi p(n);
  rep(i, n) cin >> p[i];

  int ans = 0;
  int MIN = INT_MAX;

  rep(i, n) {
    if(p[i] < MIN) {
      ans++;
      MIN = p[i];
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
//		Scanner a = new Scanner(System.in);
		Scanner b = new Scanner(System.in);
        int n = b.nextInt();
        int m = b.nextInt();
        System.out.printf("%d %d\n",n*m,2*(n+m));

	}

}


Measured memory_bytes: 26220
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
	long long q, h, s, d, n;
	cin >> q >> h >> s >> d >> n;

	long long per_litter = min({q*4, h*2, s});
	long long per_2litter = min(per_litter*2, d);
	long long ans = 0;
	if (n % 2 == 1) {
		ans += per_litter;
		n--;
	}
	ans += n / 2 * per_2litter;

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


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    while(true) {
        int N;
        cin >> N;
        if(!N) break;

        int a = 0, b = 0;
        while(N--) {
            int i, j;
            cin >> i >> j;
            if(i > j) a += i+j;
            else if(i < j) b += i+j;
            else {
                a += i;
                b += j;
            }
        }
        cout << a << ' ' << b << endl;
    }
    return 0;
}

Measured memory_bytes: 0
# coding: utf-8
import sys
import itertools


def sr():
    return sys.stdin.readline().rstrip()


def ir():
    return int(sr())


def lr():
    return list(map(int, sr().split()))


N, Q = lr()
S = sr()

ac = [0] * (N - 1)
for i, x in enumerate(zip(S[:], S[1:])):
    if x[0] == 'A' and x[1] == 'C':
        ac[i] = 1

cum = list(itertools.accumulate(ac))
ans_list = []
for _ in range(Q):
    l, r = lr()
    if (l - 2 < 0):
        result = cum[r - 2]
    else:
        result = cum[r - 2] - cum[l - 2]
    ans_list.append(result)
[print(ans) for ans in ans_list]


Measured memory_bytes: 13520
s = gets.strip

num_a = 0
num_ab = 0
num_abc = 0
M = 10 ** 9 + 7

sc = 1
s.chars.each{|v|
  if v == 'A'
    num_a += sc
  elsif v == 'B'
    num_ab += num_a
  elsif v == 'C'
    num_abc += num_ab
  else # v == '?'
    num_abc = num_abc * 3 + num_ab
    num_ab = num_ab * 3 + num_a
    num_a = num_a * 3 + sc
    sc *= 3
  end
  num_a %= M
  num_ab %= M
  num_abc %= M
  sc %= M
}
puts num_abc


Measured memory_bytes: 9468
# import sys
#
# input = lambda: sys.stdin.readline()


def cin_int_list():
    return [int(x) for x in input().split()]


def cin_int_iter():
    return (int(x) for x in input().split())


def cin_int():
    return int(input())


def cout_int_iter(a):
    print(' '.join(map(str, a)))


def iota(n, start=0):
    return list(range(start, n))


def cin_digits_list():
    return [ord(x) - ord('0') for x in input()]


def main():
    s = input()
    t = input()

    if len(t) - 1 != len(s):
        print('No')
        return

    if t[:-1] != s:
        print('No')
        return

    print('Yes')


main()


Measured memory_bytes: 61824
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

#define INF 1e9
#define MAXN 100005
#define MAXK 100005
#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define pii pair<int, int>

ll ans;
int N, M, K, A[MAXN], B[MAXN], C[MAXK], D[MAXK];
vi curr_friend[MAXN], block_list[MAXN];

class UnionFind {
    public:
        vector<int> rank, size, p;
    
    UnionFind(){}
    UnionFind(int n){ // 初期化: rankが0のノードをn個生成する
        rank.resize(n, 0); // rank(木の深さ)
        size.resize(n, 1); // ノード数を親番号で管理
        p.resize(n, 0); // 親の番号
        for(int i=0; i < n; i++) makeSet(i);
    }

    void makeSet(int x){// 各ノードの親を自分自身で初期化
        p[x] = x;
        rank[x] = 0;
        size[x] = 1;
    }

    int findSet(int x){
        if( x!= p[x]){ // 根を見つけるまで遡る
            p[x] = findSet(p[x]); // 経路圧縮
        }
        return p[x];
    }

    bool same(int x, int y){
        return findSet(x) == findSet(y);
    }

    void unite(int x, int y){ // linkを呼び出す
        link(findSet(x), findSet(y));
    }

    void link(int x, int y){ // 親が管理する集合を連結
        if(rank[x] > rank[y]){ // rankが小さい方の親を、大きい方の子とする
            p[y] = x;
            size[x] += size[y]; // sizeを更新
        } else {
            p[x] = y;
            size[y] += size[x];
            if(rank[x] == rank[y]){ // rankが等しければインクリメントする
                rank[y]++;
            }
        }
    }

    int getSize(int x){
        return size[findSet(x)];
    }
};

void solve(){
    UnionFind UF = UnionFind(N);

    rep(i, M){
        // cout << "unite A of size " << UF.getSize(A[i]);
        // cout << " and B of size " << UF.getSize(B[i]) << endl;
        if(!UF.same(A[i], B[i]))
            UF.unite(A[i], B[i]);
    }

    // rep(i, N)
    //     cout << curr_friend[i].size() << endl;

    rep(i, N){
        int ans = UF.getSize(i) - 1 - curr_friend[i].size();
        for(auto v: block_list[i]){
            if(UF.same(i, v)) ans--;
        }
        cout << ans << endl;
    }


}

int main(){
    cin >> N >> M >> K;

    rep(i, M){
        cin >> A[i] >> B[i];
        A[i]--, B[i]--;
        curr_friend[A[i]].push_back(B[i]);
        curr_friend[B[i]].push_back(A[i]);
    }

    rep(i, K){
        cin >> C[i] >> D[i];
        C[i]--, D[i]--;
        block_list[D[i]].push_back(C[i]);
        block_list[C[i]].push_back(D[i]);
    }

    solve();
}


Measured memory_bytes: 14584
def solve():
    px, py = map(int, input().split())
    if px == 0:
        return False
    N = int(input())
    *vs, = map(int, input().split())
    P = []
    for i in range(N):
        x, y = vs[2*i:2*i+2]
        P.append((x-1, y-1))
    W = H = 10
    dd = ((-2, 1), (-2, 0), (-2, -1), (-1, -2), (0, -2), (1, -2), (2, -1), (2, 0), (2, 1), (1, 2), (0, 2), (-1, 2))
    memo = {}
    def dfs(i, x, y):
        key = (i, x, y)
        if key in memo:
            return memo[key]
        if i == N:
            return 1
        x0, y0 = P[i]
        for dx, dy in dd:
            nx = x + dx; ny = y + dy
            if not 0 <= nx < W or not 0 <= ny < H:
                continue
            if -1 <= x0 - nx <= 1 and -1 <= y0 - ny <= 1:
                if dfs(i+1, nx, ny):
                    return 1
        memo[key] = 0
        return 0
    print("OK" if dfs(0, px-1, py-1) else "NA")
    return True
while solve():
    ...



Measured memory_bytes: 5604
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <tuple>
#include <queue>
#include <stack>
#include <set>
#include <map>

using namespace std;

class Solver {
};
int main() {
	while (true) {
		int n;
		cin >> n;
		if (n == 0)break;

		vector<int> cnts(26, 0);
		bool done = false;
		for (int i = 0; i < n; i++) {
			char c;
			cin >> c;
			if (done)continue;

			cnts[c - 'A']++;
			vector<tuple<int, char>> cntTmp;
			for (int j = 0; j < 26; j++) {
				cntTmp.emplace_back(make_tuple(cnts[j], (char)('A' + j)));
			}
			int remain = n - i - 1;
			sort(cntTmp.begin(), cntTmp.end(), greater<tuple<int, int>>());
			if (get<0>(cntTmp[0]) > get<0>(cntTmp[1]) + remain) {
				done = true;
				cout << get<1>(cntTmp[0]) << ' ' << i + 1 << endl;
			}
		}
		if (!done)cout << "TIE"<<endl;
	}
}


Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
using ll= long long;
using vi= vector<int>;
using vvi= vector<vi>;
using vd= vector<double>;
using vvd= vector<vd>;
using vc= vector<char>;
using vb= vector<bool>;
#define rep(i,x,n) for(int i=x; i<n; i++)
#define all(x) x.begin(), x.end()

int main(){
  int n,candy=0;
  cin >> n;
  rep(i,0,n){
    candy+= i+1;
  }
  cout << candy;
}


Measured memory_bytes: 256