akhauriyash/Code-Regression huggingface dataset:
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskD solver = new TaskD();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskD {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int h = in.nextInt();
            int w = in.nextInt();
            int n = in.nextInt();
            int[] a = in.nextIntArray(n);

            boolean flg = true;
            int x = 0;
            int y = 0;

            int[][] ans = new int[h][w];
            for (int i = 1; i <= n; i++) {
                for (int j = 0; j < a[i - 1]; j++) {
                    ans[y][x] = i;
                    if (flg) {
                        if (x == w - 1) {
                            flg = false;
                            y++;
                        } else {
                            x++;
                        }
                    } else {
                        if (x == 0) {
                            flg = true;
                            y++;
                        } else {
                            x--;
                        }
                    }
                }
            }

            for (int i = 0; i < h; i++) {
                for (int j = 0; j < w; j++) {
                    if (j > 0) {
                        out.print(" ");
                    }
                    out.print(ans[i][j]);
                }
                out.println();
            }
        }

    }

    static class InputReader {
        BufferedReader in;
        StringTokenizer tok;

        public String nextString() {
            while (!tok.hasMoreTokens()) {
                try {
                    tok = new StringTokenizer(in.readLine(), " ");
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
            }
            return tok.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(nextString());
        }

        public int[] nextIntArray(int n) {
            int[] res = new int[n];
            for (int i = 0; i < n; i++) {
                res[i] = nextInt();
            }
            return res;
        }

        public InputReader(InputStream inputStream) {
            in = new BufferedReader(new InputStreamReader(inputStream));
            tok = new StringTokenizer("");
        }

    }
}



Measured memory_bytes: 23380
#include <bits/stdc++.h>
#define MODNum 1000000007
#define REP(type, i, a, b) for( type i = a; i < b; i++ )
typedef long long ll;

using namespace std;

int main (void) {
    ll N;
    cin >> N;
    vector<ll> A(N);
    REP(ll,i,0,N){ 
        cin >> A.at(i);
        if ( A.at(i) == 0 ){
            cout << "0" << endl;
            return 0;
        }
    }
    ll prod = 1;
    REP(ll,i,0,N){
        ll D = 1000000000000000000 / prod;
        if ( A.at(i) <= D ){
            prod *= A.at(i);
        } 
        else{
            cout << "-1" << endl;
            return 0;
        }
    }
    cout << prod << endl;
    return 0;
}


Measured memory_bytes: 4052
#include <iostream>

int main(){

    int w, h, x, y;
    std::cin >> w >> h >> x >> y;

    double area = 0;
    bool isMulti = false;
    if(x == 0 || x == w || y == 0 || y == h){
        area = double(w)*double(h)/2.0;
    }
    else if(2*x == w && 2*y == h){
        isMulti = true;
        area = double(w)*double(h)/2.0;
    }
    else if(2*x == w || 2*y == h){
        area = double(w)*double(h)/2.0;
    }
    else{
        area = double(w)*double(h)/2.0;
    }

    std::cout << area << " " << (isMulti ? '1' : '0') << std::endl;

    return 0;
}

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

uint64_t powmod(uint64_t x, uint64_t y, uint64_t p)
{
	if(y == 0){
		return 1;
	} else if(y % 2 == 1){
		return (powmod(x, y-1, p) * x) % p;
	} else {
		uint64_t t = powmod(x, y/2, p);
		return (t * t) % p;
	}
}

int64_t extGCD(int64_t a, int64_t b, int64_t *x, int64_t *y) {
    if (b == 0) {
        *x = 1;
        *y = 0;
        return a;
    }
    int64_t d = extGCD(b, a%b, y, x);
    (*y) -= a/b * (*x);
    return d;
}

uint64_t invmod(uint64_t x, uint64_t p)
{
	int64_t r, s;
	if(extGCD(x, p, &r, &s)!=1){
		printf("ERR\n");
		abort();
	};
	return (r + p) % p;
}

uint64_t cmod(uint64_t n, uint64_t x, uint64_t p)
{
	uint64_t res = 1;
	for(uint64_t i=0; i<x; i++){
		res *= n-i;
		res %= p;
		res *= invmod(i+1, p);
		res %= p;
	}
	return res;
}

int main()
{
	int n, a, b;
	int p = 1000000007;
	cin >> n >> a >> b;

	cout << (powmod(2, n, p)
		+ p - cmod(n, a, p)
		+ p - cmod(n, b, p) - 1) % p << endl;

	return 0;
}


Measured memory_bytes: 256
N = input()
digit = len(N)
if(digit == 1):
    print(int(N))

elif(N[1:] == "9"*(digit-1)):
    print(9*(digit-1)+int(N[0]))
else:
    ans=[int(N[0])-1]+[9]*(digit-1)
    print(sum(ans))


Measured memory_bytes: 3060
#include<stdio.h>
#define N 100

int main(){
  int G[N][N];
  int n, u, k, v, i, j;

  scanf("%d",&n);

  for( i = 0 ; i < n ; i++ ){
    for( j = 0 ; j < n ; j++ ) G[i][j] = 0;
  }

  for( i = 0 ; i < n ; i++ ){
    scanf("%d%d",&u,&k);
    u--;
    for( j = 0 ; j < k ; j++ ){
      scanf("%d",&v);
      v--;
      G[u][v] = 1;
    }
  }

  for( i = 0 ; i < n ; i++ ){
    for( j = 0 ; j < n ; j++ ){
      if( j ) printf(" ");
      printf("%d",G[i][j]);
    }
    printf("\n");
  }
  return 0;
}



Measured memory_bytes: 2044
import copy
N,M=map(int,input().split())
A=[[] for n in range(N)]
I=[]
for m in range(M):
	I.append(list(map(int,input().split())))
	I[m][0]-=1
	I[m][1]-=1
	A[I[m][0]].append(I[m][1])
	A[I[m][1]].append(I[m][0])

def check(n):
	global C,AA
	if C[n]==1:
		return
	else:
		C[n]=1	
		for nn in AA[n]:
			check(nn)
		return
ans=M
for i in I:
	C=[0 for n in range(N)]
	AA=copy.deepcopy(A)
	AA[i[0]].remove(i[1])
	AA[i[1]].remove(i[0])
	check(0)
	ans-=all(C)
