akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <map>
#include <algorithm>
#include <string>
#include <vector> 
#include <numeric>
#include <cmath>
#include <queue>
#include <iomanip>
#include <functional>


#define CHMAX(a,b) a = std::max(a,b)
#define CHMIN(a,b) a = std::min(a,b)
#define MAXMIN(a,b,c) std::max(a,min(b,c))
#define CHABS(a) a = std::abs(a) 
#define COUT(a) std::cout << a << std::endl
#define CERR(a) std::cerr << a << std::endl
#define FOR(n) for(lli i = 0; i < n; i++)

using namespace std;
using lli = long long int;
using pll = pair<lli, lli>;
using tlll = tuple<lli, lli, lli>;
using vll = vector<lli>;

constexpr lli inf = 10000 * 10000;

lli mod197 = 1000000007LL;
lli INF = 10000000000000;

// ax + by = gcd(a,b) 最大公約数
template< typename T >
T extgcd(T a, T b, T& x, T& y) {
	T d = a;
	if (b != 0) {
		d = extgcd(b, a % b, y, x);
		y -= (a / b) * x;
	}
	else {
		x = 1;
		y = 0;
	}
	return d;
}

int main(void) {

	int digit[10] = {};

	for (int i = 0; i < 3; i++) {
		int a;
		cin >> a;
		digit[a]++;
	}

	for (int i = 1; i < 10; i++) {
		if (digit[i] == 2) {
			cout << "Yes" << endl;
			return 0;
		}
	}

	cout << "No" << endl;

	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	static Scanner in = new Scanner(System.in);

	public static void main(String[] args) {
		int N = in.nextInt();
		int A = in.nextInt();
		int B = in.nextInt();
		int max = Math.min(A, B);
		int min = Math.max((A + B) - N, 0);
		System.out.println(max + " " + min);
	}
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); ++i)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using Graph = vector<vi>;  // vi <=> vl
using vb = vector<bool>;
using boolGraph = vector<vb>;
using P = pair<int, int>;  // int <=> ll
const int MOD = 1e9+7;
const int MOD2 = 998244353;
const double EPS = 1e-9;

template<typename G>
struct LowestCommonAncestor {
  const int LOG;
  vector<int> depth;
  const G &g;
  vector<vector<int>> table;

  LowestCommonAncestor(const G &g) : g(g), depth(g.size()), LOG(32 - __builtin_clz(g.size())) {
    table.assign(LOG, vector<int>(g.size(), -1));
  }

  void dfs(int v, int p, int d) {
    table[0][v] = p;
    depth[v] = d;
    for (auto &nv : g[v]) {
      if (nv[0] != p) dfs(nv[0], v, d+1);
    }
  }

  void build() {
    dfs(0, -1, 0);
    for (int k=0; k+1<LOG; ++k) {
      for (int i=0; i<table[k].size(); ++i) {
        if (table[k][i] == -1) table[k+1][i] = -1;
        else table[k+1][i] = table[k][table[k][i]];
      }
    }
  }

  int query(int u, int v) {
    if (depth[u] > depth[v]) swap(u, v);
    for (int i=LOG-1; i>=0; --i) {
      if (((depth[v] - depth[u]) >> i) & 1) v = table[i][v];
    }
    if (u == v) return u;
    for (int i=LOG-1; i>=0; --i) {
      if (table[i][u] != table[i][v]) {
        u = table[i][u];
        v = table[i][v];
      }
    }
    return table[0][u];
  }
};

vi dist;
vi euler;
vector<Graph> color;
int idx = 0;

void add(Graph &g, int idx, int move, int d) {
  g[0].push_back(idx);
  g[1].push_back(g[1].back() + move);
  g[2].push_back(g[2].back() + move * d);
  return;
}

void dfs(const vector<Graph> &edge, int v, int p, int d) {
  dist[v] = d;

  for (auto nv : edge[v]) {
    if (nv[0] != p) {
      ++idx;
      euler[nv[0]] = idx;
      add(color[nv[1]], idx, 1, nv[2]);

      dfs(edge, nv[0], v, d + nv[2]);

      ++idx;
      add(color[nv[1]], idx, -1, nv[2]);
    }
  }
}

int main() {
  int N, Q; cin >> N >> Q;
  vector<Graph> edge(N);
  rep(i,N-1) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    --a; --b;
    edge[a].push_back({b, c, d});
    edge[b].push_back({a, c, d});
  }

  dist.resize(N);
  euler.assign(N, 0);
  color.assign(N, Graph(3, vi(1, 0)));
  idx = 0;

  dfs(edge, 0, -1, 0);

  LowestCommonAncestor<vector<Graph>> lca(edge);
  lca.build();

  rep(i,Q) {
    int x, y, u, v;
    cin >> x >> y >> u >> v;
    --u; --v;

    int w = lca.query(u, v);

    int idx_u = upper_bound(all(color[x][0]), euler[u]) - color[x][0].begin();
    int idx_v = upper_bound(all(color[x][0]), euler[v]) - color[x][0].begin();
    int idx_w = upper_bound(all(color[x][0]), euler[w]) - color[x][0].begin();
    --idx_u; --idx_v; --idx_w;
    int du = dist[u] + color[x][1][idx_u] * y - color[x][2][idx_u];
    int dv = dist[v] + color[x][1][idx_v] * y - color[x][2][idx_v];
    int dw = dist[w] + color[x][1][idx_w] * y - color[x][2][idx_w];

    cout << du + dv - dw*2 << endl;
  }
  return 0;
}


Measured memory_bytes: 52196
from itertools import combinations
n = int(input())
march = dict()
for i in "MARCH":
    march[i] = 0
for i in range(n):
    s = input()[0]
    if s in march:
        march[s] += 1
# print(march)

ans = 0
for v in combinations(list("MARCH"), 3):
    tmp = 1
    for c in v:
        tmp *= march[c]
    ans += tmp

print(ans)

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

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	
	int n;
	cin>>n;
	vector<long long int> h(n);
	for(int i=0; i<n; i++) cin>>h[i];
	vector<long long int> dp(n, 0);
	for(int  i=1; i<n; i++){
		dp[i] = dp[i-1] + abs(h[i]-h[i-1]);
		if(i>1)
			dp[i] = min(dp[i], dp[i-2] + abs(h[i]-h[i-2]));
	}
	cout<<dp[n-1];
	return 0;
}

