akhauriyash/Code-Regression huggingface dataset:
#include <iostream>

using namespace std;

int main() {
    int a[100];
    
    int n;
    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> a[i];
    
    int low = 0;
    int high = n - 1;
    while (low < high) {
        int t = a[low];
        a[low] = a[high];
        a[high] = t;
        low++;
        high--;
    }
    
    for (int i = 0; i < n; i++) {
        if (i < n - 1)
            cout << a[i] << " ";
        else
            cout << a[i] << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ok() puts(ok?"Yes":"No");
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef set<int> si;
typedef map<string, int> msi;
typedef greater<int> gt;
typedef priority_queue<int, vector<int>, gt> minq;
typedef long long ll;
typedef pair<ll,ll> pll;
const ll LINF = 1e18L + 1;
const int INF = 1e9 + 1;
//clang++ -std=c++11 -stdlib=libc++ 

int main() {
  int n,m,x; cin >> n >> m>>x;
  vi cost(n);
  vvi a(n, vi(m,0));
  rep(i, n) {
    cin >> cost[i];
    rep(j, m) {
      cin >> a[i][j];
    }
  }
  int ans = INF;
  auto f = [&](vi u) {
    for(int num : u) {
      if (num<x) return false;
    }
    return true;
  };
  for (int i=0; i<(1<<n); i++) {
    int price = 0;
    vi understanding(m,0);
    for (int j=0; j<n; j++) {
      if ((i>>j)&1) {
        price+=cost[j];
        rep(k,m) {
          understanding[k] += a[j][k];
        }
      } 
    }
    if (f(understanding)) ans = min(ans, price);
  }
  if (ans == INF) ans = -1;
  cout << ans << endl;
  return 0;
}

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

typedef pair<int,int>pii;
#define MOD 1000000007
#define MAXN 105
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
#define ll long long
#define pb push_back
#define f first
#define s second
#define debug(x) cout << "debug 1: " << x << "\n";
#define debug2(x, y) cout << "debug 2: " << x << " " << y << "\n";
#define debug3(x, y, z) cout << "debug 3: " << x << " " << y << " " << z << "\n";

bool comp(int a,int b){
    return a>b;
}

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n,v[MAXN],ok=0,tot=0;

    double m,d;

    cin>>n>>m;

    for(int i=0;i<n;i++){
        cin>>v[i];
        tot+=v[i];
    }
    sort(v,v+n,comp);

    d=ceil((tot/(4*m)));


    for(int i=0;i<m;i++){
        if(v[i]<d){
            ok=1;
            break;
        }
    }

    if(ok==1)cout<<"No";
    else cout<<"Yes";
}


Measured memory_bytes: 256
#[allow(unused_imports)]
use itertools::Itertools;
#[allow(unused_imports)]
use num::*;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::collections::*;

pub struct Graph {
    graph: Vec<Vec<usize>>,
    v: usize,
}

type Edge = (usize, usize);
impl Graph {
    pub fn new(edges: &[Edge], v: usize) -> Self {
        let mut graph = vec![Vec::new(); v];
        for &(u, v) in edges {
            graph[u].push(v);
            graph[v].push(u);
        }
        Self { graph, v }
    }

    pub fn shortest_path(&self, start: usize, pv: &[usize]) -> Vec<Option<usize>> {
        let mut cost_list = vec![None; self.v];
        let mut que = std::collections::VecDeque::new();
        cost_list[start] = Some(pv[start]);
        que.push_back(start);
        while let Some(u) = que.pop_front() {
            for &v in &self.graph[u] {
                if cost_list[v].is_some() {
                    continue;
                }
                let new_cost = cost_list[u].unwrap() + pv[v];
                cost_list[v] = Some(new_cost);
                que.push_back(v);
            }
        }
        cost_list
    }
}

fn main() {
    input! {
        n: usize, q: usize,
        edges: [(Usize1, Usize1); n - 1],
        queries: [(Usize1, usize); q]
    };

    let mut pv = vec![0; n];
    for (p, x) in queries {
        pv[p] += x;
    }
    let graph = Graph::new(&edges, n);
    let res = graph.shortest_path(0, &pv);
    println!("{}", res.into_iter().map(|o| o.unwrap()).join(" "));
}


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

struct Problem {

    ULL dp[2001][2001] = {};

    void Solve() {
        LL N; cin >> N;
        vector<pair<ULL, LL>> A(N); 
        rep(i, N) {
            ULL a; cin >> a;
            A[i] = { a, i };
        }
        LL l = 0, r = N - 1;
        sort(A.rbegin(), A.rend());
        rep(i, N) {
            for (UL s = 0; s <= i; s++) {
                dp[s][s + N - i - 1] = max(dp[s][s + N - i - 1],
                    dp[s][s + N - i] + (A[i].first * abs(LL(s + N - i - 1 - A[i].second))));
                dp[s + 1][s + N - i] = max(dp[s + 1][s + N - i],
                    dp[s][s + N - i] + (A[i].first * abs(LL(s - A[i].second))));
            }
        }
        ULL ans = 0;
        rep(i, N + 1) ans = max(ans, dp[i][i]);
        cout << ans << endl;
    }
};
int main() {
    unique_ptr<Problem> p(new Problem());
    p->Solve();
    return 0;
}


Measured memory_bytes: 34620
#include <stdio.h>
#include <iostream>
#include <string>
#include <cstdlib>
#include <sstream>
#include <cstring>
#include <stdexcept>
#include <vector>
using namespace std;


#define abs(N) ((N>0)?N:-1*N)
#define lt(A,B) ((A>B)?B:A)
#define gt(A,B) ((A<B)?B:A)
#define print(S) (cout << S)
#define println(S) (cout << S << endl)
#define ll long long int

int main(){
	int n,q;
	cin >> n;
	ll S[n+1];
	for (int i = 0; i < n; ++i) {
		cin >> S[i];
	}
	cin >> q;
	int cnt=0;
	for (int i = 0; i < q; ++i) {
		ll Q;
		cin >> Q;
		int j=0;
		S[n] = Q;
		while(S[j]!=Q){
			j++;
		}
		if(j!=n) cnt++;
	}
	println(cnt);

	return 0;
}



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

using namespace std;

int main(){
    int n,k,l[50];
    cin >> n >> k;
    for(int i = 0;i < n;i++)cin >> l[i];
    sort(l,l + n,greater<int>());
    int ans = 0;
    for(int i = 0;i < k;i++)ans += l[i];
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
c[100][100];
n,m;
u,t,l,x,y;
main(){
	while(scanf("%d%d",&n,&m),n){
		int d[100]={0};

		memset(c,9,40000);
		for(;m--;){
			scanf("%d,%d,%d",&u,&l,&t);
			c[u][l]=c[l][u]=t/100-1;
		}

		x=y=l=0;
		for(u=n;u>0;){
			d[x]=1;
			l+=y;
			u--;
			y=x[*c]=**c;
			for(m=0;m<n;m++){
				if(!d[m]){
					if(c[x][m]<m[*c])
						m[*c]=c[x][m];
				}
				if(m[*c]<y){
					t=m;
					y=m[*c];
				}
			}
			x=t;
		}
		printf("%d\n",l);
	}
	exit(0);
}

Measured memory_bytes: 0
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

bool comp(const P &a, const P &b){
    if(a.first * b.first <= 0){
        return a.first > b.first;
    }
    if(a.first + b.first >= 0) return a.second > b.second;
    return a.second < b.second;
}

string s[1000006];
ll m[1000006];
P p[1000006];

int main()
{
    int n;
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> s[i];
        ll k = s[i].size();
        ll l = 0;
        for(int j = 0; j < k; j++){
            if(s[i][j] == '(') l++;
        }
        if(l * 2 >= k){
            l = 0;
            for(int j = 0; j < k; j++){
                if(s[i][j] == '(') l++;
                else{
                    l--;
                    m[i] = min(m[i], l);
                }
            }
            p[i] = P(l, m[i]);
        }
        else{
            l = 0;
            for(int j = k - 1; j >= 0; j--){
                if(s[i][j] == ')') l++;
                else{
                    l--;
                    m[i] = min(m[i], l);
                }
            }
            p[i] = P(-l, m[i]);
        }
    }
    sort(p, p + n, comp);
    int h = 0;
    for(int i = 0; i < n; i++){
        if(p[i].first >= 0){
            if(h + p[i].second < 0){
                cout << "No" << endl;
                return 0;
            }
        }
        else{
            if(h + p[i].first + p[i].second < 0){
                cout << "No" << endl;
                return 0;
            }
        }
        h += p[i].first;
    }
    if(h != 0) cout << "No" << endl;
    else cout << "Yes" << endl;
}


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

using namespace std;
bool cmp (int a, int b) {
  return(a > b);
}
int main(){
  int n, h;
  vector<int> b;
  int a_max = 0;
  int count = 0;
  cin >> n >> h;
  for (int i=0;i<n;i++) {
    int aa, bb;
    cin >> aa >> bb;
    a_max = aa > a_max?aa:a_max;
    b.push_back(bb);
  }
  sort(b.begin(), b.end(), cmp);
  for (int i=0;i<n;i++) {
    if (b[i] > a_max) {
      h -= b[i];
      count++;
      if (h<=0) {
	cout << count << endl;
	return(0);
      }
    }
  }

  count += h/a_max;
  if (h%a_max!=0) {
    count++;
  }
  cout << count << endl;
  return(0);
}


Measured memory_bytes: 892
N = int(input())
h = list(map(int, input().split()))

# nowはまだ0になっていない花のうち左端の添え字
# nowが0からはじまりn-1まで
# まだ残りの高さが0になっていない場合は、その花に水をやり、同時に可能なだけ右の花にも水をやる
now = 0
ans = 0
while now < N:
    if h[now] > 0:
        ans += 1
        i = now
        while i < N and h[i] > 0:
            h[i] -= 1
            i += 1
    else:
        now += 1
print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); i++) 
#define FOR(i, a, b) for(int (i) = a; (i) < (int)b; i++)
#define RREP(i, n) for(int (i)=((int)(n)-1); (i)>=0; i--)
#define RFOR(i, a, b) for(int (i) =((int)(b)-1); (i)>=(int)a; i--)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define FT first
#define SC second