print(ans)

Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
bool comp(pair<pair<string, int>, int> a, pair<pair<string, int>, int> b) {
    if(lexicographical_compare(((a.first).first).begin(), ((a.first).first).end(), ((b.first).first).begin(), ((b.first).first).end())) return true;
    else if(((a.first).first) == ((b.first).first)) {
        if(((a.first).second) > ((b.first).second)) return true;
    }
    return false;
}
int main() {
    int n;
    cin >> n;
    vector<pair<pair<string, int>, int> > p(n);
    for(int i = 0; i < n; i++) {
        cin >> ((p[i]).first).first >> ((p[i]).first).second;
        (p[i]).second = i + 1;
    }
    sort(p.begin(), p.end(), comp);
    for(int i = 0; i < n; i++) {
        cout << (p[i]).second << "\n";
    }
}


Measured memory_bytes: 256
N, M, C = map(int, input().split())
B = list(map(int, input().split()))
ans = 0
for i in range(N):
    A = list(map(int, input().split()))
    sum = C
    for j in range(M):
        sum += B[j]*A[j]
    if sum > 0:
        ans += 1
print(ans)

Measured memory_bytes: 3060
import java.util.ArrayList;
import java.util.Scanner;
public class Main {
	char map[][];
	int x,y;
	static final char START = 'S';//??£?????????????????°??????
	static final char BLOCK = 'X';//?????????
	static final char SPACE = '.';//????????°
	static final char CHECKED = 'C';
	void run(){
		Scanner scan = new Scanner(System.in);
		int h,w,n;
		h = scan.nextInt();//??????(1 <= h <= 1000)
		w = scan.nextInt();//???(1 <= w <= 1000)
		n = scan.nextInt();//???????????\??´?????°(1 <= n <= 9)
		map = new char[h][w];
		for(int i = 0;i < h;i++){
			String rows = scan.next();
			for(int j = 0;j < w;j++){
				map[i][j] = rows.charAt(j);
				if(map[i][j] == START){
					map[i][j] = SPACE;
					y = i;
					x = j;
				}
			}
		}
		int result = 0;
		for(int i = 1;i <= n;i++){
			result += eat(x,y,i);
		}
		System.out.println(result);
	}

	int eat(int x,int y,int cheese){
		ArrayList<Integer> xStack = new ArrayList<Integer>();
		ArrayList<Integer> yStack = new ArrayList<Integer>();
		char moveMap[][] = new char[map.length][map[0].length];
		for(int i = 0;i < map.length;i++){
			moveMap[i] = map[i].clone();
		}
		int cnt = 0;
		xStack.add(x);
		yStack.add(y);
		moveMap[y][x] = CHECKED;
		while(true){
			int amount = xStack.size();
			//??°?????????????????§????????????
			for(int i = 0;i < amount;i++){
				int x0 = xStack.get(0);
				int y0 = yStack.get(0);
				//System.out.println("x0:" + x0 + "| |y0:" + y0);
				if(map[y0][x0] == Integer.toString(cheese).charAt(0)){
					this.x = x0;
					this.y = y0;
					return cnt;
				}else{
					if(chkTile(x0 + 1,y0,moveMap)){
						moveMap[y0][x0 + 1] = CHECKED;
						xStack.add(x0 + 1);
						yStack.add(y0    );
					}
					if(chkTile(x0 - 1,y0,moveMap)){
						moveMap[y0][x0 - 1] = CHECKED;
						xStack.add(x0 - 1);
						yStack.add(y0    );
					}
					if(chkTile(x0,y0 + 1,moveMap)){
						moveMap[y0 + 1][x0] = CHECKED;
						xStack.add(x0    );
						yStack.add(y0 + 1);
					}
					if(chkTile(x0,y0 - 1,moveMap)){
						moveMap[y0 - 1][x0] = CHECKED;
						xStack.add(x0    );
						yStack.add(y0 - 1);
					}
					xStack.remove(0);
					yStack.remove(0);
				}
			}
			//System.out.println("count:" + cnt);
			cnt++;
		}
	}