Measured memory_bytes: 1792
from collections import defaultdict as dd
from collections import deque
from collections import Counter as cnt
import bisect
n, m = map(int, input().split())
A = list(map(int, input().split()))
temoti_dic = cnt(A)

add_card_dic = dd(lambda: 0)
for i in range(m):
    b, c = map(int, input().split())
    add_card_dic[c] += b

temoti_dq = deque(sorted(temoti_dic.keys()))

total = 0
for add_card in sorted(add_card_dic.keys(), reverse=True):
    pointer = bisect.bisect_left(temoti_dq, add_card)
    #print(temoti_dic, temoti_dq, add_card, add_card_dic[add_card], pointer)
    if pointer == 0:
        break
    else:
        i = 0
        add_card_num = add_card_dic[add_card]
        while add_card_num > 0 and i < pointer:
            least_temoti = temoti_dq[0]
            least_temoti_num = temoti_dic[least_temoti]
            if least_temoti_num <= add_card_num:
                total += least_temoti_num * add_card
                temoti_dq.popleft()
                del temoti_dic[least_temoti]
                add_card_num -= least_temoti_num
            else:
                temoti_dic[least_temoti] -= add_card_num
                total += add_card_num * add_card
                add_card_num = 0
            i += 1

#print(temoti_dic)
for key in temoti_dq:
    total += key * temoti_dic[key]

print(total)

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

int main() {
  int H, W;
  cin >> H >> W;
  
  vector<vector<char>> score(H, vector<char>(W));
  
  
  
  vector<bool> flagH(H), flagW(W);
  
  for(int i=0; i<H; i++){
    flagH.at(i)=false;
  }
  
  for(int i=0; i<W; i++){
    flagW.at(i)=false;
  }
  
  for(int i=0; i<H; i++){
    for(int j=0; j<W; j++){
      
      cin >> score.at(i).at(j);
      if(score.at(i).at(j)=='#'){
        flagH.at(i)=true;
        flagW.at(j)=true;
      }
      
    }
  }
  
  for(int i=0; i<H; i++){
    
    if(flagH.at(i)){
      
      for(int j=0; j<W; j++){
        
        if(flagW.at(j)){
          
          cout << score.at(i).at(j);
        }
        
      }
      
      cout << endl;
    }
  }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		long a = sc.nextLong();
		long b = sc.nextLong();
		long g = gcm (a, b);
		int count = 1;
		long n = (long)Math.sqrt(g);
		n++;

		for(int i = 2; i <= n; i++) {
			if(g%i == 0) {
				while(g%i == 0) {
					g = g/i;
				}
				count++;
			}
		}

		if(g > 1) count++;

		System.out.println(count);
		sc.close();
	}
	private static long gcm(long a, long b) {
		if(a<b) return gcm(b, a);
		if(b ==0) return a;
		return gcm(b, a%b);
	}
}

Measured memory_bytes: 21844
#include<stdio.h>

int main(){

    int s,h,m;

    scanf("%d",&s);

    h=s/3600;
    m=(s-h*3600)/60;
    s=s-h*3600-m*60;
    printf("%d:%d:%d\n",h,m,s);

    return 0;

}


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

int main() {
    
    string S;
    
    cin >> S;
    
    int zero = 0;
    int one = 0;
    for (char ch: S) {
        if (ch == '0') {
            ++zero;
        } else {
            ++one;
        }
    }
    
    cout << 2 * min(one, zero) << endl;    
    
    return 0;
}

Measured memory_bytes: 512
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<functional>
#include<random>
#include<iostream>
using namespace std;

int main() {
	int N;
	int A[20];
	int x[100][100];
	int y[100][100];

	cin >> N;

	for (int i = 0; i < N; i++) {
		cin >> A[i];
		for (int j = 0; j < A[i]; j++) {
			cin >> x[i][j] >> y[i][j];
		}
	}
	int TF[20];

	int ans = 0;
	for (int i = 0; i < (1 << N); i++) {
		int p = i;

		int num_true = 0;
		for (int j = 0; j < N; j++) {
			TF[j] = (i >> j) & 1;
			if (TF[j] == 1) { num_true += 1; }
		}

		/*j番目の人の真偽がTF[j]だったとして、矛盾しないか*/
		int contradict = 0;
		for (int j = 0; j < N; j++) {
			if (TF[j] == 0) {
				continue;
			}
			for (int k = 0; k < A[j]; k++) {
				if (TF[x[j][k] - 1] != y[j][k]) {
					contradict = 1;
					break;
				}
			}
		}
		if (contradict == 0) {
			if (ans < num_true) {
				ans = num_true;
			}
		}
	}

	cout << ans << "\n";

}

Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    int n = s.length();
    int[] num = new int[n];
    for(int i = 0; i < n; i++) {
      num[i] = Integer.parseInt(String.valueOf(s.charAt(n - 1 - i)));
    }
    long ans = 0;
    for(int i = 0; i < (int)Math.pow(2, n); i++) {
      int p = 0;
      if((i & 1) == 0) {
        for(int j = 0; j < n; j++) {
          if((i & (1 << j)) != 0) {
            p = 0;
            ans += ((long)num[j] * (long)Math.pow(10, p));
            p++;
          } else {
            ans += ((long)num[j] * (long)Math.pow(10, p));
            p++;
          }
        }
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 22612
import java.util.*;


class Main{
    public static void main(String argv[]) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] V = new int[N];
        int[] C = new int[N];
        for(int i=0;i<N;i++){
            V[i] = sc.nextInt();
        }
        for(int i=0;i<N;i++){
            C[i] = sc.nextInt();
        }
        int result = 0;
        for(int i=0;i<N;i++){
            if(V[i]>C[i]){
                result += (V[i]-C[i]);
            }
        }
        System.out.println(result);
    }
}

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

bool judge(string s){
  int l = s.length();
  for(int i = 1; i < l; ++i){
    int a = s[i-1] - 'A', b = s[i] - 'A';
    if((a == b) || (a/3 == b/3 && abs(a-b) > 1) || (a%3 == b%3 && abs(a/3 - b/3) > 1) || (a%3 != b%3 && a/3 != b/3))
      return false;
  }
  return true;
}