using namespace std ;
typedef long long ll;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef pair<int, int> pint;
const int INF = 1e9;
const double EPS = 1e-9;



int main()
{
  string s ;
  cin >> s ;
  int count = 0 ;
  int n = s.size() ;
  s.pop_back() ;
  
  REP(i,n-1){
    if(s.size()%2==0){
      int m = s.size() ;
      REP(j,m/2){
        if(s.at(j)==s.at(j+m/2)){
          count++ ;
        }
      }
      if(count==m/2){
        cout << m <<endl ;
        return 0 ;
      }
    }
      count = 0 ;
      s.pop_back() ;
  }
  
      
  

  return 0 ;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
 
using namespace std;
using namespace __gnu_pbds;
 
#define debug(s) cout << #s << " = " << s << endl
#define all(v) (v).begin(), (v).end()
#define mem(a,val) memset(a, val, sizeof a)
 
#define maxn 100010
#define INF 1e15
#define ff first
#define ss second
#define endl '\n'
typedef long long ll;
 
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

ll arr[maxn];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> arr[i];
  sort(arr + 1, arr + 1 + n);
  ll mini = INF, idx;
  for (int i = 1; i < n; ++i) {
    ll val = max(arr[i], (arr[n] - arr[i]));
    if (val < mini) {
      mini = val;
      idx = i;
    }
  }
  cout << arr[n] << " " << arr[idx] << endl;
}





Measured memory_bytes: 1024
import itertools
N = int(input())
P = list(map(int,input().split()))
Q = list(map(int,input().split()))
n_list = [i for i in range(1,N+1)]
n_perm = sorted(list(itertools.permutations(n_list, N)))
a = 0
b = 0

for i in range(len(n_perm)):
    if list(n_perm[i]) == P:
        a = i
        break

for k in range(len(n_perm)):
    if list(n_perm[k]) == Q:
        b = k
        break
        
print(abs(a-b))    

Measured memory_bytes: 8308
package main

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

func main() {
	sc := NewScanner()

	a := sc.ReadInt()
	b := sc.ReadInt()
	_ = sc.ReadInt()
	k := sc.ReadInt()

	if k <= a {
		fmt.Println(k)
		return
	} else if k <= a+b {
		fmt.Println(a)
		return
	}
	fmt.Println(a - (k - (a + b)))
}

// util
// *   math/simple

func Abs(x int) int {
	if x >= 0 {
		return x
	}
	return -x
}

func Min(values ...int) int {
	if len(values) == 0 {
		panic("no values")
	}
	min := values[0]
	for _, v := range values {
		if v < min {
			min = v
		}
	}
	return min
}

func Max(values ...int) int {
	if len(values) == 0 {
		panic("no values")
	}
	max := values[0]
	for _, v := range values {
		if v > max {
			max = v
		}
	}
	return max
}

func Pow(base int, exponent uint) int {
	answer := 1
	for i := uint(0); i < exponent; i++ {
		answer *= base
	}
	return answer
}