	boolean chkTile(int x,int y,char[][] map){
		if(x < 0 || x >= map[0].length)return false;
		if(y < 0 || y >= map.length)return false;
		return map[y][x] != BLOCK && map[y][x] != CHECKED;
	}

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

/*
??£:S
?????????:X
????????°:.
???????????\??´:1,2,3,...,9
*/

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

using namespace std;
typedef long long ll;

#define MOD (long long)(1e9+7)
#define INF (1LL<<60)
#define rep(i,n) for(ll i = 0; i < (n); i++)
#define rep1(i,n) for(ll i = 1; i <= (n); i++)

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


// 最大公約数
ll gcd(ll a, ll b)
{
  if(b == 0) return a;
  return gcd(b, a % b);
}

// mod m におけるa の逆元
ll modinv(ll a, ll m) {
  ll b = m, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b; swap(a, b);
    u -= t * v; swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}

// 素因数分解
vector<pair<ll, ll>> prim;
void pf(ll n)
{
  ll s = sqrt(n);
  ll r = 0;
  for(ll i = 2; i <= s; i++) {
    if((n % i) == 0) {
      r = 0;
      do {
	r++;
	n = n / i;
      } while((n % i) == 0);
      prim.push_back({i, r});
    }
  }
  if(n > s) {
    prim.push_back({n, 1});
  }
}

void solve()
{
  ll N, K; cin >> N >> K;
  vector<ll> a(N); rep(i, N) cin >> a[i];
  
  ll ans = -1;

  for(ll ib = 0; ib < (1<<N); ib++) {
    vector<int> b(N); rep(i, N) b[i] = a[i];
    ll h = 0;
    ll co = 0;
    rep(i, N) {
      if(ib & (1<<i)) {
	if(h == 0) {
	  h = b[i];
	} else {
	  if(b[i] <= h) {
	    co += (h + 1 - a[i]);
	    b[i] = h = h + 1;
	  } else {
	    h = b[i];
	  }
	}
      }
    }
    cerr << ib << " " << co << endl;

    ll cb = 0, ch = 0;
    rep(i, N) {
      if(b[i] > ch) {cb ++; ch = b[i];}
    }
    
    if(cb >= K && (ans < 0 || co < ans)) ans = co;
  }
  
  cout << ans << endl;
}


int main(void)
{
  // ll t; cin >> t; rep(i, t)
  solve();
}


Measured memory_bytes: 3628
#include<stdio.h>

int main(void)
{

	int N,A,b=0;

	scanf("%d", &N);
	for (int i = 0;i < N;i++) {
		scanf("%d", &A);
		if (A % 2 == 0) {
			if (A % 3 == 0 || A % 5 == 0) {

			}
			else
			{
				printf("DENIED");
				return 0;
			}
		}
	}
	printf("APPROVED");
	
	return 0;
}

Measured memory_bytes: 128
import numpy as np
from sys import stdin

N, S = map(int, stdin.readline().split())
A = list(map(int, stdin.readline().split()))
M = 998244353
V = max(max(A), S)

ans = 0
cs = np.zeros(V + 1, dtype=np.int64)
for i, a in enumerate(A):
    dp = np.zeros(V + 1, dtype=np.int64)
    dp[a] = i + 1
    dp[a + 1 : S + 1] = cs[np.arange(a + 1, S + 1) - a]
    cs = (cs + dp) % M
    ans = (ans + (N - i) * dp[S]) % M
print(ans)


Measured memory_bytes: 14536
#include<iostream>
#include<cstring>
#include<algorithm>
#include<vector>
#include<cmath>
#include<limits>
#include<map>
#define ll long long
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define int_INF 2147483647
#define ll_INF 	9223372036854775807
#define vi vector<int>
#define vll vector<long long>
#define pii pair<int,int>
using namespace std;

int main(){
  string s;
  cin >> s;
  int flag  = 1;
  for(int i = 0; 2 * i + 1 < s.size();i++){
    if(s[2 * i] == 'h' && s[2 * i + 1] == 'i'){
      flag = 1;
    }
    else{
      flag = 0;
    }
  }

  if(s.size() %2 != 0){
    flag = 0;
  }

  if(flag){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}


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

int main() {
    int n;
    cin >> n;
    int N = n;
    int sum = 0;
    while (N > 0) {
        sum += N % 10;
        N /= 10;
    }
    cout << (n % sum == 0 ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int a[5];
int test(int x)
{
    int flag=1;
    int a=x/10000;
    int b=(x-a*10000)/1000;
    int d=x%10;
    int c=(x%100-x%10)/10;
    if(a!=d||b!=c) flag=0;
    return flag;
}
int main()
{
    int a,b;
    while(cin>>a>>b){
        int t=0;
        for(int i=a;i<=b;i++){
            if(test(i)) t++;
        }
        cout<<t<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define brep(i,n) for(int i=n-1;i>=0;i--)
int main(void){
    int n,k;
    int ans = INT_MAX;
    cin >> n >> k;
    int a[n];
    int memo = 0;
    bool memo2 = false;
    rep(i,n){
        cin >> a[i];
        if(a[i] < 0)memo=i+1;
        if(a[i]==0)memo2=true;
    }
    for(int i = 0;i <= k;i++){
        if(memo2){
            if(i==k||memo+i>=n||memo-k+1+i<0)continue;
            ans = min(ans,min(2*a[memo+i]-a[memo-k+1+i],a[memo+i]-2*(a[memo-k+1+i])));
        }
        else{
            if(memo+i>n||memo-k+i<0)continue;
            if (i==k)ans=min(ans,abs(a[memo+k-1]));
            else if(i==0)ans=min(ans,abs(a[memo-k]));
            else ans= min(ans,min(a[memo+i-1]*2-a[memo-k+i],a[memo+i-1]-2*(a[memo-k+i])));
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
import math
n = int(input())
li1 = [int(i) for i in input().split()]
li2 = [int(i) for i in input().split()]
D1 = 0
D2 = 0
d2 = 0
D3 = 0
d3 = 0
D8 = 0
li = []
for i in range(n):
    D1 += abs(li1[i]-li2[i])
    d2 += (li1[i]-li2[i])**2
    D2 = math.sqrt(d2)
    d3 += (abs(li1[i]-li2[i]))**3
    D3 = d3**(1/3)
    li.append(abs(li1[i]-li2[i]))
    D8 = max(li)
print(D1)
print(D2)
print(D3)
print(D8)


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

int main() {
    ll N;
    cin >> N;
    ll x[N], y[N], h[N];
    for (int i = 0; i < N; i++) {
        cin >> x[i] >> y[i] >> h[i];
    }

    ll CX, CY, Height;

    for (int cx = 0; cx <= 100; cx++) {
        for (int cy = 0; cy <= 100; cy++) {
            ll key = 0;
            for (int i = 0; i < N; i++) {
                if (h[i] != 0) {
                    key = i; break;
                }
            }
            ll H = h[key] + abs(x[key]-cx) + abs(y[key]-cy);

            bool ok = true;
            for (int i = 0; i < N; i++) {
                if (h[i] != max(H - abs(x[i]-cx) - abs(y[i]-cy), 0LL)) {
                    ok = false;
                }
            }
            if (ok) {
                CX = cx, CY = cy, Height = H;
                break;
            }
        }
    }

    cout << CX << " " << CY << " " << Height << endl;
    return 0;
}

Measured memory_bytes: 256
mod io{
    use std::io::*;
    pub fn read<T: ::std::str::FromStr>()->T{
        let stdin=stdin();
        let ret=stdin.lock().bytes().map(|c|c.unwrap()as char)
        .skip_while(|c|c.is_whitespace())
        .take_while(|c|!c.is_whitespace())
        .collect::<String>().parse().ok().unwrap();
        ret
    }
}
use io::read;
fn main(){
    let a=read::<i32>();
    let b=read::<i32>();
    let c=read::<i32>();
    let d=read::<i32>();
    println!("{} {} {} {}",b+c-d,c+d-a,a+b-d,b+c-a);
}


Measured memory_bytes: 4352
n = int(input())
s = [input() for i in range(n)]

d = {}
cnt = 0
for i in range(n):
	if s[i] in d: d[s[i]] += 1
	else: d[s[i]] = 1
	cnt = max(cnt, d[s[i]])

l = []
for i in range(n):
	if d[s[i]] == cnt:
		l.append(s[i])

l = list(set(l))
l.sort()
for i in range(len(l)):
	print(l[i])

Measured memory_bytes: 45456
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
int main(){
    
    string str, test;
    cin>>str>>test;
    
    ll ans = 0;
    
    bool ar[26], br[26];
    
    for(int i=0; i<26; i++) {
        ar[i] = br[ i] = 0;
    }
    
    for(int i=0; i< str.length() ; i++) {
        ar[str[i] - 'a'] += 1;
    }
    for(int i=0; i< test.length() ; i ++){
        br[test[i] - 'a'] += 1;
    }
    bool istrue = true;
    
    for(int i=0; i<26 ;i++){
       if(br[i]== true && ar[i] == false){
           istrue = false;
           break;
       } 
    }
    
    if(!istrue){
        cout<<"-1"<<endl;
        return 0;
    }
    else{
        vector<ll> p[26];
        
        for(int i=0; i<str.length() ; i++){
            p[str[i] - 'a'].push_back(i);
        }
        
        ll curidx = -1;
        for(int i=0 ; i<test.length() ; i++){
            ll num = test[i] - 'a';
            vector<ll> :: iterator itr;
            itr = upper_bound(p[num].begin(), p[num].end(), curidx);
            
            if(itr!=p[num].end()){
                ans = ans + (*itr - curidx);
                curidx = *itr;
            }
            else{
                ans = ans  + (str.length() - 1 - curidx);
                curidx = -1;
                vector<ll> :: iterator itr = upper_bound(p[num].begin(), p[num].end(), curidx);
                ans = ans + (*itr - curidx);
                curidx = *itr;
            }
            // cout<<ans<<endl;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1724
n=int(input())
s=[list(input()) for _ in range(n)]

l=[10**5]*28
for i in range(n):
    tmp_l=[0]*28
    for j in range(len(s[i])):
        tmp_l[ord(s[i][j])-97]+=1
    for i in range(28):
        l[i]=min(l[i], tmp_l[i])
ans=[]
for i in range(28):
    ans+=chr(i+97)*l[i]
print(''.join(ans))


Measured memory_bytes: 9128
#include<iostream>
using namespace std;
int main(){
  int ka,s,ans=0;
  cin >> ka >>s ;
  for(int i=ka;0<=i;--i){
    if(i+2*ka<s){
      break;
    }
    for(int j=ka;0<=j;--j){
      if(0<=s-i-j&&s-i-j<=ka){
       ans++; 
      }
    }
  }
  cout<<ans;
}



Measured memory_bytes: 256
n, m = map(int, input().split())
x = list(map(int, input().split()))
if m < n:
  print(0)
  exit()
x.sort()
diff = []
for i in range(m-1):
  diff.append(x[i+1] - x[i] - 1)
diff.sort(reverse=True)
print(x[-1] - x[0] + 1 - sum(diff[:n-1]) - n)

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

int main(){
	int n,m,x; cin>>n>>m>>x;
	vector<vector<int>> a(n,vector<int>(m+1));
	rep(i,n){
		cin>>a[i][0];
		for(int j=1; j<=m; j++) cin>>a[i][j];
	}
	int ans=1e9+7;
	for(int i=0; i<(1<<n); i++){
		int sum=0;
		bool flg=true;
		vector<int> u(m);
		
		for(int j=0; j<n; j++){
			if(i &(1<<j)){
				sum+=a[j][0];
				for(int k=0; k<m; k++) u[k]+=a[j][k+1];
			}
		}
		for(auto t:u) if(t<x) flg=false;
		if(flg) ans=min(ans,sum);
	}
	if(ans==1e9+7) cout<<-1<<endl;
	else cout<<ans<<endl;
}

Measured memory_bytes: 3584
import java.util.*;
//import java.util.stream.Collectors;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		int n = Integer.parseInt(sc.next());
		int k = Integer.parseInt(sc.next());
		int x = Integer.parseInt(sc.next());
		int y = Integer.parseInt(sc.next());
		
		System.out.println(n > k ? k * x + (n - k) * y : n * x);
	}
}


Measured memory_bytes: 35596
#include<iostream>
#include<atcoder/all>
using namespace std;
typedef long long li;
#define rep(i,n) for(int i=0;i<(n);i++)
#define df 0
template<class T> void print(const T& t){ cout << t << "\n"; }
template<class T, class... Ts> void print(const T& t, const Ts&... ts) { cout << t; if (sizeof...(ts)) cout << " "; print(ts...); }

int main(){
  int t; cin >>t;
  rep(_,t){
    li n,m,a,b; cin >>n >>m >>a >>b;
    print(atcoder::floor_sum(n,m,a,b));
  }
}


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

long long n;

int main() {
  cin >> n;
  long long res = 0;
  for (long long i = 1; i <= n; ++i) {
    for (int j = 1; i * j < n; ++j) ++res;
  }
  cout << res << endl;
  return 0;
}

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

using namespace std;

#define long long long
#define INF ((long) 1e18)
#define MOD ((long) 1e9 + 7)
#define mll map<long, long>
#define pll pair<long, long>
#define pb push_back
#define FOR(i, a, b) \
  for (long i = (a); i < (long) (b); i++)
#define PRINTV(v) \
  FOR (_i, 0, v.size()) \
    cout << v[_i] << " "; \
  cout << "\n";

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

  long n;
  cin >> n;

  mll d;
  FOR (i, 1, n+1) {
    d[i] = d[i-1] + 1;
    FOR (k, 1, 12) {
      long y = pow(6, k);
      if (i - y >= 0) {
        d[i] = min(d[i], d[i-y] + 1);
      }
    }
    FOR (k, 1, 12) {
      long y = pow(9, k);
      if (i - y >= 0) {
        d[i] = min(d[i], d[i-y] + 1);
      }
    }
  }
  printf("%lld\n", d[n]);
}


Measured memory_bytes: 6528
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
typedef long long       ll;
#define pb                push_back
#define mp                make_pair
#define all(a)            (a).begin(), (a).end()
#define clr(a,h)          memset(a, (h), sizeof(a))
#define mem(a,h)          memset(a, (h), sizeof(a))
#define F first
#define S second
#define f first
#define s second
#define fore(i, b, e)    for (int i = (int)b; i < (int)e; i++)
#define forr(i, b, e)    for (int i = (int)b; i < (int)e; i++)
int faster_in(){int r=0,c;for(c=getchar();c<=32;c=getchar());if(c=='-') return -faster_in();for(;c>32;r=(r<<1)+(r<<3)+c-'0',c=getchar());return r;}

using namespace std;
//using namespace __gnu_pbds;

typedef pair<int, int>  ii;
typedef vector<int>     vi;
typedef vector<ii>      vii;
typedef vector<ll>      vll;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
const int INF = int(1e9 + 7);
const double EPS = 1e-9;
const double PI = acos(-1);
bool palind(string txt)
{
    
    string rev;
    rev=txt;
    reverse(rev.begin(),rev.end());
    return rev==txt;
}
int main()
{
    std::ios::sync_with_stdio(false); cin.tie(0);
    string txt;
    cin>>txt;
    int n=txt.size();
    if (palind(txt) && palind(txt.substr(0,(n-1)/2)) && palind(txt.substr((n+3)/2LL-1)))
        cout<<"Yes\n";
    else
        cout<<"No\n";
}
// PLUS ULTRA!


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<string>
// #include<fstream>

using namespace std;

struct Node {
	int key;
	Node *parent, *left, *right;
};

Node * root = NULL;

void insert(int v) {
 	Node * newNode = (Node *)malloc(sizeof(Node));
 	newNode->key = v;
 	newNode->left = newNode->right = NULL;

 	Node * p = NULL;
 	Node * cur = root;

    while (cur != NULL) {
 		p = cur;
 		if (v > cur->key)
 			cur = cur->right;
 		else
 			cur = cur->left;
 	}

 	newNode->parent = p;

 	if (root == NULL) // if tree is empty
 		root = newNode;
 	else if (v > p->key)
 		p->right = newNode;
 	else
 		p->left = newNode;
}

Node* find(Node* curNode, int v) {
	while(curNode != NULL && curNode->key != v) {
		if (v > curNode->key)
			curNode = curNode->right;
		else
			curNode = curNode->left;
	}
	return curNode;
}


void preOrder(Node* node) {
	if (node == NULL)
		return;
	printf(" %d", node->key);
	preOrder(node->left);
	preOrder(node->right);
} 

void inOrder(Node* node) {
	if (node == NULL)
		return;
	inOrder(node->left);
	printf(" %d", node->key);
	inOrder(node->right);
}


int main() {
	int i, n, value;
	string command;
	Node * foundNode = NULL;

	// ifstream input;
	// input.open("input.txt");

	scanf("%d", &n);
	// input >> n;
	for (i = 0; i < n; i++) {
		// input >> command;
		cin >> command;
		if (command == "insert"){
			// input >> value;
			scanf("%d",&value);
			insert(value);
		}else if (command == "print"){
			inOrder(root);
			printf("\n");
			preOrder(root);
			printf("\n");
		}else if (command == "find"){
			// input >> value;
			scanf("%d",&value);
			
			foundNode = find(root, value);
			if (foundNode == NULL)
				printf("no\n");
			else
				printf("yes\n");
		}
	}

	// input.close();

	return 0;
}

Measured memory_bytes: 22032
N, M = gets.split(" ").map(&:to_i)
a = gets.split(" ").map(&:to_i)
h  = Hash.new(0)
a.each do |num|
    h[num] += 1
end

M.times do |i|
    b, c = gets.split(" ").map(&:to_i)
    h[c] += b
end

h = h.sort.reverse.to_h
ans = 0
count = 0

loop do
    tmp = h.shift.to_a
    x = tmp[0]
    y = tmp[1]
    if (count + y) < N
        ans += x * y
        count += y
    else
        ans += x * (N - count)
        break
    end
end

puts ans

Measured memory_bytes: 42448
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<list>
#include<algorithm>
#include<set>
#include<map>
#include<stack>
#include<queue>

using namespace std;

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

#define PRINT(str) printf(#str "\n")
#define yOUT PRINT(Yes)
#define nOUT PRINT(No)
#define YOUT PRINT(YES)
#define NOUT PRINT(NO)
 
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

int main(){
    int a, b;
	cin >> a >> b;
	cout << max(a,b)+ max(max(a, b)-1, min(a, b)) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define mp make_pair
#define all(a)      (a).begin(),(a).end()
#define debug_array(a,n) for (ll bccc=(0); bccc<(n); bccc++) cout<<a[bccc]<<" "<<"\n"
#define debug_vector(a) for(ll bccc=(0); bccc<(a.size());bccc++) cout<<a[bccc]<<" "<<"\n"
#define F           first
#define S           second
#define debug_set(s) for(auto p:s) cout<<p<<" "
#define debug_map(m) for(auto p:m) cout<<p.F<<" "<<p.S<<"\n"
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl;
typedef long long ll;
using namespace __gnu_pbds;
typedef tree<pair<ll,ll>,null_type,less<pair<ll,ll> >,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;

/* ll t = 0;
ordered_multiset me;
...
me.insert({x, t++});
me.erase(me.lower_bound({x, 0}));
cout << me.order_of_key({x, 0}) << "\n";

///////////   t is insertion time
*/
//#pragma GCC optimize("Ofast")  // works very well
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
typedef long double lld;
lld pi=3.14159265358;
ll powr(ll a,ll b)
{
    ll c=1;
    ll kjk;
    for(kjk=0;kjk<b;kjk++)
        c*=a;
    return c;
}
ll hell=1000000007;
//ll hell=998244353   ;
ll power(ll x, ll y, ll p)
{
    ll res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
// to generate random number , use rng() ... eg cout<<rng();
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    cout<<max(a*c,max(a*d,max(b*c,b*d)));
    return 0;
}


Measured memory_bytes: 3648
#include <stdio.h>

int main()
{
  int i, j, H, W;

  for( ; ; )
  {
    scanf("%d %d", &H, &W);

    if( H == 0 && W == 0 )
      break;

    for( i = 0 ; i < H ; i++ )
    {
      for( j = 0 ; j < W ; j++ )
      {
        printf("#");
      }
      printf("\n");
    }
    printf("\n");
  }
}



Measured memory_bytes: 2100
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <algorithm>
#include <numeric>
#include <utility>
#include <random>
#include <chrono>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>

using namespace std;

using LL = long long;
using ULL = unsigned long long;
using PII = pair<int, int>;
using PIL = pair<int, LL>;
using PLL = pair<LL, LL>;
// const int mod = 1e9 + 7;
// const int mod = 998244353;

inline void quickread() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
}

int a[410];
LL pre[410], f[410][410];
int n;

inline void work() {
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
        pre[i] = pre[i - 1] + a[i];
    }
    for (int j = 2; j <= n; ++j) {
        for (int i = j - 1; i >= 1; --i) {
            f[i][j] = LONG_MAX;
            for (int k = i; k < j; ++k) {
                f[i][j] = min(f[i][j], f[i][k] + f[k + 1][j] + (pre[j] - pre[i - 1]));
            }
        }
    }
    cout << f[1][n] << "\n";
}

int main() {
    // freopen("input.txt", "r", stdin);
    quickread();
    work();
    return 0;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
 
//DEFINE and TYPEDEF--------------------------------------------------------------
 
#define FORG(i,a,n) for(lld i=a;i<n;i++) //for - general
#define FORZ(i,n) for(lld i=0;i<n;i++) //for - zero
#define FORGI(i,a,n,inc) for(lld i=a;i<n;i+=inc) //for - general incremental
#define FORZI(i,n,inc) for(lld i=0;i<n;i+=inc) //for - zero incremental
#define DEBUG(x) cerr<<(#x)<<" is "<<(x)<<"\n" //to debug values of variables
#define ZINDA cerr<<"\nIdhar-ich hai apun!!\n"; //to debug if code reached that point
#define SPEEDUP ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
 
#define SORTall(m) sort(m.begin(),m.end());
 
#define st first
#define nd second
#define mkp make_pair
#define pb push_back
#define endl '\n'
#define mod 1000000007
 
typedef long long int lld;
typedef unsigned long long int ulld;
 
lld power(lld b, lld e)
{
    if(e==0)
        return 1;
    if(e%2==1)
        return b*power(b*b,(e-1)/2);
    else
        return power(b*b,e/2);
}
 
lld power(lld b, lld e, lld m)
{
	if(e==0)
		return 1;
	if(e%2==1)
		return b*power(((b%m)*(b%m))%m,(e-1)/2,m)%m;
	else
		return power(((b%m)*(b%m))%m,e/2,m)%m;
}
 
int nDig(lld n)
{
	if(n<0) 
		n*=-1;
	if(n==0)
		return 1;

    return floor(log10(n) + 1);
}

//endl : changed to '\n', to flush comment that definition
//--------------------------------------------------------------------------------

void swagWaalaFunction()
{
	lld a,b,c;
	cin>>a>>b>>c;

	cout<<c<<" "<<a<<" "<<b;
	return;
}

int main()
{
    SPEEDUP;
 	lld t=1;
 	//cin>>t;

 	while(t--)
 		swagWaalaFunction();

 	return 0;
}

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

N = int(input())

A = [1]
i = 1
while 6 ** i <= 100000:
    A.append(6 ** i)
    i += 1
j = 1
while 9 ** j <= 100000:
    A.append(9 ** j)
    j += 1
A.sort()  # 引き出せる金額のリスト

# i円を引き出す最小の操作回数をメモ、参照するのは常に前の値なのでループを回せる
dp = [1000000 for _ in range(N + 1)]
dp[0] = 0

for i in range(1, N+1):
    a = 0
    while 6 ** a <= i:
        # 1円,6円,36円,...を使って操作回数を減らす
        dp[i] = min(dp[i], dp[i - 6 ** a] + 1)
        a += 1
    b = 0
    while 9 ** b <= i:
        # 1円,9円,81円,...を使って操作回数を減らす
        dp[i] = min(dp[i], dp[i - 9 ** b] + 1)
        b += 1

print(dp[N])


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

int main(){
    string s, t, u; int a, b;
    cin >> s >> t >> a >> b >> u;

    if(u == s) a--;
    else b--;
    cout << a << ' ' << b << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define N 100

int main(){
  int A[N],kazu,i,j,kou,minj,kari;

  scanf("%d",&kazu);
  if(kazu>100)exit(1);
  for(i=0;i<kazu;i++){
    scanf("%d",&A[i]);
  }

  for(i=0;i<kazu;i++){
    minj=i;
    for(j=i;j<kazu;j++){
      if(A[j]<A[minj]){
	minj=j;
      }
    }
    if(i!=minj){
    kari=A[minj];
    A[minj]=A[i];
    A[i]=kari;
    kou++;
    }
  }
  for(i=0;i<kazu;i++){
    printf("%d",A[i]);
    if(i<kazu-1)printf(" ");
  }
  printf("\n%d\n",kou);

  return 0;
}



Measured memory_bytes: 2048
#include<bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define REPvec(itr, mp) for(auto itr = mp.begin();itr != mp.end(); itr ++)
#define all(x) x.begin(), x.end()
#define MOD 1000000007//1e9+7
using namespace std;
typedef long long unsigned int ll;
typedef vector<int >    vecint;
typedef vector<double >    vecd;
typedef vector<vector<int> >  vec2int;
typedef vector<vector<double> >  vec2d;
typedef vector<ll >     vecll;
typedef vector<string > vecstr;
typedef vector<bool > vecbool;
typedef vector<vector< bool > > vec2bool;
typedef vector<bool > vecbool;
////////////////////////////////////////////////
int main()
{
  string s; cin >> s;
  ll n = stoll(s);
  ll m = 9*(s.size() - 1);
  ll c = stoll(s.substr(0,1));
  if((c + 1)*pow(10,s.size() - 1) > n + 1 ){
    cout << (c - 1) + m << endl;
  }else{
    cout << c + m << endl;
  }
} 

Measured memory_bytes: 384
N = int(input())
a = list(map(int, input().split()))
cnt1 = 0
li1 = []
for i in range(1,N):
    M = max(a)
    num = 0
    for j in range(N):
        if a[j] == M:
            n = j
    if a[i] < a[i-1]:
        if M <= 0:
            cnt1= -1
            break
        num += -((-a[i-1]+a[i])//M)
        if num < 0 or num > 2*N:
            cnt1 = -1
            break
        a[i] += num*M
        for j in range(num):
            li1.append([n+1, i+1])
        cnt1 += num
cnt2 = 0
li2 = []
for i in range(1,N):
    M = min(a)
    num = 0
    for j in range(N):
        if a[j] == M:
            n = j
    if a[N-i] < a[N-i-1]:
        if M >= 0:
            cnt2 = -1
            break
        num += -((-a[N-i-1]+a[N-i])//(-M))
        if num < 0 or num > 2*N:
            cnt2 = -1
            break
        a[N-i-1] += num *M
        for j in range(num):
            li2.append([n+1, N-i])
        cnt2 += num
if cnt1 <= 2*N and cnt1 >= 0:
    print(cnt1)
    for x in li1:
        print(*x)
else:
    print(cnt2)
    for x in li2:
        print(*x)

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

int main() {
	int x; cin >> x;
	if (x == 1) {
		cout << 1 << endl;
		return 0;
	}

	vector<int>nums;
	for (int i = 2; i <= x; i++) {
		int tmp = i * i;
		while (tmp <= x) {
			nums.push_back(tmp);
			tmp *= i;
		}
	}
	sort(nums.rbegin(), nums.rend());
	cout << nums[0] << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<stack>
#include<algorithm>
#include<queue>
#include<cmath>
#include<numeric>
#include<map>
#include<set>
#include<vector>
#include<list>
#include<iomanip>
#include<functional>
#include<bitset>

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

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

bool check(vector<P> s){
    int h = 0;
    for(P p:s){
        int b = h+p.first;
        if(b <0) return false;
        h += p.second;
    }
    return true;
}

int main(){
    int n;
    cin>>n;
    vector<P> ls,rs;
    int total = 0;
    rep(i,n){
        string s;
        cin>>s;
        int h = 0,b=0;
        for(char c:s){
            if(c=='(') ++h;else --h;
            b = min(b,h);
        }
        if(h>0) ls.emplace_back(b,h);
        else rs.emplace_back(b-h,-h);
        total += h;
    }
    sort(ls.rbegin(),ls.rend());
    sort(rs.rbegin(),rs.rend());
    if(check(ls) && check(rs) && total == 0){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }


    return 0;
}

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

int main () {
  int a;
  cin >> a;

  int a2 = a * a;
  int a3 = a * a * a;

  cout << a + a2 + a3;
}

Measured memory_bytes: 3620
N,M = gets.split.map(&:to_i)

g = Array.new(N){Array.new(N)}

M.times do |i|
  
  a,b = gets.split.map(&:to_i).sort.reverse
  a -= 1
  b -= 1
  g[a][b] = g[b][a] = 1
end

pattern = [*1...N].permutation(N-1).to_a.map{ |k| [0] + k }

ans = 0
pattern.each do |p|
  
  f = true
  (1...N).each do |i|
    p [p[i-1], p[i]]
    if g[p[i-1]][p[i]].nil?
      f = false
      break
    end
  end
  ans += 1 if f
end

puts ans

Measured memory_bytes: 3452
#include <iostream>

using namespace std;

int main(){
	int n;
	cin >> n;
	int p[n];
	
	int w_count = 0;
	
	for(int i = 0; i < n; i++){
		cin >> p[i];
		if(p[i] != i+1){
			w_count++;
		}
	}
	
	if(w_count <= 2) cout << "YES";
	else cout << "NO";
	cout << endl;
	
}

Measured memory_bytes: 3572
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  int cnt = 0;
  for(int i=1;i<=n;i++){
    if(((int)(log10(i))+1)%2==1){
      cnt++;
    }
  }
  cout<<cnt<<endl;
  return 0;
}


Measured memory_bytes: 512
while True:
  h, w = map(int, raw_input().split())
  if (h == 0 and w == 0):
    break
  wi = int(w)
  for i in range(0,h):
    if i % 2 == 0:
      if w % 2 == 0: print('#.' * (wi / 2))
      else: print('#.' * (wi / 2) + '#')
    else:
      if w % 2 == 0: print('.#' * (wi / 2))
      else: print('.#' * (wi / 2) + '.') 
  print

  

Measured memory_bytes: 6444
import java.util.*;

public class Main {
    public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int n = sc.nextInt();
	String s = sc.next();
	char[] a = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
	StringBuilder sb = new StringBuilder();
	for (int i=0; i<s.length(); i++) {
	    sb.append(a[(re(s.charAt(i)) + n) % 26]);
	}
	System.out.print(sb.toString());
    }
    static int re(char is) {
	int r = 0;
	switch(is) {
	case 'A' : r = 0; break;
	case 'B' : r = 1; break;
	case 'C' : r = 2; break;
	case 'D' : r = 3; break;
	case 'E' : r = 4; break;
	case 'F' : r = 5; break;
	case 'G' : r = 6; break;
	case 'H' : r = 7; break;
	case 'I' : r = 8; break;
	case 'J' : r = 9; break;
	case 'K' : r = 10; break;
	case 'L' : r = 11; break;
	case 'M' : r = 12; break;
	case 'N' : r = 13; break;
	case 'O' : r = 14; break;
	case 'P' : r = 15; break;
	case 'Q' : r = 16; break;
	case 'R' : r = 17; break;
	case 'S' : r = 18; break;
	case 'T' : r = 19; break;
	case 'U' : r = 20; break;
	case 'V' : r = 21; break;
	case 'W' : r = 22; break;
	case 'X' : r = 23; break;
	case 'Y' : r = 24; break;
	case 'Z' : r = 25; break;
	}
	return r;
    }
}


Measured memory_bytes: 36556
#include <bits/stdc++.h>
using namespace std;
int main () {
    int N;
    cin >> N;
    vector<long long> a(N);
    for (int i = 0; i < N; i++) {
        cin >> a[i];
    }
    vector<pair<int, int>> ans;
    int m = min_element(a.begin(), a.end()) - a.begin(), M = max_element(a.begin(), a.end()) - a.begin();
    if (!(a[m] >= 0 || a[M] <= 0)) {
        if (abs(a[m]) >= abs(a[M])) {
            for (int i = 0; i < N; i++) {
                if (a[i] > 0) {
                    a[i] += a[m];
                    ans.push_back(make_pair(m, i));
                }
            }
        }
        else {
            for (int i = 0; i < N; i++) {
                if (a[i] < 0) {
                    a[i] += a[M];
                    ans.push_back(make_pair(M, i));
                }
            }
        }
    }
    if (*min_element(a.begin(), a.end()) >= 0) {
        for (int i = 1; i < N; i++) {
            if (a[i-1] > a[i]) {
                a[i] += a[i-1];
                ans.push_back(make_pair(i-1, i));
            }
        }
    }
    else {
        for (int i = N-1; i > 0; i--) {
            if (a[i-1] > a[i]) {
                a[i-1] += a[i];
                ans.push_back(make_pair(i, i-1));
            }
        }
    }
    cout << ans.size() << endl;
    for (auto w: ans) {
        cout << w.first+1 << " " << w.second+1 << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    int b, r, g, c, s, t;
    while (true) {
        cin >> b >> r >> g >> c >> s >> t;
        if (t == 0) {
            return 0;
        }
        cout << 100 + 13 * (5 * b + 3 * r) + (7 * g) + (2 * c) - 3 * (t - s - 5 * b - 3 * r) + 15 * (b + r) << endl;
    }
}

Measured memory_bytes: 1160
N,K=map(int,input().split())
R,S,P=map(int,input().split())
T=list(input())
L=[]

for i in range(K):
    L.append(T[i::K])
#print(L)

def ranlength(A):
    num = list(A)
    count = 1
    result = ''
    table = []
    for i in range(len(num)):
        try:
            if num[i] == num[i+1]:
               count = count + 1
            else:
                result += str(num[i])
                table.append(count)
                count = 1
        except:
            result += str(num[i])
            table.append(count)
    return(result,table)

def Point(List):
    score=0
    RR=ranlength(List)
    word=RR[0]
    table=RR[1]
    for i in range(len(word)):
        if word[i]=='p':
            score+=(-(-table[i]//2))*S
        elif word[i]=='s':
            score+=(-(-table[i]//2))*R
        else:
            score+=(-(-table[i]//2))*P
#    print(word,table,score)
    return score

M=0
for i in L:
    M+=Point(i)

print(M)

Measured memory_bytes: 12752
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>

#define INFINITE 1000000
#define USED -1
// Maximum number of nodes
#define NODENUM 100

#define SIZE 100
#define MAX(a, b) ((a) > (b) ? (a) : (b))

int parent[SIZE];
int depth[SIZE];

typedef struct pair {
    int first;
    int second;
} Pair;

// 隣接行列. 辺が使用済みの場合はUSEDにする
int dist[NODENUM][NODENUM];

int find(int x) {
    if (parent[x] == x)
        return x;
    return parent[x] = find(parent[x]);
}

void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y)
        return;
    if (depth[x] < depth[y]) {
        int tmp = x;
        x = y;
        y = tmp;
    }
    // depth[x] > depth[y]
    parent[y] = x;
    depth[x] = MAX(depth[x], depth[y] + 1);
}

// 重さ最小の枝を見つける(heapは面倒なので使わない)
Pair findMinEdge(int n) {
    int min = INFINITE;
    Pair minPair;
    int flag = 0;
    int i, j;
    for (i = 0; i < n; i++) {
        for (j = i; j < n; j++) {
            if (dist[i][j] != USED && dist[i][j] < min) {
                min = dist[i][j];
                minPair.first = i;
                minPair.second = j;
                flag = 1;
            }
        }
    }
    if (!flag) {
        minPair.first = -1;
        return minPair;
    }
    return minPair;
}

int kruscal(int nodeNum)
{
    int i, j, k;
    long weight = 0;
    for (i = 0; i < nodeNum; i++)
        parent[i] = i;
    Pair p = findMinEdge(nodeNum);
    while (p.first != -1) {
        if (find(p.first) != find(p.second)) {
            unite(p.first, p.second);
            weight += dist[p.first][p.second];
        }
        dist[p.first][p.second] = USED;
        dist[p.second][p.first] = USED;
        p = findMinEdge(nodeNum);
    }
    return weight;
}

int main (void)
{
    int c, r;
    for (c = 0; c < NODENUM; c++)
        for (r = 0; r < NODENUM; r++)
            dist[c][r] = (c == r)? 0 : INFINITE;
    int n, i, j;
    scanf("%d", &n);
    for (i = 0; i < n; i++) {
        for (j = 0; j < n; j++) {
            scanf("%d", &dist[i][j]);
            if (dist[i][j] == -1)
                dist[i][j] = INFINITE;
        }
    }
    printf("%d\n", kruscal(n));
    return 0;
}


Measured memory_bytes: 1832
a, b, c, x, y = map(int, input().split())

set_ga_otoku = c * 2 < a + b
nimai_ga_otoku_a = c * 2 < a
nimai_ga_otoku_b = c * 2 < b

dup = min(x, y)
cost = c * 2 * dup if set_ga_otoku else a * dup + b * dup

x, y = map(lambda x: x - dup, [x, y])

if x:
    cost += c * 2 * x if nimai_ga_otoku_a else a * x
else:
    cost += c * 2 * y if nimai_ga_otoku_b else b * y

print(cost)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
const int INF = 2147483647;
using ll = long long;

int main(){
    int n;
    cin >>n;
    vector<int> a(n);
    for(int i=0;i<n;i++){
        cin >> a.at(i);
    }
        bool ok=true;

    for(int i=0;i<n;i++){
        if (a.at(i)%2 == 0){
            if(a.at(i)%3!=0 && a.at(i)%5!=0)
                ok =false;
        }
    }
    if(ok) cout << "APPROVED" <<endl;
    else cout << "DENIED"  <<endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<string>
#include<cmath>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> P_;
struct P2{
public:
  ll x,y,idx;
  P operator - (P2 p){
    return P(x-p.x,y-p.y);
  }
  bool operator < (P2 p){
    if(x==p.x) return y<p.y;
    return x<p.x;
  }
};
ll det(P p1,P p2){
  return p1.first*p2.second-p2.first*p1.second;
}
vector<P2> convex(vector<P2> vec,int n){
  sort(vec.begin(),vec.end());
  int k=0;
  vector<P2> qs(n*2);
  for(int i=0;i<n;i++){
    while(k>1&&det((qs[k-1]-qs[k-2]),(vec[i]-qs[k-1]))<0) k--;
    qs[k++]=vec[i];
  }
  for(int i=n-2,t=k;i>=0;i--){
    while(k>t&&det((qs[k-1]-qs[k-2]),(vec[i]-qs[k-1]))<0) k--;
    qs[k++]=vec[i];
  }
  qs.resize(k-1);
  return qs;
}
vector<P2> v;
vector<P> node[105];
double prim(vector<bool> used,int n){
  ll mincost[105];
  double ret=0.0;
  for(int i=0;i<105;i++) mincost[i]=174417441744;
  for(int i=0;i<105;i++){
    if(!used[i]){
      for(int j=0;j<node[i].size();j++){
        int to=node[i][j].first;
        if(used[to]) mincost[i]=min(mincost[i],node[i][j].second);
      }
    }
  }
  while(true){
    int v=-1;
    for(int i=0;i<n;i++){
      if(!used[i]&&(v==-1||mincost[i]<mincost[v])) v=i;
    }
    if(v==-1) break;
    used[v]=true;
    ret+=(double)sqrt((double)mincost[v]);
    //cout<<"V:"<<v<<" "<<mincost[v]<<endl;

    for(int i=0;i<node[v].size();i++){
      int to=node[v][i].first;
      mincost[to]=min(mincost[to],node[v][i].second);
    }
  }
  return ret;
}
int main(){
  int n,m;
  cin>>n>>m;
  for(int i=0;i<n;i++){
    ll a,b;
    cin>>a>>b;
    P2 p;
    p.x=a;
    p.y=b;
    p.idx=i;
    v.push_back(p);
  }
  for(int i=0;i<m;i++){
    int a,b;
    cin>>a>>b;
    a--;
    b--;
    ll distx2=(v[a].x-v[b].x)*(v[a].x-v[b].x);
    ll disty2=(v[a].y-v[b].y)*(v[a].y-v[b].y);
    ll cost=distx2+disty2;
    node[a].push_back(P(b,cost));
    node[b].push_back(P(a,cost));
  //  cout<<cost<<endl;
  }

  vector<P2> totuho=convex(v,n);
  /*for(int i=0;i<totuho.size();i++){
    cout<<totuho[i].x<<" "<<totuho[i].y<<" "<<totuho[i].idx<<endl;
  }*/

  vector<P> ans_v;
  for(int i=0;i<totuho.size()-1;i++){
    ans_v.push_back(P(totuho[i].idx,totuho[i+1].idx));
  }
  ans_v.push_back(P(totuho[0].idx,totuho[totuho.size()-1].idx));

  vector<bool> used(105);
  for(int i=0;i<105;i++) used[i]=false;
  for(int i=0;i<totuho.size();i++) used[totuho[i].idx]=true;

  double ans=prim(used,n);
  //cout<<ans<<endl;
  for(int i=0;i<ans_v.size();i++){
    int p1=ans_v[i].first,p2=ans_v[i].second;
    ll distx2=(v[p1].x-v[p2].x)*(v[p1].x-v[p2].x);
    ll disty2=(v[p1].y-v[p2].y)*(v[p1].y-v[p2].y);
    ll dist=distx2+disty2;
    ans+=(double)sqrt((double)dist);
  }
  cout<<fixed;
  cout<<setprecision(10)<<ans<<endl;
}



Measured memory_bytes: 3320