int main(){
  int N = 1e3;

  for(int i = 0; i < N; ++i){
    string s;
    cin >> s;
    if(judge(s)) cout << s << endl;
  }
  return 0;
}



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

/* #pragma */
/*
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
*/

/*alias*/
#define F first
#define S second

#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define itn int

/*template*/
template<class T>inline bool amax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>inline bool amin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }

/* func */
int GCD(int a,int b){return b?GCD(b,a%b):a;}
long long GCD(long long a, long long b){return b ? GCD(b, a%b) : a;}
int LCM(int a, int b){return a * b / GCD(a, b);}
long long LCM(long long a, long long b){return a * b / GCD(a, b);}

/*struct*/
struct aaa {
	aaa() {
		cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20);
	};
}aaaaaaa;

/* const */
const int INF = 1001001001;
const long long LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7; //10^9
const double EPS = 1e-9;
const int dx[] = { 1, 1, 0, -1, -1, -1, 0, 1 }, dy[] = { 0, 1, 1, 1, 0, -1, -1, -1 };
//const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
//Counterclockwise from the 6o'clock direction
//Take the x-axis downward and the y-axis right

#define int long long

//g++ -std=c++14 -Wall --pedantic-errors -o template template.cpp
//chcp 65001

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

	if(a == 0){
		cout << b/x+1 << endl;
	}
	else{
		cout << b/x - (a-1)/x << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, ll> P;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

ll dp[2][222][10101];
int v[222];

int main(void){
	int n,w,i,j,k,p=0,q=1;
	ll ans = 0ll;
	cin >> n >> w;
	dp[p][0][0] = 1ll;
	for(i=0; i<n; ++i){
		cin >> v[i];
	}
	sort(v,v+n,greater<int>());
	for(i=0; i<n; ++i){
		for(j=0; j<=n; ++j){
			for(k=0; k<=w; ++k){
				dp[q][j][k] = 0ll;
			}
		}
		for(j=0; j<=i; ++j){
			for(k=0; k<=w; ++k){
				add_mod(dp[q][i+1][k],dp[p][j][k]);
				if(k+v[i]>w){
					continue;
				}
				add_mod(dp[q][j][k+v[i]],dp[p][j][k]);
			}
		}
		swap(p,q);
	}
	for(k=0; k<=w; ++k){
		add_mod(ans,dp[p][0][k]);
	}
	for(j=0; j<n; ++j){
		for(k=0; k<v[j]; ++k){
			add_mod(ans,dp[p][j+1][w-k]);
		}
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 34732
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<ll, ll, ll> T;

string o, e;

int main(void){
    
    cin >> o >> e;
    int idx1 = 0, idx2 = 0;
    for(int i = 1; i <= o.size() + e.size(); ++i){
        if(i % 2) printf("%c", o[idx1++]); 
        else printf("%c", e[idx2++]);
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define INF 0x3f3f3f3f 
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)
int main() {
    ll n,flag=0,i;
    cin>>n;
    string s;
    cin>>s;
    if(n%2==1)
    	flag=1;
    for(i=0;i<n/2;i++)
    	if(s[i]!=s[i+n/2])
    		flag=1;
    	if(flag==0)
    		cout<<"Yes";
    	else
    		cout<<"No";
    return 0;
}

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

int main(){
  int n; cin>>n;
  string s; cin>>s;
  int count_R=0;
  int tmp_W=0;
  rep (i,n) if (s[i]=='R') count_R++;
  rep(i,count_R){
    if (s[i]=='W') tmp_W++;
  }
  cout << tmp_W;
}

Measured memory_bytes: 3736
#include<stdio.h>
#define MAX 100
int swap(int *x,int *y)
{
  int z=*x;
  if(*x==*y)return 0;//同じだったら０
  *x=*y;
  *y=z;
  return 1;//違ったら１
}

//Aに代入された数をnまで並べ替えて、入れ直す
//　　　/交換回数
int bubbleSort(int *A, int n)
{
  int flag=1;
  int i,j;
  int count=0;//交換回数
  for (i=0;flag;i++){
    flag = 0;//一回も交換しない、 つまり既に並んんでいたら０

    for (j = n-1;j>=1;j--){
      if (A[j] < A[j-1])
	{
	  swap(&A[j],&A[j-1]);
	  count++;
	  flag=1;
	}
    }
  }
  return count;
}


int main(){
  int i;
  int A[MAX]; // need
  int n;
  int count;
  
  scanf("%d",&n);//Input
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
 
  count=bubbleSort(A,n);
  
  for(i=0;i<n;i++){//OUTPUT
    if(i)printf(" ");
    printf("%d",A[i]);
  }
  printf("\n%d\n",count);
  return 0;
}
/*5
1 2 3 4 5を昇順に並べ替える
出力はそれと、交換回数*/



Measured memory_bytes: 2112
package main

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

type Railway struct {
	trains trains
}

type trains []int

func main() {
	var stdin string
	var s = bufio.NewScanner(os.Stdin)

	railway := Railway{}
	for s.Scan() {
		stdin = s.Text()

		n, err := strconv.Atoi(stdin)
		if err != nil {
			continue
		}
		railway.lifo(n)
	}
}

func (r *Railway) lifo(n int) {
	if n == 0 {
		if len(r.trains) == 0 {
			return
		}
		fmt.Println(r.trains[len(r.trains)-1])
		r.trains = r.trains[:len(r.trains)-1]
	} else {
		r.trains = append(r.trains, n)
	}
}


Measured memory_bytes: 1096
package main

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

func getNextLine(scanner *bufio.Reader) string {
	var buffer string
	for {
		line, isPrefix, _ := scanner.ReadLine()
		buffer += string(line)
		if isPrefix == false {
			break
		}
	}
	return buffer
}

func getIntList(scanner *bufio.Reader) []int {
	list := strings.Split(getNextLine(scanner), " ")
	l := len(list)
	result := make([]int, l)
	for i := 0; i < l; i++ {
		result[i], _ = strconv.Atoi(list[i])
	}
	return result
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := bufio.NewReader(fp)
	writer := bufio.NewWriter(os.Stdout)

	var n, q, d int
	fmt.Sscan(getNextLine(scanner), &n, &q)
	stops := make(Stops, n)
	persons := make(Persons, q)
	for i := 0; i < n; i++ {
		stx := getIntList(scanner)
		stops[i].s = stx[0] - stx[2]
		stops[i].t = stx[1] - stx[2]
		stops[i].x = stx[2]
	}
	sort.Sort(stops)
	ans := make([]int, q)
	for i := 0; i < q; i++ {
		fmt.Sscan(getNextLine(scanner), &d)
		persons[i].i = i
		persons[i].d = d
		persons[i].next = i + 1
		ans[i] = -1
	}

	sort.Sort(persons)

	for i := 0; i < n; i++ {
		l := 0
		r := len(persons)
		for l < r {
			m := (l + r) / 2
			if persons[m].d < stops[i].s {
				l = m + 1
				continue
			}
			r = m
		}
		del := r
		for r < len(persons) && persons[r].d < stops[i].t {
			if ans[persons[r].i] == -1 {
				ans[persons[r].i] = stops[i].x
			}
			r = persons[r].next
		}
		for del < len(persons) && persons[del].d < stops[i].t {
			del, persons[del].next = persons[del].next, r
		}
	}
	for i := 0; i < q; i++ {
		fmt.Fprintln(writer, ans[i])
	}

	writer.Flush()
}

type Stop struct {
	s int
	t int
	x int
}

type Stops []Stop

func (a Stops) Len() int           { return len(a) }
func (a Stops) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a Stops) Less(i, j int) bool { return a[i].x < a[j].x }

type Person struct {
	d    int
	i    int
	next int
}
type Persons []Person

func (a Persons) Len() int           { return len(a) }
func (a Persons) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a Persons) Less(i, j int) bool { return a[i].d < a[j].d }


Measured memory_bytes: 25088
using System;
using System.Linq;

class Program
{
  /// <summary>
  ///   配列xから数値のペアを作り、小さい方を足していく。
  /// </summary>
  [STAThread]
  public static void Main(string[] args)
  {
    int n = int.Parse(Console.ReadLine());
    int[,] l = new int[n,2];
    int[] x = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
    Array.Sort(x);
    for (int i = 0; i < n; i ++)
    {
      l[i,0] = x[i * 2];
      l[i,1] = x[i * 2 + 1];
    }
    int sum = 0;
    for (int i = 0; i < n; i ++)
    {
      sum += Math.Min(l[i,0], l[i,1]);
    }
    Console.WriteLine(sum);
  }
}


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

using ll = long long;
using pii = pair<int, int>;
template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (int i = m; i < (n); i++)
#define per(i, b) per2(i, 0, b)
#define per2(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define ALL(c) (c).begin(), (c).end()
#define SZ(x) ((int)(x).size())

constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }

template <class T, class U>
void chmin(T& t, const U& u) {
    if (t > u) t = u;
}
template <class T, class U>
void chmax(T& t, const U& u) {
    if (t < u) t = u;
}

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

template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "{";
    rep(i, v.size()) {
        if (i) os << ",";
        os << v[i];
    }
    os << "}";
    return os;
}