// *   sortutil

func ReverseInts(a []int) {
	sort.Sort(sort.Reverse(sort.IntSlice(a)))
}

func ReverseStrings(a []string) {
	sort.Sort(sort.Reverse(sort.StringSlice(a)))
}

// *   io

type Scanner struct {
	bufScanner *bufio.Scanner
}

func NewScanner() *Scanner {
	bufSc := bufio.NewScanner(os.Stdin)
	bufSc.Split(bufio.ScanWords)
	bufSc.Buffer(nil, 100000000)
	return &Scanner{bufSc}
}

func (sc *Scanner) ReadString() string {
	bufSc := sc.bufScanner
	bufSc.Scan()
	return bufSc.Text()
}

func (sc *Scanner) ReadInt() int {
	bufSc := sc.bufScanner
	bufSc.Scan()
	text := bufSc.Text()

	num, err := strconv.Atoi(text)
	if err != nil {
		panic(err)
	}
	return num
}


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


int main() {
    int N;
  string S;
  cin >> N >> S;
  
  int i = 0;
  int Ans = 1;
  
  if(N != 1){
  while(i<N-1){
    if(S.at(i) == S.at(i+1)){
    i++;
    continue;
    }else{
    Ans++;
    i++;
    continue;
    }
  }
 }
  cout << Ans << endl;

}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <array>
using namespace std;
using ULL = unsigned long long;
using UL = unsigned;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

struct Problem {

	void Solve() {
		UL N; cin >> N;
		vector<UL> A(N); rep(i, N) cin >> A[i];
		vector<UL> B(N); rep(i, N) cin >> B[i];
		UL ans = 0;
		for (int d = 28; d >= 0; d--) {
			UL D = 1 << d;
			ULL C = 0;
			rep(i, N) {
				if (A[i] & D) { C += N; A[i] ^= D; }
				if (B[i] & D) { C += N; B[i] ^= D; }
			}
			sort(A.begin(), A.end());
			rep(i, N) {
				UL p = B[i];
				p = D - p;
				UL l = 0, r = N + 1;
				while (l + 1 < r) {
					UL m = (l + r) >> 1;
					if (A[m - 1] < p) l = m; else r = m;
				}
				C += N - l;
			}
			if (C & 1) ans |= D;
		}
		cout << ans << endl;
	}


	Problem();
};
int main() {
	unique_ptr<Problem> p(new Problem());
	p->Solve();
	return 0;
}
Problem::Problem() {
	cout << fixed << setprecision(10);
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define M 1000000007
#define ll long long int
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define null NULL
#define mp make_pair
#define fi first
#define se second
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);
#define inf 1e17
#define si 400005
#define For(i,a,b) for(i=a;i<b;i++)
#define piv pair<int ,vector<int>>


ll powmod(ll a, ll b){ ll ans = 1; while(b){if(b&1)ans=(ans%M*a%M)%M; a=(a%M*a%M)%M; b=b>>1;}return ans;}

int main(){
    boost
    int n, i, vac[100000][3], dp[100000][3];
    cin>>n;
    For(i, 0, n)
        cin>>vac[i][0]>>vac[i][1]>>vac[i][2];
    dp[0][0] = vac[0][0];
    dp[0][1] = vac[0][1];
    dp[0][2] = vac[0][2];
    for(i=1;i<n;i++){
        dp[i][0] = vac[i][0] + max(dp[i-1][1], dp[i-1][2]);
        dp[i][1] = vac[i][1] + max(dp[i-1][2], dp[i-1][0]);
        dp[i][2] = vac[i][2] + max(dp[i-1][1], dp[i-1][0]);
    }
    cout<<max(dp[n-1][0], max(dp[n-1][1], dp[n-1][2]))<<endl;
    return 0;
}


Measured memory_bytes: 2560
n = int(input())
A = [list(map(int,input().split())) for i in range(2)]
D = [[], []]

for i in range(3):
    if A[0][i] > A[1][i]:
        D[1].append([A[1][i], A[0][i]])
    else:
        D[0].append([A[0][i], A[1][i]])