#ifdef LOCAL
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << H;
    debug_out(T...);
}
#define debug(...) \
    cerr << __LINE__ << " [" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif

int main() {
    string s;
    int N;
    cin >> N >> s;
    V<int> vl(N + 1), vr(N + 1);
    rep(i, N) { vl[i + 1] = vl[i] + (s[i] == 'W'); }
    per(i, N) { vr[i] = vr[i + 1] + (s[i] == 'E'); }
    int ans = N;
    rep(i, N) { chmin(ans, vl[i] + vr[i + 1]); }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3076
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i, x, n) for (int i = x; i < (int)(n); ++i)

int n;
vector<int> tr[100001];
char cl[100001];

int pl(int v = 1, int p = 0, int d = 1){
	if (v == n)return d;
	f(i, 0, tr[v].size()){
		int u = tr[v][i];
		if (u == p)continue;
		int t = pl(u, v, d + 1);
		if (t == 0)continue;
		if (d <= (t + 1) >> 1)cl[v] = 1; else cl[v] = 2;
		return t;
	}
	return 0;
}

int C;
void go(int v, int p = 0){
	cl[v] = C;
	f(i, 0, tr[v].size()){
		int u = tr[v][i];
		if (u == p)continue;
		if (cl[u] != (C ^ 3))go(u, v);
	}
}

int main(){
	scanf("%d", &n);
	f(i, 1, n){
		int a, b;
		scanf("%d%d", &a, &b);
		tr[a].push_back(b);
		tr[b].push_back(a);
	}
	cl[1] = 1;
	cl[n] = 2;
	pl();
	C = 1;
	go(1);
	C = 2;
	go(n);
	int a = 0, b = 0;
	f(i, 1, n + 1)if (cl[i] == 1)++a; else ++b;
	printf("%s\n", a > b ? "Fennec" : "Snuke");
}

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

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<(o)<<" ";}
#define dumpl(o) if(DBG){cerr<<#o<<" "<<(o)<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