def d1(x, in_0, out_0):
    return out_0 * (x // in_0) + (x % in_0)

def d2(x, in_0, out_0, in_1, out_1):
    ans = 0
    for i in range((x // in_0) + 1):
        ans = max(ans, out_0 * i + out_1 * ((x - i * in_0) // in_1) + ((x - i * in_0) % in_1))
    return ans

def d3(x, in_0, out_0, in_1, out_1, in_2, out_2):
    ans = 0
    for i in range((x // in_0) + 1):
        for j in range(((x - i * in_0) // in_1) + 1):
            ans = max(ans, out_0 * i + out_1 * j + out_2 * ((x - i * in_0 - j * in_1) // in_2) \
                + ((x - i * in_0 - j * in_1) % in_2))
            # print(i,j,ans)
    return ans

# print(D)

ans = 0
l = len(D[0])
if l == 3:
    ans = d3(n, D[0][0][0], D[0][0][1], D[0][1][0], D[0][1][1], D[0][2][0], D[0][2][1])
elif l == 2:
    ans = d1(d2(n, D[0][0][0], D[0][0][1], D[0][1][0], D[0][1][1]), D[1][0][0], D[1][0][1])
elif l == 1:
    ans = d2(d1(n, D[0][0][0], D[0][0][1]), D[1][0][0], D[1][0][1], D[1][1][0], D[1][1][1])
elif l == 0:
    ans = d3(n, D[1][0][0], D[1][0][1], D[1][1][0], D[1][1][1], D[1][2][0], D[1][2][1])

print(ans)

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

#define FOR(x,y,z) for(int x=y,x##_=z;x<=x##_;++x)
#define DOR(x,y,z) for(int x=y,x##_=z;x>=x##_;--x)
#define FOR_(x,y,z,s) for(int x=y,x##_=z;x<=x##_;x+=s)
#define FOR__(x,y,z) for(int x=y,x##_=z;x<=x##_;x<<=1)
#define EOR(x,y) for(int x##_=head[x],y=edge[x##_].e;x##_;y=edge[x##_=edge[x##_].to].e)
#define EGOR(x,y,z) for(int x##_=head[x],y=edge[x##_].e,z=edge[x##_].c;x##_;y=edge[x##_=edge[x##_].to].e,z=edge[x##_].c)

#define clr(x,y) memset(x,y,sizeof(x))
#define szf(x) sizeof(x)
#define min3(x,y,z) min(min(x,y),z)
#define max3(x,y,z) max(max(x,y),z)

#define read2(x,y) read(x),read(y)
#define read3(x,y,z) read(x),read(y),read(z)
#define read4(x,y,z,w) read3(x,y,z),read(w)
#define reads(str) sf("%s",str)

#define ts (*this)
#define sf scanf
#define pf printf

#define ll long long
#define ull unsigned long long
#define db double
#define ct clock_t
#define ck() clock()
#define rd rand()
#define rmx RAND_MAX
#define RD T*(rd*2-rmx)


using namespace std;

template<class T>bool tomin(T &x,T y){return y<x?x=y,1:0;}
template<class T>bool tomax(T &x,T y){return x<y?x=y,1:0;}
template<class T>void read(T &x){
    char c;
    x=0;
    int f=1;
    while(c=getchar(),c<'0'||c>'9')if(c=='-')f=-1;
    do x=(x<<3)+(x<<1)+(c^48);
    while(c=getchar(),c>='0'&&c<='9');
    x*=f;
}

const db Pi=acos(-1);
const int maxn=2e5+5;
int n,m;
int A[maxn],B[maxn];
int c[maxn];
void Add(int x,int d){
    while(x){
        tomax(c[x],d);
        x&=x-1;
    }
}
int query(int x){
    int ans=0;
    while(x<=m){
        tomax(ans,c[x]);
        x+=x&-x;
    }return ans;
}
int main(){
    srand(time(NULL));
    read(n);
    FOR(i,1,n)read(A[i]),B[i]=A[i];
    sort(B+1,B+n+1);
    m=unique(B+1,B+n+1)-B-1;
    FOR(i,1,n)A[i]=lower_bound(B+1,B+m+1,A[i])-B;
    int ans=0,dp=0;
    FOR(i,1,n){
        Add(A[i],dp=query(A[i])+1);
        tomax(ans,dp);
    }
    pf("%d",ans);
    return 0;
}


Measured memory_bytes: 1408
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

n, c = na()
stc = []
for i in range(n):
    stc.append(na())
stc.sort(key=lambda x: (x[2], x[0]))

nstc = []
for i in range(n):
    if len(nstc) > 0 and nstc[-1][2] == stc[i][2] and nstc[-1][1] == stc[i][0]:
        nstc[-1][1] = stc[i][1]
    else:
        nstc.append(stc[i])
n = len(nstc)

h = [0]*200005
for i in range(n):
    h[2*nstc[i][0] - 1] += 1
    h[2*nstc[i][1]] += -1
for i in range(len(h)-1):
    h[i] += h[i-1]
print(max(h))


Measured memory_bytes: 36820
#include <iostream>
#include<vector>
#include<string>
using namespace std;
typedef long long ll;

int main() {
	int n;cin>>n;
	string s;cin>>s;
	int q;cin>>q;
	vector<int> k(q);
	for(int i=0;i<q;i++){
		cin>>k[i];
	}
	vector<ll> d(n,0);
	vector<ll> m(n,0);
	vector<ll> c(n,0),cm(n,0);
	for(int i=0;i<n;i++){
		if(s[i]=='D'){
			d[i]=1;
		}else if(s[i]=='M'){
			m[i]=1;
		}else if(s[i]=='C'){
			c[i]=1;
		}
	}
//	for(int i=0;i<n;i++){
//		cout<<d[i]<<' ';
//	}
//	cout<<endl;
//	for(int i=0;i<n;i++){
//		cout<<m[i]<<' ';
//	}
//	cout<<endl;
//	for(int i=0;i<n;i++){
//		cout<<c[i]<<' ';
//	}
//	cout<<endl;
	for(int i=1;i<n;i++){
//		d[i]+=d[i-1];
		m[i]+=m[i-1];
		cm[i]+=cm[i-1];
		if(c[i]){
			cm[i]+=m[i];
		}
		c[i]+=c[i-1];
	}
//	for(int i=0;i<n;i++){
//		cout<<cm[i]<<endl;
//	}

	for(int j=0;j<q;j++){
		ll ans=0;
		int tk=k[j];
		for(int i=0;i<n;i++){
			if(s[i]=='D'){
				int r=i+tk-1;
				if(r>=n)r=n-1;
				ll add=cm[r]-cm[i];
				int nc=c[r]-c[i];
				add-=nc*m[i];
				ans+=add;
//				cout<<i<<' '<<add<<' '<<nc<<endl;
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 32644
#include <iostream>
#include <cmath>
#include <string.h>
#include <iomanip>

using namespace std;

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

int main(){
    int l,ans = 0;
    string s;
    string k = "", t = "";
    cin >> s;
    rep(i,s.length()){
        k.push_back(s[i]);
        if (k != t){
            t = k;
            k = "";
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include<bits/stdc++.h>
#include<vector>
#include<string>
#define ll long long
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define vi vector<ll>
#define el printf("\n")
#define N 100001
using namespace std;
ll fact(ll n)
{
ll    res=1;
    for(int i = 1; i <= n;i++){
    res = res * i ;
}
return res;
}
ll pw(ll a, ll n)
{
    ll ans=1;
    while(n>0)
    {
        if (n%2!=0)
        {
            ans=ans*a;
        }
        a=a*a;
        n=n/2;
    }
    return ans;
}



int main()
{   IOS;
cout.precision(30);

   ll a;
   cin >> a;
   cout << a*a*a;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#define take_input freopen("input.txt", "r", stdin)
#define ll long long int 
#define pb push_back
#define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define fi first
#define se second
using namespace std;
#define mod 1000000007

// ll power(ll x, ll n){
// 	ll res = 1;
// 	while(n){
// 		if(n%2) res = ((res%mod)*(x%mod))%mod;
// 		x = ((x%mod)*(x%mod))%mod;
// 		n /= 2;
// 	}
// 	return res%mod;
// }

// int main(){
// 	ll n;
// 	cin >> n;
// 	ll res = (power(10, n)-2*power(9, n)+power(8,n))%mod;
// 	cout << res << "\n";
// }
	
// int main(){
// 	int n;
// 	cin >> n;
// 	vector< pair<string, string> > v(n);
// 	int flag=0;
// 	for(int i=0; i<n; i++){
// 		string s1,s2;
// 		cin >> s1 >> s2;
// 		v[i] = {s1, s2};
// 	}
// 	for(int i=0; i<n-3; i++){
// 		if((v[i].fi == v[i].se) &&( (v[i+1].fi == v[i+1].se) && (v[i+2].fi == v[i+2].se))){
// 			flag = 1;
// 		}
// 	}
// 	if(flag == 1){
// 		cout << "Yes" << endl;
// 	}else{
// 		cout << "No" << endl;
// 	}
// }


int main(){
	int n;
	cin >> n;
	int count=0;
	for(int i=1; i<n; i++){
		int num = n-i;
		for(int j=1; j*j<=num; j++){
			if(num%j == 0){
				if(num/j == j) count++;
				else count+=2;
			}
		}
	}
	cout << count << endl;
}

Measured memory_bytes: 3220
#include <iostream>
#include <thread>
#include <chrono>
#include <random>
#include <fstream>
#include <time.h>
#include <algorithm>

int main()
{
    int N;
    int ans=0;

    std::cin >> N;

    std::vector<int> a(N);

    for(int i=0; i<N; i++){
        std::cin >> a[i];
    }

    sort(a.begin(), a.end());

    ans = a[a.size()-1] - a[0];

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

    return 0;
}

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

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SIZE(a) ((int)(a).size())

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

	ll a, b;
	cin >> a >> b;
	int result = 0;
	while (a <= b) {
		++result;
		a *= 2;
	}
	cout << result << '\n';

	return 0;
}

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

#define INF 99999999
using namespace std;

void print_v(vector<int> v) {
    for (int i : v) {
        cout << i << " ";
    }
    cout << endl;
}
int mod = 1e9+7;
int main() {
    int n,m,x,c,tmp,ans = INF;
    cin >> n >> m >> x;
    vector<vector<int>> a(n, vector<int> (m+1));
    for (int i = 0; i < n; ++i) {
        cin >> c;
        a[i][0] = c;
        for (int j = 0; j < m; ++j) {
            cin >> tmp;
            a[i][j+1] = tmp;
        }
    }
    for (int bit = 0; bit < (1<<n); ++bit) {
        vector<int> kari(m+1, 0);
        for (int i = 0; i < n; ++i) {
            if(bit & (1<<i)){
                for (int j = 0; j < m + 1; ++j) {
                    kari[j]+=a[i][j];
                }
            }
        }
        bool flag = true;
        for (int i = 1; i < m+1; ++i) {
            if(kari[i] < x) {
                flag = false;
            }
        }
        if(flag){
            ans = min(ans, kari[0]);

        }
        //print_v(kari);
    }
    if(ans == INF){
        cout << -1 << endl;
    } else {
        cout << ans << endl;
    }
    return 0;
}


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

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        while (true) {
            int n = sc.nextInt();
            int k = sc.nextInt();

            if (n == 0 && k == 0) break;

            int[] a = new int[n];
            for (int i = 0; i < n; i++) a[i] = Integer.parseInt(sc.next());

            int[] s = new int[n + 1];
            s[0] = 0;
            for (int i = 0; i < n; i++) s[i+1] = s[i] + a[i];

            long ans = Long.MIN_VALUE;
            for (int i = 0; i <= n-k; i++) {
                long val = s[i+k] - s[i];
                if (ans < val) ans = val;
            }

            System.out.println(ans);
        }
    }
}



Measured memory_bytes: 71368
#include <algorithm>
#include <iostream> //入出力
#include <stdio.h>
#include <map>
#include <set>
#include <string>
#include <math.h> //算術演算子
#include <vector>
#include <cstdlib>
#include <queue>
#include <stack>
#include <list>
#include <iomanip> //小数点以下を表示させる(setprecision())
//#include <bits/stdc++.h>
using namespace std;
typedef long long ll; //64bit型

#define debug(x) cerr << x << " " \
                      << "(L:" << __LINE__ << ")" << '\n'
#define PRINT(V)                                   \
        {                                          \
                for (int i = 0; i < V.size(); i++) \
                {                                  \
                        cout << V[i] << " ";       \
                }                                  \
                cout << endl;                      \
        }

int gcd(int a, int b)
{
        return b ? gcd(b, a % b) : a;
}

int main()
{
        //input->compute->output//

        int A, B;
        cin >> A >> B;
        if (A+B<10)
        {
                cout << A+B << endl;
        }
        else
        {
                cout << "error" << endl;
        }

        return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<n;++i)
#define rep1(i,n) for(ll i=1;i<=n;++i)
int main(){
  int n;
  cin>>n;
  string s;
  cin>>s;
  int size=(int)s.length();
  rep(i,size){
    int k='Z';
    s[i]+=n;
    if(s[i]>k)s[i]=s[i]-'Z'+'A'-1;
  }
  cout<<s<<endl;
  return 0;
}


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

int main()
{
	int a[3][3],vis[3][3];
	
	memset(vis,0,sizeof(vis));
	
	for(int i=0; i<3; i++)
		for(int j=0; j<3; j++)
			cin>>a[i][j];
	
	int n;
	cin>>n;
	int b[n+1];
	
	for(int i=1; i<=n; i++)
		cin>>b[i];
	
	sort(b+1,b+n+1);
	
	for(int i=0; i<3; i++)
		for(int j=0; j<3; j++)
		{
			if(binary_search(b+1,b+n+1,a[i][j]))
				vis[i][j]=1;
		}
	
	if(vis[0][0]==1 && vis[0][1]==1 && vis[0][2]==1
	|| vis[1][0]==1 && vis[1][1]==1 && vis[1][2]==1
	|| vis[2][0]==1 && vis[2][1]==1 && vis[2][2]==1
	|| vis[0][0]==1 && vis[1][0]==1 && vis[2][0]==1
	|| vis[0][1]==1 && vis[1][1]==1 && vis[2][1]==1
	|| vis[0][2]==1 && vis[1][2]==1 && vis[2][2]==1
	|| vis[0][0]==1 && vis[1][1]==1 && vis[2][2]==1
	|| vis[0][2]==1 && vis[1][1]==1 && vis[2][0]==1)
	{
		cout<<"Yes"<< endl;
		return 0;
	}
	else
	{
		cout<<"No"<< endl;
		return 0;
	}
	
	return 0;
}

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

int main() {
	int N, M, ansAC = 0,ansWA=0;
	cin >> N >> M;
	vector<int>p(M+2000),AC(N+2000),WA(N+2000);
	vector<string>s(M);
	for (int i = 0; i < M; i++) {
		cin >> p[i] >> s[i];
	}
	for (int i = 0; i < M; i++) {
		if (s[i] == "AC") {
			AC[p[i]-1] = 1;
		}
		else if (s[i] == "WA") {
			if (AC[p[i]-1] == 0) {
				WA[p[i]-1]++;
			}
		}
	}
	for (int i = 0; i < M; i++) {
		if (AC[p[i] - 1] == 0) {
			WA[p[i] - 1] = 0;
		}
	}
	for (int i = 0; i < N; i++) {
		ansAC += AC[i];
		ansWA += WA[i];
	}
	cout << ansAC << " " << ansWA << endl;
	return 0;
}

Measured memory_bytes: 8064
#include"bits/stdc++.h"

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const ll INF = 1LL << 60;

int main() {
    int n, m,k,a,b;
    int maxcnt = 0,tmpcnt=0;
    cin >> n >> m >> k;
    vector<ll>booka, bookb;
    vector<ll>bookasum(n+1,0), bookbsum(m+1,0);
    rep(i, n) {
        cin >> a;
        booka.push_back(a);
        bookasum[i + 1] = a + bookasum[i];
    }

    rep(i, m) {
        cin >> b;
        bookb.push_back(b);
        bookbsum[i + 1] = b + bookbsum[i];
    }
    for (int i = 0;i <= n;i++) {
        if (bookasum[i] > k)break;
        auto itr = upper_bound(all(bookbsum), k - bookasum[i]);
        if (bookbsum.begin() != itr)itr--;
        //tmpcnt = itr - bookbsum.begin();
        //if (bookbsum.begin() != itr)tmpcnt--;
        maxcnt = max(maxcnt, int(i + itr - bookbsum.begin()));
        //maxcnt = max(maxcnt, int(i + tmpcnt));
    }

    cout << maxcnt << endl;
    return 0;

}


Measured memory_bytes: 11036
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <deque>
#include <cctype>
#include <cstdio>
#include <math.h>
using namespace std;
int main(){
    long long n,m;
    cin >> n >> m;
    long long ans=0;
    m-=n*2;
    if(m>=0){
        ans+=n;
        ans+=m/4;
    }else{
        n-=abs(m/2)+abs(m%2);
        ans+=n;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>

using namespace std;

int main()
{

    int n, k;

    cin >> n >> k;

    int h[n+1], i, j;

    for(i = 1 ; i <= n ; i++)
        cin >> h[i];

    int dp[n+1];

    dp[1] = 0;


    for(i = 2 ; i <= n ; i++)
    {
        dp[i] = dp[i-1] + abs(h[i] - h[i-1]);
        for(j = 2 ; j <= k ; j++)
        {
            if(i > j)
            {
                dp[i] = min(dp[i-j] + abs(h[i] - h[i-j]), dp[i]);

            }
        }

    }

    cout << dp[n] ;
    return 0;
}


Measured memory_bytes: 1024
n = int(input())
l = list(map(int, input().split()))

diff = []
for i in range(n-1):
    num = l[i]
    diff.append(l[i+1] - l[i])

diff.append(100)

cn = 0
ans = 0

for i in diff:
    if i <= 0:
        cn += 1
    else:
        ans = max(cn, ans)
        cn = 0
print(ans)


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

int toInt(char a){
  if(islower(a))return a-'a';
  return a-'A'+26;
}

char toChar(int a){
  if(a<26)return 'a'+a;
  return 'A'+a-26;
}

const int M = 52;

int main(){
  int n,k[100];
  string s;

  while(cin >> n,n){
    for(int i=0;i<n;i++)cin >> k[i];
    cin >> s;

    for(int i=0;i<s.size();i++){
      int tmp = toInt(s[i]) - k[i%n];
      tmp = ((tmp%M) + M) % M;
      cout << toChar(tmp);
    }
    cout << endl;
  }
}

Measured memory_bytes: 1196
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize ("-O3")

int solve(vector<int>& arr, vector<int>& dp, int n){
    dp[0] = 0;
    if(n==1)
        return dp[0];
    dp[1] = abs(arr[0]-arr[1]);
    if(n==2)
        return dp[1];
    for(int i=2;i<n;i++){
        dp[i] = min((dp[i-1]+abs(arr[i]-arr[i-1])),(dp[i-2]+abs(arr[i]-arr[i-2])));
    }
    return dp[n-1];
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(NULL); cout.tie(NULL);
    int n;
    cin>>n;
    vector<int> arr(n),dp(n,0);
    for(int i=0; i<n; i++)
        cin>>arr[i];
    int res = solve(arr,dp,n);
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 1024
n,m=map(int,input().split())
a=[list(map(int,input().split()))for i in range(m)]
b=[[]for i in range(n)]
for i in range(m):
    b[a[i][0]-1]+=[a[i][1]-1]
    b[a[i][1]-1]+=[a[i][0]-1]
def f(x,p,q):
    c[x]=True
    for i in b[x]:
        if c[i]==False:
            if (i==p and x==q) or(i==q and x==p):
                continue
            else:
                f(i,p,q)
d=0
for i in range(m):
    c=[False]*n
    f(a[i][0]-1,a[i][0]-1,a[i][1]-1)
    if c!=[True]*n:
        d+=1
print(d)

Measured memory_bytes: 3064
hour :: Int -> Int 
hour time = div time 3600

minute :: Int -> Int 
minute time = mod (div time 60) 60

second :: Int -> Int 
second time = mod time 60

main = do
  num <- readLn
  putStrLn (show (hour num) ++ ":" ++ show (minute num) ++ ":" ++ show (second num))

Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define all(v) v.begin(),v.end()
#define mem(arr) memset(arr, 0, sizeof(arr))
#define ff first
#define ss second
#define int long long int
const int MOD = 1e9 + 7;
const int INF = 1e18;
const int N = 1e6 + 20;
vector<int> g[N];
vector<int> vis(N);
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int tc = 1;
    while(tc--){
        int n, k;
        cin >> n >> k;
        int a[n + 1];
        for(int i = 1; i <= n; i++){
            cin >> a[i];
        }
        vis[1] = 1;
        int i = 1, c, ans;
        while(1){
            i = a[i];
            k--;
            if(!k){
                ans = i;
                break;
            }
            if(vis[i]){
                c = i;
                break;
            }
            vis[i] = 1;
        }
        if(k){
            vector<int> ans;
            int val = a[c];
            ans.pb(c);
            while(val != c){
                ans.pb(val);
                val = a[val];
            }
            int len = ans.size();
            k %= len;
            cout << ans[k] << '\n';
        }else{
            cout << ans << '\n';
        }
    }
}

Measured memory_bytes: 36920
input_line = raw_input()
temp_list = input_line.split()
a = int(temp_list[0])
b = int(temp_list[1])
c = int(temp_list[2])

x = min([a, b, c])
z = max([a, b, c])

if  not a in [x, z]:
  y = a
elif not b in [x, z]:
  y = b
else:
  y = c

print(str(x) + " " + str(y) + " " + str(z))


Measured memory_bytes: 4648
import bisect, copy, heapq, math
import sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
sys.setrecursionlimit(5000000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

a,b=map(int,input().split())
g=math.gcd(a,b)

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])
    if arr==[]:
        arr.append([n, 1])
    return arr

if g==1:
    print(1)
else:
    print(len(factorization(g))+1)

Measured memory_bytes: 9972
n = int(input())
arr = list(map(int, input().split()))

MOD = 10**9 + 7

dp = [0] * (n + 1)
dp[0] = 3
ans = 1
for x in arr:
    ans = ans * dp[x] % MOD
    # 選んだら減る
    dp[x] -= 1
    # 次に選べるようになる
    dp[x + 1] += 1

print(ans)

Measured memory_bytes: 20760
import sys
input = sys.stdin.readline
n = int(input())
from collections import defaultdict
import bisect
xd0=defaultdict(list)
xd90=defaultdict(list)
xd180=defaultdict(list)
xd270=defaultdict(list)
xyd0=defaultdict(list)
xyd90=defaultdict(list)
xyd180=defaultdict(list)
xyd270=defaultdict(list)

def rotate(x,y,u):
    if u=='U': u0='R'
    elif u=='R': u0='D'
    elif u=='D': u0='L'
    else: u0='U'
    x0=y
    y0=200000-x
    return x0,y0,u0

for _ in range(n):
    x,y,u=input().split()
    x,y=int(x),int(y)
    if u=='U' or u=='D':
        xd0[x].append((y,u))
    x90,y90,u90=rotate(x,y,u)
    if u90=='U' or u90=='D':
        xd90[x90].append((y90,u90))
    x180,y180,u180=rotate(x90,y90,u90)
    if u180=='U' or u180=='D':
        xd180[x180].append((y180,u180))
    x270,y270,u270=rotate(x180,y180,u180)
    if u270=='U' or u270=='D':
        xd270[x270].append((y270,u270))
    if u=='U' or u=='R':
        xyd0[x+y].append((y,u))
    if u90=='U' or u90=='R':
        xyd90[x90+y90].append((y90,u90))
    if u180=='U' or u180=='R':
        xyd180[x180+y180].append((y180,u180))
    if u270=='U' or u270=='R':
        xyd270[x270+y270].append((y270,u270))

ans=float('inf')
for i in range(4):
    if i==0:
        xd=xd0
        xyd=xyd0
    elif i==1:
        xd=xd90
        xyd=xyd90        
    elif i==2:
        xd=xd180
        xyd=xyd180
    elif i==3:
        xd=xd270
        xyd=xyd270
    for j in range(200001):
        xl=xd[j]
        nxl=len(xl)
        if nxl<=1: continue
        elif nxl>1:
            xl=sorted(xl)
            for i in range(1,nxl):
                if xl[i][1]=='D' and xl[i-1][1]=='U':
                    ans=min(ans, (xl[i][0]-xl[i-1][0])*5)
    for j in range(400001):
        xyl=xyd[j]
        nxyl=len(xyl)
        if nxyl<=1: continue
        elif nxyl>1:
            xyl=sorted(xyl)
            for i in range(1,nxyl):
                if xyl[i][1]=='R' and xyl[i-1][1]=='U':
                    ans=min(ans, (xyl[i][0]-xyl[i-1][0])*10)            

if ans!=float('inf'):
    print(ans)
else:
    print('SAFE')

Measured memory_bytes: 421328
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
    ll n;
    cin >> n;
    string s;
    cin >> s;
    ll l=s.size();
    if(n>=l)
        cout << s << endl;
    else{
    for(int i=0;i<n;i++)
        cout << s[i];
    cout << "..." << endl;
    }
    return 0;
}


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

#define rep3(i, s, n ,a) for (int i = (s); i < (int)(n); i+=a)
#define rep2(i, s, n) rep3(i, s, n, 1)
#define rep(i, n) rep2(i, 0, n)

int main(){
    long a, b, c, k;
    cin >> a >> b >> c >> k;
    long A = min(k, a);
    long B = min(k-A, b);
    long C = k-A-B;
    cout << A - C << endl;
    // if(a>=k){
    //     cout << k << endl;
    // }else{
    //     k -= a;
    //     if(b>=k){
    //         cout << a << endl;
    //     }else{
    //         cout << a - k + b << endl;
    //     }
    // }
    return 0;
}

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

int main(){
//変数の宣言
int a[10],c[10];
int n,b;
//初期化
a[0]=1;
for(int i=1;i<10;i++){
a[i]=a[i-1]*2;}

while(cin>>n){
//初期化
b=0;
for(int i=0;i<10;i++){
c[i]=0;}
//おもりを乗せるか
for(int i=9;i>-1;i--){
if(n>=a[i]){
c[b]=a[i];
b++;
n-=a[i];}
if(n==0){break;}
}
//出力
for(int i=b-1;i>0;i--){
cout<<c[i]<<" ";}
cout<<c[0]<<endl;
}}

Measured memory_bytes: 1160
#include <stdio.h>
int main(){
    int n,x,t,ans=0;
    scanf("%d%d%d", &n, &x, &t);
    if(n%x){ ans = ((n/x)+1) *t; }
    else   { ans =   n/x     *t; }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 1676
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n = int(readline())
    l = list(map(int, readline().split()))
    l.sort()

    print(sum(l[::2]))


if __name__ == '__main__':
    main()


Measured memory_bytes: 61900
#include<stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
 /*
int Sumed(int Num , int min, int max){
  int i;
  for(i=min;i < max;i++){
    
}
*/
 
int main()
{
    int N;
    int A, B;
    int Number[5];
    int wa;
    int Sum=0;
 // 整数の入力
    scanf("%d %d %d", &N, &A, &B);
 // printf("%d\n",N);

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


    Number[0] = (i / 10000) % 10;
    Number[1] = (i / 1000) % 10;
    Number[2] = (i / 100) % 10;
    Number[3] = (i / 10) % 10;
    Number[4] = i  % 10;

    
    wa = Number[0] + Number[1] + Number[2] + Number[3] + Number[4];
//     printf("%d:wa %d, \n", i,wa);   
    if((A<=wa) && (wa <=B) ){
      Sum = Sum + i;
    }
//    printf("Sum %d\n", Sum);
  }
printf("%d\n", Sum);

/*  
    if((a + b) > (c + d))
    printf("Left\n");
    else if((a + b) == (c + d))
    printf("Balanced\n");
    else
    printf("Right\n");
    return 0;
*/
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll>pll;
typedef pair<ll,pair<ll,ll> >pk;
#define sf(a) scanf("%d",&a)
#define pf(a) printf("%d\n",a)
#define F first
#define S second
#define minheap int,vector<int>,greater<int>
#define mp make_pair
#define pb push_back
#define pp pop_back
#define ischar(x)  (('a' <= x && x <= 'z') || ('A' <= x && x <= 'Z'))
#define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL));
const int Max = 2e6 + 10;
const int Mod = 1e9 + 7;
bool compare(const pair<int,int> &a,
               const pair<int,int> &b)
{
       return (a.first > b.first);
}

int main()
{
   fastread();

   ll n,m;

   cin>>n>>m;

   cout<<max((n-m),max((n+m),(n*m)))<<endl;


}


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

signed main() {
    int N, K;
    cin >> N >> K;

    vector<vector<int>> vv(N);
    for (int i = 0; i < N; i++) {
        int t, d;
        cin >> t >> d;

        vv[--t].push_back(d);
    }

    for (auto& v : vv) {
        sort(v.rbegin(), v.rend());
    }

    vector<int> inc, others;
    for (auto v : vv) {
        for (int i = 0; i < v.size(); i++) {
            if (!i) inc.push_back(v[i]);
            else others.push_back(v[i]);
        }
    }

    sort(inc.rbegin(), inc.rend());
    sort(others.rbegin(), others.rend());

    inc.insert(inc.begin(), 0);
    others.insert(others.begin(), 0);

    for (int i = 1; i < inc.size(); i++) {
        inc[i] += inc[i - 1];
    }

    for (int i = 1; i < others.size(); i++) {
        others[i] += others[i - 1];
    }

    int ans = 0;
    for (int i = 1; i <= K; i++) {
        if (i >= inc.size()) break;
        if (K - i >= others.size()) continue;

        int t = i * i;
        t += inc[i] + others[K - i];
        ans = max(ans, t);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 6904
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

map< int64_t, int > prime_factor(int64_t n) {
  map< int64_t, int > ret;
  for(int64_t i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}


int main(int argc, char const *argv[]) {
    ll n; cin>>n;
    auto primes = prime_factor(n);
    vector<ll> cnt(100);
    iota(cnt.begin(), cnt.end(), 1);
    rep(i,98) cnt[i+1] += cnt[i];

    ll ans = 0;
    for (auto &&e: primes) {
        ll x = e.second;
        auto itr = upper_bound(cnt.begin(), cnt.end(), x);
        int idx = itr-cnt.begin();
        ans += idx;
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 3632
import itertools

N = int(raw_input())
P = tuple(map(int, raw_input().split()))
Q = tuple(map(int, raw_input().split()))

permutations = list(itertools.permutations(range(1, N + 1)))
a = permutations.index(P)
b = permutations.index(Q)

print(abs(a - b))


Measured memory_bytes: 7920
#include <iostream>

using namespace std;
int M[100][100];
int V[100];

int main() {
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < n; ++i) for (int j = 0; j < m; ++j) cin >> M[i][j];
    for (int i = 0; i < m; ++i) cin >> V[i];
    for (int i = 0; i < n; ++i) {
        int val = 0;
        for (int j = 0; j < m; ++j) {
            val += M[i][j] * V[j];
        }
        cout << val << endl;
    }
    return 0;
}



Measured memory_bytes: 3116
#include<bits/stdc++.h>
using namespace std;
int now=0;
long long x;
deque<int>q1,q2;
void solve(long long n)
{
	if(n==1) return;
	solve(n>>1);
	now++,q1.push_front(now),q2.push_front(now);
	if(n&1) now++,q1.push_front(now),q2.push_back(now);
}
int main()
{
	scanf("%lld",&x);
	solve(x+1);
	int s1=q1.size(),s2=q2.size();
	printf("%d\n",s1+s2);
	for(int i=0;i<s1;i++) printf("%d ",q1[i]);
	for(int i=0;i<s2;i++) printf("%d ",q2[i]);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,k,n) for(ll i=(k);i<(ll)(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(x) begin(x),end(x)
 
using namespace std;
using namespace std::string_literals;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin>>n;
  vecint a(n),b(n);
  REP(i,n) {
    cin>>a[i]>>b[i];
  }
  sort(ALL(a));
  sort(ALL(b));
  auto dmed = [](auto&& v) {
    int l = size(v);
    if (l%2 == 1) {
      return v[l/2];
    } else {
      return (v[l/2-1] + v[l/2]);
    }
  };
  int meda = dmed(a);
  int medb = dmed(b);
  cout<<medb - meda + 1<<endl;
  return 0;
}


Measured memory_bytes: 4784
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100 + 10;
int a[maxn][maxn];
int main()
{
	int h, w, n, cx = 1, cy = 1;
	scanf("%d%d", &h, &w);
	scanf("%d", &n);
	for(int i = 1; i <= n; ++i)
	{
		int v;
		scanf("%d", &v);
		for(int j = 1; j <= v; ++j)
		{
			a[cx][cy] = i;
			if(cx & 1)
			{
				if(cy == w)
					++cx;
				else
					++cy;
			}
			else
			{
				if(cy == 1)
					++cx;
				else
					--cy;
			}
		}
	}
	for(int i = 1; i <= h; ++i)
	{
		for(int j = 1; j <= w; ++j)
			printf("%d ", a[i][j]);
		puts("");
	}
	return 0;
} 
			

Measured memory_bytes: 3832
#include<bits/stdc++.h>
using namespace std;
 int main()
 {
 	int sx ,sy ,tx, ty; int i;
 	cin>>sx>>sy>>tx>>ty;
for (i=sy; i<ty; ++i)
{
	cout<<"U"; 
}

for (i=sx; i<tx; ++i)
{
	cout<<"R"; 
}
for (i=ty; i>sy; --i)
{
	cout<<"D"; 
}
for (i=tx; i>sx-1; --i)
{
	cout<<"L"; 
}
for (i=sy; i<ty+1; ++i)
{
	cout<<"U"; 
}
for (i=sx-1; i<tx; ++i)
{
	cout<<"R"; 
}
cout<<"DR";
for (i=ty; i>sy-1; --i)
{
	cout<<"D"; 
}
for (i=tx+1; i>sx; --i)
{
	cout<<"L"; 
}
cout<<"U";



 }


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (n); ++i)
#define FOR(i, m, n) for(ll i = m; i < (n); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
using vi = vector<int>;
using vii = vector<vi>;
using pii = pair<int, int>; 
using vl = vector<ll>;
using vll = vector<vl>;
using pll = pair<ll, ll>;

int main() {
    ll D;
    cin >> D;
    vl c(26);
    rep(i, 26) cin >> c[i];
    vll s(D, vl(26));
    rep(i, D){
        rep(j, 26){
            cin >> s[i][j];
        }
    }
    rep(i, D){
        cout << max_element(all(s[i])) - s[i].begin() + 1 << endl;
    }

}

Measured memory_bytes: 3720