signed main() {
	cout << fixed << setprecision(7);
	double p[110][110];
	bool Lose[110], Back[110];
	for (int N, T, L, B; cin >> N >> T >> L >> B&&N;) {
		fill(p[0], p[110], 0);
		memset(Lose, 0, sizeof(Lose));
		memset(Back, 0, sizeof(Back));
		rep(i, 0, L) { int l; cin >> l; Lose[l] = true; }
		rep(i, 0, B) { int b; cin >> b; Back[b] = true; }
		p[0][0] = 1;
		rep(t, 0, T) {
			rep(i, 0, N) {
				rep(j, 1, 7) {
					int to = i + j;
					if (to > N)to = 2 * N - to;
					if (Back[to])p[t + 1][0] += p[t][i] / 6;
					else if(Lose[to])p[t + 2][to] += p[t][i] / 6;
					else p[t + 1][to] += p[t][i] / 6;
				}
			}
		}
		double ans = 0;
		rep(t, 0, T + 1) {
			ans += p[t][N];
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3224
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/














int W, H, x, y;
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> W >> H >> x >> y;

	double ans1 = 1.0 * W * H / 2;
	int ans2 = 0;
	if (x * 2 == W and y * 2 == H) ans2 = 1;

	printf("%.6f %d\n", ans1, ans2);
}







Measured memory_bytes: 256
N, X = map(int, input().split())
L = list(map(int, input().split()))



cnt = 0
x = 0
for length in L:
    #print(cnt, x)
    if x <= X:
        cnt += 1
        x += length
    else:
        break
else:
    if x <= X:
        cnt += 1


print(cnt)
    


Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<unordered_map>

using namespace std;
int n,m;
char s[233];
unordered_map<string,long long> mp[233];//mp[len]:Hashval->cnt
int main()
{
	scanf("%d %s",&n,s+1);
	for(int st=0;st<(1<<n);st++)
	{
		string h;
		int cntl=0;
		for(int b=0;b<n;b++)
		{
			if(st&(1<<b))
				h+=s[b+1],cntl++;
		}
		for(int b=n-1;b>=0;b--)
		{
			if(!(st&(1<<b)))
				h+=s[b+1];
		}
//		cout<<"state = "<<st<<", hash = "<<h<<endl;
		mp[cntl][h]++;
//		cout<<"subhash "<<cntl<<' '<<h<<endl;
	}
	long long ans=0;
	for(int st=0;st<(1<<n);st++)
	{
		string h;
		int cntr=0;
		for(int b=n-1;b>=0;b--)
		{
			if(!(st&(1<<b)))
				h+=s[b+n+1];
		}
		for(int b=0;b<n;b++)
		{
			if(st&(1<<b))
				h+=s[b+n+1],cntr++;
		}
//		cout<<"state = "<<st<<", hash = "<<h<<endl;
		ans+=mp[n-cntr][h];
//		cout<<"subhash "<<n-cntr<<' '<<h<<' '<<mp[n-cntr][h]<<endl;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 72372
// B. 

#include <iostream>
#include <algorithm>
#include <sstream>
#include <cstdio>
#include <cstring>

using namespace std;

typedef long long LL;

int main(int argc, char *argv[])
{
	int N, a[100000], ans = 0;
	cin >> N;
	for (int i = 0; i < N; ++i) {
		cin >> a[i];
	}
	sort(a, a + N);
	LL tot = 0;
	for (int i = 0; i < N; ++i) {
		if (tot * 2 < a[i]) {
			ans = 0;
		}
		++ans;
		tot += a[i];
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 640
////////////////////////// Author
////////////////////////// Nasim Hossain Rabbi
////////////////////////// JU-CSE28
////////////////////////// CF - imnasim3.1415
////////////////////////// UVA - imnasim3.1415
////////////////////////// Mail - imnasim3.1415@gmail.com

#include<bits/stdc++.h>
using namespace std;
#define sz size()
#define mk make_pair
#define clr clear()
#define B begin()
#define E end()
#define EM empty()
#define mem(a,b) memset(a,b,sizeof(a))
#define rep(i,n) for(i=0;i<n;i++)
#define Rep(i,n) for(i=1;i<=n;i++)
#define all(cont) cont.begin(),cont.end()
#define pb push_back
#define endl '\n'
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL)
#define pi 3.1415926535897932384626433832795
#define vi vector<int>
#define vs vector<string>
#define vp(vi,x) cin>>x; vi.pb(x);
typedef long long int LL;
typedef unsigned long long int ULL;
int main()
{
    fast;
    int i,j,k,n,m,l,s=0,x,y,tc=1,c=0;
    while(cin>>n)
    {
        c=0;
        rep(k,n)
        {
        cin>>i>>j;
        c+=(abs(i-j))+1;
        }
        cout<<c<<endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long int
#define pb push_back
#define fi first
#define se second
#define ld long double
#define vi vector<vector<ll> >
using namespace std;
const int MOD=1000000007;
const int MOD2=15000007;
const ll MAX=9187201950435737471;
const int N=100005;
const int INF=1e17;
const long double PI=acos(-1);



void solve(int T){
    ll a,b;
    cin>>a>>b;
    ll x=__gcd(a,b);
    cout<<(a*b)/x<<"\n";
}

int main() {
    fastio
    int T=1;
    //cin>>T;
    for(int i=1;i<=T;i++){
        solve(i);
        //if(i<T)cout<<"\n";
    }
    return 0;
}





Measured memory_bytes: 3660
#include <iostream>
#include <vector>
#include <map>
#include <stack>
#include <list>
#include <queue>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <math.h>

#define PREP(i, m, n) for(int i = m; i < n; i++)
#define MREP(i, m, n) for(int i = m - 1; i >= n; i--)
using namespace std;

const int dirX[] = {-1, 0, 1, 0};
const int dirY[] = {0, -1, 0, 1};

struct point{
	int x;
	int y;
	point(int x = 0, int y = 0):x(x), y(y){}
};

int wideSearch(point start, vector<string> &map){
	int count = 1;
	queue<point> usablepos;
	usablepos.push(start);
	while(1){
		if(usablepos.size() == 0) break;
		point current = usablepos.front();
		usablepos.pop();
		for(int i = 0; i < 4; i++){
			if((current.y + dirY[i] >= 0 && current.y + dirY[i] < map.size()) && (current.x + dirX[i] >= 0 && current.x + dirX[i] < map[0].size())){
				if(map[current.y + dirY[i]][current.x + dirX[i]] == '.'){
					map[current.y + dirY[i]][current.x + dirX[i]] = '#';
					point tmp(current.x + dirX[i], current.y + dirY[i]);
					count++;
					usablepos.push(tmp);
				}
			}
		}
	}
	return count;
}

int main(){
	int w = 0, h = 0;
	while(cin >> w >> h && (w != 0 || h != 0)){
		vector<string> map;
		point start;
		string input;
		for(int i = 0; i < h; i++){
			cin >> input;
			map.push_back(input);
			for(int j = 0; j < w; j++){
				if(map[i][j] == '@'){
					start.x = j;
					start.y = i;
				}
			}
		}
		cout << wideSearch(start, map) << endl;
	}
	return 0;
}

Measured memory_bytes: 1236
/*

*/
#include<iostream>
#include<iomanip>
#include<ios>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<string>
#include<algorithm>
#include<utility>
#include<math.h>
#include<cstdlib>
#define rep(i, n) for(int i=0;i<n;i++)
#define repb(i, a, b) for(int i=a;i<b;i++)
#define MAX_N 10000

using namespace std;
typedef pair<int, int> P;
typedef long long int ll;

const int INF = 1<<30;
const ll MOD = ll(1e9+7);

int main(){
  int n;cin>>n;
  vector<int> l(n);
  vector<int> bigger(2000+2, 0);
  rep(i, n){
    cin>>l[i];
    bigger[l[i]]++;
  }
  for(int i=2000;i>=0;i--){
    bigger[i]+=bigger[i+1];
  }
  ll ans=0LL;
  rep(i, n){
    rep(j, i){
      int M=l[i]+l[j], m=abs(l[i]-l[j]); // m<k<M
      int ret = bigger[m+1]-bigger[M];
      ret -= int(l[i]>=m+1)+int(l[j]>=m+1);
      ans += max(ret, 0);
      // cout<<l[i]<<" + "<<l[j]<<" -> "<<ret<<" triangles"<<endl;
    }
  }
  cout<<ans/3<<endl;
  // system("read -n 1 -s -p \"Press any key to continue...\"");
}


Measured memory_bytes: 256
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int main(){
    int N,L;
    int ansi;
    cin >> N >> L;
    if(L*(L+N-1)<=0){
        ansi = (L+(L+N-1))*N/2;
    }else{
        if(abs(L)>abs(L+N-1)){
            ansi = (L+(L+N-1))*N/2-(L+N-1);
        }else{
            ansi = (L+(L+N-1))*N/2-L;
        }
        
    }
    cout << ansi << endl;
    

    // if(ans){
    //     cout << "Good" << endl; 
    // }else{
    //     cout << "Bad" << endl;
    // }
}

Measured memory_bytes: 256
k = int(input())
s = input()
n = len(s)
mod = 10 ** 9 + 7

f = [1, 1]
f_inv = [1, 1]
inv = [0, 1]
 
for i in range(2, n+k+1):
    f.append((f[-1] * i ) % mod)
    inv.append((-inv[mod % i] * (mod // i) ) % mod)
    f_inv.append((f_inv[-1] * inv[-1]) % mod)

def comb(n, k):
    return f[n] * f_inv[k] * f_inv[n-k] % mod

ans = 0
for i in range(k+1):
    x = pow(25, i, mod) * pow(26, k-i, mod) * comb(n-1+i, n-1)
    ans += x
    ans %= mod

print(ans)

Measured memory_bytes: 197196
// Problem : B - Substring
// Contest : AtCoder - AtCoder Beginner Contest 177
// URL : https://atcoder.jp/contests/abc177/tasks/abc177_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define int long long
#define db double
#define mod 1000000007
#define pb push_back
#define pp pair<int,int>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repe(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=b;i>=a;i--)
#define maxn 200005
#define ss second
#define ff first
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
int inv(int a, int b){
 return 1<a ? b - inv(b%a,a)*b/a : 1;
}
void solve()
{
	string s,t;
	cin >> s >> t;
	int n = s.size(),m = t.size();
	int ans = maxn;
	for(int i=0;i<s.size();i++)	
	{
		if(i+m <= n)
		{
			int tmp = 0;
			for(int j=i;j<i+m;j++)
				if(s[j] != t[j-i])
					tmp++;
			ans = min(ans,tmp);
		}
	}
	cout << ans;
}
signed main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1;
    //cin >> t;
    while(t--)
    solve();
    return 0;
}


Measured memory_bytes: 3648
#include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<set>
#include<queue>
#include<map>
#define debug(a) cout << "*" << a << "*" << endl
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
int n, m, mod = 25610;
int x, a[85][85];
int dp[2][85][25615], b[2][25615];
int main()
{   
	while (scanf("%d%d", &n, &m) != EOF)
	{
		memset(a, 0, sizeof(a));
		memset(dp, 0, sizeof(dp));
		dp[0][1][0] = true;
		for (int i = 1; i <= n; i++)
		{
			for (int j = 1; j <= m; j++)
			{
				scanf("%d", &a[i][j]);
			}
		}
		for (int i = 1; i <= n; i++)
		{
			for (int j = 1; j <= m; j++)
			{
				scanf("%d", &x);
				a[i][j] = abs(a[i][j] - x);
			}
		}
		for (int i = 1; i <= n; i++)
		{
			for (int j = 1; j <= m; j++)
			{
				int z = 0, w = 0, k = 0, l = 0;
				while (z < dp[(i + 1) & 1][j][mod] && w < dp[i & 1][j - 1][mod])
				{
					if (dp[(i + 1) & 1][j][z] > dp[i & 1][j - 1][w])
						dp[i & 1][j][k++] = dp[i & 1][j - 1][w++];
					else if (dp[(i + 1) & 1][j][z] < dp[i & 1][j - 1][w])
						dp[i & 1][j][k++] = dp[(i + 1) & 1][j][z++];
					else
						dp[i & 1][j][k++] = dp[(i + 1) & 1][j][z++], w++;
				}
				while (z < dp[(i + 1) & 1][j][mod]) dp[i & 1][j][k++] = dp[(i + 1) & 1][j][z++];
				while (w < dp[i & 1][j - 1][mod]) dp[i & 1][j][k++] = dp[i & 1][j - 1][w++];
				for (int h = 0; h < k; h++)	b[0][h] = dp[i & 1][j][h] - a[i][j];
				for (int h = 0; h < k; h++)	b[1][h] = dp[i & 1][j][h] + a[i][j];
				z = 0, w = 0;
				while (z < k && w < k)
				{
					if (b[0][z] > b[1][w])
						dp[i & 1][j][l++] = b[1][w++];
					else if (b[0][z] < b[1][w])
						dp[i & 1][j][l++] = b[0][z++];
					else
						dp[i & 1][j][l++] = b[0][z++], w++;
				}
				while (z < k)	dp[i & 1][j][l++] = b[0][z++];
				while (w < k)	dp[i & 1][j][l++] = b[1][w++];
				dp[i & 1][j][mod] = l;
				if (i == 1 && j == 1)
				{
					dp[i & 1][j][0] = -a[i][j];
					dp[i & 1][j][1] = a[i][j];
					dp[i & 1][j][mod] = 2;
				}
			}
		}
		int mx = mod;
		for (int i = 0; i < dp[n & 1][m][mod]; i++)
		{
			if (mx > abs(dp[n & 1][m][i]))	mx = abs(dp[n & 1][m][i]);
		}
		printf("%d\n", mx);
	}
}

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

const int N = 4010;

int n,x;
int a[N],b[N][N];

int main() {
  scanf("%d%d",&n,&x);
  REP(i,n) scanf("%d", &a[i]), a[i+n] = a[i];

  REP(i,n) {
    b[i][i] = a[i];
    for(int j=i+1;j<n+n;j++) b[i][j] = min(b[i][j-1], a[j]);
  }
  ll ans = 9e18;
  REP(s,n) {
    ll cur = 1ll * s * x;
    REP(i,n) cur += b[i][s+i];
    ans = min(ans, cur);
  }
  printf("%lld\n", ans);

  return 0;
}


Measured memory_bytes: 33024
#include <iostream>
    #include <vector>
    #include <algorithm>
    using namespace std;
    int main(){
      int n,x;cin>>n>>x;
      vector<int> a;
      for(int i = 0; n > i; i++){
        int tmp;cin>>tmp;
        a.push_back(tmp);
      }
      sort(a.begin(),a.end());
      int ret = 0;
      for(int i = 0; n > i; i++){
      	if(x >= a[i]){
          ret++;
          x-=a[i];
        }
      }
      if(ret==n && x > 0)ret--;
      cout << ret << endl;
    }

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define debug(x) cerr<<#x<<' '<<x<<'\n'
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
const int maxn=2e5+10;
const int mod=1e9+7;
const int inf=0x3f3f3f3f;
ll ans=0,num=1,h;
int main()
{
    ios::sync_with_stdio(false);cin.tie(0);
    cin>>h;
    while(h) {
        ans+=num;
        num<<=1;
        h>>=1;
    }
    cout<<ans<<'\n';
    return 0;
}



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

using namespace std;

class KatanaDamage {
    public:
        int val;
        bool throwing;

        KatanaDamage(int v, bool t): val(v), throwing(t) {

        }

        bool operator<(const KatanaDamage& rhs) const {
            return val < rhs.val;
        }

        bool operator>(const KatanaDamage& rhs) const {
            return val > rhs.val;
        }
};

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

    vector<KatanaDamage> vec(N*2, KatanaDamage(0, false));

    for(int i=0; i<N; i++) {
        int a, b;
        cin >> a >> b;
        vec[i*2].val = a;
        vec[i*2+1].val = b;
        vec[i*2+1].throwing = true;
    }

    sort(vec.begin(), vec.end());
    int ans = 0;
    while(H > 0) {
        KatanaDamage& kd = vec.back();
        if(kd.throwing) {
            ans++;
            H -= kd.val;
            vec.pop_back();
        } else {
            if(H % kd.val == 0) {
                ans += H / kd.val;
            } else {
                ans += H / kd.val + 1;
            }
            break;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <bitset>
#include <cmath>
#include <algorithm>
#include <map>

using namespace std;
typedef long long ll;

const long long MOD = 1e9 + 7;

vector<string> s;

int main()
{
    ll n;
    ll ans = 0;
    ll endsA = 0, begsB = 0, all = 0;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        string c;
        cin >> c;
        s.push_back(c);
        for (int j = 0; j + 1 < c.size(); j++)
        {
            if (c[j] == 'A' && c[j + 1] == 'B')
                ans++;
        }
        if (c[0] == 'B')
            begsB++;
        if (c[c.size() - 1] == 'A')
            endsA++;
        if (c[0] == 'B' && c[c.size() - 1] == 'A')
            all++;
    }
    long long onlyA = endsA - all;
    long long onlyB = begsB - all;
    if (onlyA >= 1 && onlyB >= 1)
    {
        ans += all + 1;
        onlyA--;
        onlyB--;
        cout << ans + min(onlyA, onlyB);
    }
    else
    {
        if (onlyA + onlyB >= 1)
        {
            cout << ans + all;
        }
        else
        {
            cout << max(ans, ans + all - 1);
        }
    }
}


Measured memory_bytes: 768
function main()
N,M = parse.(Int,split(readline()))
H = parse.(Int,split(readline()))
  
ok_list = zeros(Int,N)
for i in 1:M
    a,b = parse.(Int,split(readline()))
    if H[a] == H[b]
        ok_list[a] = 1
        ok_list[b] = 1
    elseif  H[a] > H[b]
        ok_list[b] = 1
    else
        ok_list[a] = 1
    end
end




println(N - sum(ok_list))


end

main()


Measured memory_bytes: 203952
//include
//------------------------------------------
#include <bits/stdc++.h>
using namespace std;
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
// chmax chmin
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main(void){

    int N,T;
    cin >> N >> T;
    int A[N];
    REP(i,N) cin >> A[i];

    pair<int,int> p;
    p.first = A[N-1]-A[N-2]; p.second = 1;

    int mx = A[N-1];
    for(int i=N-3; i>=0; i--){
        if(mx-A[i] > p.first){
            p.first = mx-A[i];
            p.second = 1;
        }
        else if(mx-A[i] == p.first) p.second++;
        if(mx < A[i]) mx = A[i];
    }

    cout << p.second << endl;
    return 0;
}

Measured memory_bytes: 640
from itertools import accumulate

N, K, *A = map(int, open(0).read().split())

for _ in range(min(K, 41)):
    B = [0] * (N + 1)
    for x, d in enumerate(A):
        B[max(0, x - d)] += 1
        B[min(N, x + d + 1)] -= 1
    A = accumulate(B)

print(*list(A)[:-1])

Measured memory_bytes: 141528
#include <stdio.h>

int main(){
    long    n, m, a;
    scanf("%ld %ld", &n, &m);

    for(int i=0; i<m; i++){
        scanf("%ld", &a);
        n -= a;
        if( n < 0 ){ printf("-1\n"); return 0; }
    }
    printf("%ld\n", n);
    return 0;
}

Measured memory_bytes: 1728
N = int(input())
S = input()

# r: (
# l: )

# '(' をいくつ足せばよいか？
ans_r, r = 0, 0
for i in range(N):
    if S[i] == ')':
        if r >= 1:
            r -= 1
        else:
            ans_r += 1
    else:
        r += 1

# ')' をいくつ足せばよいか？
ans_l, l = 0, 0
for i in range(N):
    if S[N-1-i] == '(':
        if l >= 1:
            l -= 1
        else:
            ans_l += 1
    else:
        l += 1

print('('*ans_r + S + ')'*ans_l)


Measured memory_bytes: 38384
/*
        Author  : Malisetti Samrat
*/

#pragma GCC optimize ("O3")
#pragma GCC optimize("Ofast")
#include   <bits/stdc++.h>
#include   <algorithm>
#include   <queue>
#include   <list>
#include   <map>
#include   <math.h>
#include   <numeric>
#include   <iomanip>
using      namespace        std;
#define    endl             '\n'
#define    FAST             ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define    ipfile           ifstream cin ("input.txt");std::cin.rdbuf(std::cin.rdbuf())
#define    pb(x)            push_back(x)
#define    int              long long int
#define    ull              unsigned long long int
#define    db               long double
#define    mod              1000000007
#define    vll              vector<int>
#define    all(v)           v.begin(),v.end()
#define    GCD(m,n)         __gcd(m,n)
#define    LCM(m,n)         m*(n/GCD(m,n))
#define    REVVEC(v)        reverse(v.begin(),v.end())
#define    REVARR(a)        reverse(a,a+n)
#define    maxc(v)          max_element(all(v))
#define    minc(v)          min_element(all(v))
#define    inputarr(a,n)    for(int xxx=0;xxx<n;++xxx) cin>>a[xxx]
#define    outputarr(a,n)   for(int xxx=0;xxx<n;xxx++) cout<<a[xxx]<<" "
#define    rep(i,m, n)      for(int i = m; i < (n); ++i)
#define    sp               setprecison(10)
#define    sz(v)            v.size()
#define    len(s)           s.length()

clock_t time_p = clock();
void time()
{
  time_p = clock() - time_p;
  cerr << "Time elapsed : " << (double)(time_p)/CLOCKS_PER_SEC <<endl;
}


void TestCase3()
{
    
    int a,b,c;
    cin>>a>>b>>c;
    if(a==b and a!=c)
    cout<<"Yes\n";
    else if(c==b and a!=c)
    cout<<"Yes\n";
    else if(a==c and b!=c)
    
    cout<<"Yes\n";
    
    else
    cout<<"No\n";
    
}

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

  // int T; cin>>T; while( T -- > 0){

    TestCase3();
  	
    //}
    time();
	return 0;
}

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

int main(){
	// sengen
	int h,w;
	// nyuryoku
	cin >> h >> w;
	char s[h][w];
	int count = 0;
	int dist[h][w];
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			cin >> s[i][j];
			dist[i][j] = -1;
			if(s[i][j] == '.'){
				count++;
			}
		}
	}
	int dx[4] = {-1,1,0,0};
	int dy[4] = {0,0,-1,1};
	// keisan
	queue<pair<int,int>> que;
	que.emplace(0,0);
	dist[0][0] = 1;
	while(!que.empty()){
		pair<int,int> now = que.front();
		que.pop();
		for(int i=0;i<4;i++){
			int nx = now.first + dx[i];
			int ny = now.second + dy[i];
			if(nx<0 || ny<0 || nx>h-1 || ny>w-1) continue;
			if(s[nx][ny] == '#') continue;
			if(dist[nx][ny] == -1){
				dist[nx][ny] = dist[now.first][now.second] +1;
				que.emplace(nx,ny);
			}
		}
	}
	// syutsuryoku
	if(dist[h-1][w-1] == -1){
		cout << "-1";
	}else{
		cout << count - dist[h-1][w-1];
	}
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<iomanip>
using namespace std;
#define pi 3.141592653589793283462
int main(){
	int a,b,c;
     cin>>a>>b>>c;
	 if(a<b){
		 if(b<c)
             cout<<"Yes"<<endl;
		 else 
			  cout<<"No"<<endl;
	 }
	 else
		  cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 1156
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/stack:256000000")
#include<utility>
#include<iostream>
#include<vector>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<functional>
#include<random>
#include<climits>
#include<queue>
#include<stack>
#include<deque>
#include<bitset>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<cassert>
#include<ccomplex>

//4Head
#define all(x) x.begin(), x.end()
#define mp make_pair
#define X first
#define Y second

using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
mt19937_64 gen(time(NULL));

// belik's shit
ll const mod = 1e9 + 7;
namespace {
	ll mult(ll& a, ll& b) {
		ll val = a * b - (ll)((ld)a * b / mod) * mod;
		if (val < 0) {
			val += mod;
		}
		if (val >= mod) {
			val -= mod;
		}
		return val;
	}
	ll poww(ll a, ll b)
	{
		ll val = 1;
		a %= mod;
		while (b > 0){
			if (b % 2) val = mult(a, val);
			a = mult(a, a);
			b >>= 1;
		}
		return val % mod;
	}
	ll inv(ll a) {
		return poww(a, mod - 2);
	}
}

ll const maxn = 5e5 + 5;

signed main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	ll l, r; cin >> l >> r;
	r = min(r, l + 2020);
	ll ans = LLONG_MAX;
	for (ll i = l; i < r; i++) {
		for (ll j = i + 1; j <= r; j++) {
			ans = min(((i % 2019) * (j % 2019)) % 2019, ans);
		}
	}
	cout << ans;
	return 0;
}
/*

*/

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long int LL;
typedef long double dd; 
#define endl "\n"
int dx[4]={1,-1,0,0};
int dy[4]={0,0,-1,1};
LL dp[2000001];
LL mod=1e9+7;
using namespace std;
bool isPrime(LL n) {
  LL j; 
  for( j=2;j<=sqrt(n);j++){
    if(n%j==0){
      break;  
    } 
  }
  if(j>sqrt(n)){
    return 1; 
  }
  else{
    return 0; }
}
void solve(LL k){
LL n, x, t; 
cin>>n>>x>>t;
LL c=n/x;
if(n%x!=0){
 c+=1;
}
cout<<c*t<<endl; 
 }
int main(){
  ios_base::sync_with_stdio(false);
    cin.tie(NULL);
 LL t=1;
//cin>>t;
 LL k=1;
while(k<=t){
   solve(k);
  k++;
  }
   return 0;
   }

Measured memory_bytes: 3664