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

using namespace std;

int main()
{
    int n, m;
    cin >> n >> m;

    vector<int> ac(n), pena(n);
    for (int i = 0; i < m; i++)
    {
        int p;
        string s;
        cin >> p >> s;
        --p;

        if (ac[p]) {
            continue;
        }
        if (s == "AC") {
            ac[p] = 1;
        } else {
            pena[p]++;
        }
    }
    
    int AC = 0, PENA = 0;
    for (int i = 0; i < n; i++)
    {
        AC += ac[i];
        if (ac[i]) {
            PENA += pena[i]; 
        }
    }
    cout << AC << " " << PENA << endl;
    return 0;
}


Measured memory_bytes: 1024
import java.util.Scanner;

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

		// input
		final int NUM = scan.nextInt();
		int[] answer = new int[NUM];
		for(int i = 0; i < NUM; i++){	// init
			answer[i] = Integer.MAX_VALUE;
		}
		for(int i = 0; i < NUM -1; i++){
			int temp = scan.nextInt();
			if(temp < answer[i]){
				answer[i] = temp;
			}
			if(temp < answer[i+1]){
				answer[i+1] = temp;
			}
		}
		
		// sum
		int sum = 0;
		for(int i = 0; i < NUM; i++){
			sum += answer[i];
		}
		
		// answer
		System.out.println(sum);
		
	}
}

Measured memory_bytes: 23764
import math
A, B, H, M = map(int,input().split())
k = 0.5*(60*H + M) - 6*M
l = abs(k)

if l <= 180:
    c = math.radians(l)
    C = math.cos(c)
    Q = math.sqrt(A**2 + B**2 - 2*A*B*C)
    print(Q)
else:
    w = 360-l
    c = math.radians(w)
    C =math.cos(c)
    Q = math.sqrt(A**2 + B**2 - 2*A*B*C)
    print(Q)

Measured memory_bytes: 9568
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,a,b,c,d;
	char s[200005];
	cin>>n>>a>>b>>c>>d;
	for(int i=1;i<=n;i++)
	{
		cin>>s[i];
	}
	int tot=0;
	for(int i=a;i<=max(c,d);i++)
	{
		if(s[i]=='#'&&s[i+1]=='#')
		{
			tot=1;
			break;
		}
	}
	if(c==d||tot)
	{
		cout<<"No";
	}
	else
	{
		if(c<d)
		{
			cout<<"Yes";
		}
		else
		{
			int flag=0;
			for(int i=b;i<=d;)
			{
				if(s[i-1]=='.'&&s[i+1]=='.')
				{
					flag=1;
					break;
				}
				if(s[i+1]=='.')
				{
					i+=1;
				}
				else if(s[i+2]=='.')
				{
					i+=2;
				}
			} 
			if(flag)
			{
				cout<<"Yes";
			}
			else
			{
				cout<<"No";
			}
		}
	}
	return 0; 
}

Measured memory_bytes: 384
import itertools
n = int(input())
a = list(map(int, input().split()))
#互いに素なa,bについて、a*x+b*y=1の一つの解
def mod_combination(n,k,mod):
    if k == 0:
        return 1
    return (n*mod_inv(k,mod) * mod_combination(n-1,k-1,mod) ) % mod
def extgcd(a,b):
    r = [1,0,a]
    w = [0,1,b]
    while w[2]!=1:
        q = r[2]//w[2]
        r2 = w
        w2 = [r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
        r = r2
        w = w2
    #[x,y]
    return [w[0],w[1]]

# aの逆元(mod m)を求める。(aとmは互いに素であることが前提)
#a/b = a*(b`)となるb`を求める
mod = 10**9+7
def mod_inv(a,mod):
    x = extgcd(a,mod)[0]
    return (mod+x%mod)%mod
combi = [0 for i in range(n+2)]
combi[0] = 1
for i in range(1,n+2):
    combi[i] = (combi[i-1]*(n-i+2)*mod_inv(i,mod)) % mod
kind = set()
left = -1
right = -1
for i in range(n+1):
    if a[i] in kind:
        right = (n - i)
        left = a.index(a[i])
        break
    else:
        kind.add(a[i])
combi_remain = [0 for i in range(left + right+3)]
combi_remain[0] = 1
for i in range(1,left+right+2):
    combi_remain[i] = (combi_remain[i-1]*(left+right-i+1)*mod_inv(i,mod)) % mod
for i in range(1,n+2):
    if i-1 <= left+right:
        print((combi[i] - combi_remain[i-1]) % mod)
    else:
        print(combi[i]%mod)
  

Measured memory_bytes: 77932
#include<bits/stdc++.h>
using namespace std;
 
int n,C;
int t[100];
 
int main(){
  cin>>n;
  while(n)t[C++]=n%3,n/=3;
  string ans="";
  for(int i=0;i<=C;i++){
    if(t[i]==0){
      if(i==C)break;
      ans.push_back('0');
    }else if(t[i]==1){
      ans.push_back('+');
    }else if(t[i]==2){
      ans.push_back('-');
      t[i+1]++;
    }else if(t[i]==3){
      ans.push_back('0');
      t[i+1]++;
    }
  }
  reverse(ans.begin(),ans.end());
  cout<<ans<<endl;
  return 0;
}

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

long long gcd(long long a, long long b) {
	if (b == 0) return a;
	else return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
	return a * b / gcd(a, b);
}
using namespace std;
int main() {
	long long A, B, C, D;
	cin >> A >> B >> C >> D;
	long long CNum = B / C - (A - 1) / C;
	long long DNum = B / D - (A - 1) / D;
	long long CDlcm = lcm(C, D);
	long long CDNum = B / CDlcm - (A - 1) / CDlcm;
	cout << B - A + 1 - (CNum + DNum - CDNum) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <numeric>
#include <queue>
#include <vector>
#include <cmath>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <set>
#include <map>
#include <stack>

using namespace std;

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

typedef long long LL;
typedef pair<int, int> PII;

#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repl(i, n) for(LL i = 0; i < (LL)(n); i++)

int main(void){
  string s;
  cin >> s;

  if (s == "ABC") {
    cout << "ARC" << endl;
  } else {
    cout << "ABC" << endl;
  }

  return 0;
}

Measured memory_bytes: 3596
N=int(input())
S=list(map(int,input().split()))


T=sum(S)
L=sum(S)
M=0
U=[]
Q=T/2
for i in range(len(S)):
  M=M+S[i]
  T=T-S[i]
  L=min(L,abs(M-T))
print(L)

Measured memory_bytes: 3060
#include <iostream>

int main()
{
    int sss;
    std::cin >> sss;

    int s_1=sss/100, s_2=(sss-100*s_1)/10, s_3=(sss-100*s_1-10*s_2);
    int ans = s_1 + s_2 + s_3;

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

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

int main(){
    ll n;
    cin >> n;
    string ans;
    while(n > 0){
        ans.push_back('a'+ (n-1) % 26);
        n = (n-1) / 26;
    }
    reverse(ans.begin(),ans.end());
    cout << ans << endl;
}

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



int main(){
    stack<int> s1;
    stack<pair<int,int> > s2;
    char ch;
    int total_area = 0;
    for(int i=0;cin>>ch;++i){
        if(ch == '\\') s1.push(i);
        else if(ch == '/' && s1.size()>0){
            int pos = s1.top();
            s1.pop();
            total_area += (i-pos);
            int value = (i-pos);
            while(s2.size()>0 && pos<s2.top().first){
                value += s2.top().second;
                s2.pop();
            }
            s2.push(make_pair(pos, value));
        }
    }
    list<int> s3;
    while(s2.size()>0){
        s3.push_front(s2.top().second);
        s2.pop();
    }
    printf("%d\n",total_area);
    list<int>::iterator it = s3.begin();
    printf("%d",s3.size());
    for(it;it != s3.end();it++){
        printf(" %d",*it);
    }
    printf("\n");
    return 0;
}
//\\///\_/\/\\\\/_/\\///



Measured memory_bytes: 3364
import java.util.Scanner;


public class Main {
  public static void main(String[] arg){
    // input
    Scanner scan = new Scanner(System.in);
    String[] line = scan.nextLine().split(" ");
    String s = line[0];
    String t = line[1];
    String[] line2 = scan.nextLine().split(" ");
    int a = Integer.parseInt(line2[0]);
    int b = Integer.parseInt(line2[1]);
    String u = scan.nextLine();


    // condition process
    if(u.equals(s)){
      a = a - 1;
    }else{
      b = b - 1;
    }

    // output
    System.out.println(a + " " + b);

  }
}


Measured memory_bytes: 23636
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010


int main() {
  int A, B;

  cin >> A >> B;

  if (A >= 13)
    cout << B << endl;
  else if (A >= 6)
    cout << B / 2 << endl;
  else
    cout << 0 << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <cmath>

#define FOR(i, f, n) for(int (i) = (f); (i) < (n); (i)++)
#define RFOR(i, f, n) for(int (i) = (f); (i) >= (n); (i)--)
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for(int (i) = (n); (i) >= 0; (i)--)
#define step(i, f, n, a) for(int (i) = (f); (i) < (n); (i)+=a)
#define rstep(i, f, n, a) for(int (i) = (f); (i) >= (n); (i)-=a)
#define p(...) printf(__VA_ARGS__); cout << endl;
#define gets(x) x; cin >> x;
#define puts(x) x; cout << x << endl;
#define list_input(x, n) x[(n)]; for(int (i) = 0; (i) < (n); (i)++) cin >> x[i];
#define lambda(a, b, c) [](const a, const b){ return c ;}
#define key(t, x, compare) [](const t& a, const t& b){ return a x compare b x ;}

using namespace std;

using ll = long long;
using pii = pair<int, int>;

int main(){
	ll s, c, result;
	gets(s) gets(c)
	if (c/2 <= s){
		result = c/2;
	}else{
		result = s;
		c = c-(s*2);
		result += c/4;
	}
	puts(result)
}


Measured memory_bytes: 256
module deque_mod
    use,intrinsic :: iso_fortran_env
    implicit none
    type deque
        integer(int32),pointer:: v(:)
        integer(int32):: l,r
        integer(int32):: lmax, rmax
    end type
    private
    public:: deque
    public:: init_deque
    public:: append, appendleft
    public:: pop, popleft
    public:: right, left
    public:: remaining_elements
    public:: remain

contains
    subroutine init_deque(dq)
        ! 初期化
        type(deque):: dq
        dq%r=0; dq%rmax=1
        dq%l=1; dq%lmax=-1
        allocate(dq%v(dq%lmax:dq%rmax))
    end subroutine


    subroutine append(dq,num)
        ! 右端に挿入
        type(deque):: dq
        integer(int32):: num
        if (dq%r+1 > dq%rmax) call add_(dq)
        dq%r=dq%r+1
        dq%v(dq%r) = num
    end subroutine

    subroutine appendleft(dq,num)
        ! 左端に挿入
        type(deque):: dq
        integer(int32):: num
        if (dq%l-1 < dq%lmax) call add_(dq)
        dq%l=dq%l-1
        dq%v(dq%l) = num
    end subroutine

    subroutine add_(dq)
        ! arrayの延長
        type(deque):: dq
        integer(int32):: l
        integer(int32),pointer:: tmp(:)
        l = size(dq%v)
        allocate(tmp(l))
        tmp(:) = dq%v(:)
        deallocate(dq%v)
        allocate(dq%v(2*dq%lmax:2*dq%rmax))
        dq%v(dq%lmax:dq%rmax) = tmp(:)
        dq%lmax = 2*dq%lmax
        dq%rmax = 2*dq%rmax
    end subroutine


    function pop(dq) result(ret)
        ! 右端から取り出し
        type(deque):: dq
        integer(int32):: ret
        ret = dq%v(dq%r)
        dq%r=dq%r-1
    end function

    function popleft(dq) result(ret)
        ! 左端から取り出し
        type(deque):: dq
        integer(int32):: ret
        ret = dq%v(dq%l)
        dq%l=dq%l+1
    end function


    function right(dq) result(ret)
        ! 右端を確認
        type(deque):: dq
        integer(int32):: ret
        ret = dq%v(dq%r)
    end function

    function left(dq) result(ret)
        ! 左端を確認
        type(deque):: dq
        integer(int32):: ret
        ret = dq%v(dq%l)
    end function

    function remaining_elements(dq) result(ret)
        ! 残りの要素数
        type(deque):: dq
        integer(int32):: ret 
        ret = dq%r - dq%l + 1
    end function

    function remain(dq) result(ret)
        ! 要素が残っているかどうか
        type(deque):: dq
        logical:: ret
        ret = remaining_elements(dq) > 0
    end function
end module


program name
    use,intrinsic :: iso_fortran_env
    use deque_mod
    implicit none
    integer(int32):: n,i
    integer(int32), allocatable:: a(:), ans(:)
    type(deque):: b

    call init_deque(b)
    read*, n
    allocate(a(n),ans(n))
    read*, a(:)

    do i=1,n
        if (mod(i,2) == 1) then
            call append(b,a(i))
        else
            call appendleft(b,a(i))
        end if
    end do

    if (mod(n,2) /= 0) then
        do i=1,n
            ans(i) = pop(b)
        end do
    else
        do i=1,n
            ans(i) = popleft(b)
        end do
    end if

    print'(100000(i0,1x))', ans(:)




end program name

Measured memory_bytes: 7924
using System;

class Program
{
    static void Main(string[] args)
    {
        int a = int.Parse(Console.ReadLine());
        int b = int.Parse(Console.ReadLine());
        int h = int.Parse(Console.ReadLine());

        int S = (a + b) * h / 2;

        Console.WriteLine(S.ToString());
    }
}


Measured memory_bytes: 2648
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<queue>
#include<stack>
#include<map>

using namespace std;

template<typename A, typename B> bool chmin(A &a, const B &b){ return b < a && (a = b, true); }
template<typename A, typename B> bool chmax(A &a, const B &b){ return a < b && (a = b, true); }

int main(){
  int a,b;
  cin >> a >> b;
  if (a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0){
    cout << "Possible\n";
  }
  else{
    cout << "Impossible\n";
  }
  return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

N, K = map(int, input().split())
MOD = 10 ** 9 + 7

ans = 0
for i in range(K, N + 2):
    mi = (i - 1) * i // 2
    ma = (N + N - i + 1) * i // 2
    ans += (ma - mi + 1)

print(ans % MOD)


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

int main() {
    string S;
    cin >> S;
    int a = 1000;
    for (int i = 0; i < S.size() - 2; i++) {
        a = min(abs(753 - ((S.at(i) - '0') * 100 + (S.at(i + 1) - '0') * 10 + S.at(i + 2) - '0')), a);
    }
    cout << a << endl;
}

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

struct Edge {
  int to;
  int id;
  Edge(int t, int i) : to(t), id(i) {}
};

vector<vector<Edge>> g;
vector<bool> seen;
vector<int> ans;

void dfs(const vector<vector<Edge>> &g, int vertex, int c = -1) {
  seen.at(vertex) = true;
  int color = 1;

  for (int i = 0; i < g.at(vertex).size(); i++) {
    int next_v = g.at(vertex).at(i).to, ei = g.at(vertex).at(i).id;

    if (seen.at(next_v)) continue;
    if (color == c) color++;
    ans.at(ei) = color;
    color++;
    dfs(g, next_v, ans.at(ei));
  }
}

int main() {
  int N;
  cin >> N;
  int edge_num = N - 1;
  int from, to;
  g.resize(N);
  seen.assign(N, false);
  ans.resize(edge_num);
  for (int i = 0; i < edge_num; i++) {
    cin >> from >> to;
    from--; to--;
    g.at(from).push_back(Edge(to, i));
    g.at(to).push_back(Edge(from, i));
  }
  dfs(g, 0);

  int color_max = 0;
  for (int i = 0; i < N; i++) {
    color_max = max(color_max, static_cast<int>(g.at(i).size()));
  }
  cout << color_max << endl;
  for (int i = 0; i < edge_num; i++) {
    cout << ans.at(i) << endl;
  }
}


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

string s;

int main(){
  cin >> s;
  int n = s.size();
  long long int res = 0;
  for(int S = 0; S < (1 << n - 1); S++){
    long long int add = s.at(0) - '0';
    for(int i = 1; i < n; i++){
      if(S & (1 << i - 1)){
        //cerr << add << endl;
        res += add;
        add = s.at(i) - '0';
      }else{
        add *= 10LL;
        add += s.at(i) - '0';
      }
    }
    //cerr << add << endl;
    res += add;
  }
  cout << res << endl;
  return 0;
}


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

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

    x -= a;
    if (x <= 0) {
        std::cout << 0 << std::endl;
        return 0;
    }

    if (x < b) {
        std::cout << x << std::endl;
        return 0;
    }

    int num = x / b;
    x -= b * num;

    std::cout << x << std::endl;

    return 0;
}

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

int main()
{
    int N,k;
    cin>>N>>k;
    vector <long long> a(N);
    long long count=0;
    for(int i=0;i<N;i++)
    {
        cin>>a[i];
    }

    sort(a.begin(),a.end(),greater<long long>());

    for(int i=k;i<N;i++)
    {
        count+=a[i];
    }
    cout<<count<<endl;
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <sstream>
#include <string>
#include <cmath>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)

int main()
{
  string a, b;
  cin >> a >> b;
  stringstream ss;
  ss << a + b;
  int n, work;
  ss >> n;
  work = sqrt(n);
  if (work * work == n)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


Measured memory_bytes: 256
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
#include<memory>
using namespace std;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
/*
cout<<setprecision(20);
cin.tie(0);
ios::sync_with_stdio(false);
*/
const llint mod=924844033;
const llint big=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-15;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
int main(void){
	cout<<setprecision(20);
	cin.tie(0);
	ios::sync_with_stdio(false);
	llint n,i,j;cin>>n;
	vector<llint>usa;
	usa.reserve(n+n+10);
	for(i=2;;i++){
		bool ok=1;
		for(j=2;j*j<=i;j++){
			if(i%j==0){ok=0;break;}
		}
		if(ok){usa.pub(i);if(usa.size()>=n+n+10){break;}}
	}
	int m=n;
	if(n%2==1){m++;}
	for(i=0;i<n;i++){
		for(j=0;j<n;j++){
			if((i+j)%2==0){//大
				llint ans=1;
				int x=(i+j)/2;
				//xとx+1
				ans*=usa[x];
				ans*=usa[x+1];
				int y=(i+m-j)/2 +2;
				ans*=usa[n+5+y];
				ans*=usa[n+6+y];
				cout<<ans+1;
			}else{
				llint ans=1;
				int x=(i+j)/2;
				//xとx+1
				ans*=usa[x+1];
				int y=(i+m-j)/2 +2;
				ans*=usa[n+6+y];
				cout<<ans;
			}
			if(j+1<n){cout<<" ";}
		}
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 3200
#include<stdio.h>


int main()
{
	int t, h,s,t1,h1,s1, sum, sum1;
	
	while (1)
	{
		scanf("%d %d %d",&t,&h,&s);
		if (t == -1 && h == -1 && s == -1)
		{
			break;
		}

		sum = 120 * 60 - t * 3600 - h * 60 - s;

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


		sum *= 3;
		t = sum / 3600;
		h = (sum - t * 3600) / 60;
		s = (sum - t * 3600 - h * 60);
		printf("%02d:%02d:%02d\n", t, h, s);

		/*sum1 = sum * 3;
		t1 = sum1 / 3600;
		h1= (sum1 - t1 * 3600) / 60;
		s1 = (sum1 - t1 * 3600 - h1 * 60);
		printf("%02d:%02d:%02d\n", t1, h1, s1);*/

	}


	return 0;
}


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

using namespace std;
typedef  long long int ll;
#define rep(i, n) for (int i = 0; i < (n); i++)

string s, t;
vector<string> v;
bool isMatch(string a, string b) {

    for(int i = 0; i < a.size(); i++) {
        if (a[i] != '?' && a[i] != b[i])
            return false;
    }
    return true;
}

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

    if (s.size() < t.size()) {
        cout << "UNRESTORABLE" << endl;
        return 0;
    }

    for (int i = 0; i <= s.size() - t.size(); i++) {
        if (isMatch(s.substr(i, t.size()), t)) {
            string ts = "";
            for (int j = 0; j < i; j++) {
                if (s[j] == '?')
                    ts += "a";
                else
                    ts += s[j];
            }
            ts += t;
            for (int j = i+t.size(); j < s.size(); j++) {
                if (s[j] == '?')
                    ts += "a";
                else
                    ts += s[j];
            }
            v.push_back(ts);
        }
    }
    sort(v.begin(), v.end());
    
    if (v.size() == 0)
        cout << "UNRESTORABLE" << endl;
    else    
        cout << v[0] << endl;
    
    return 0;
 }


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

namespace ConsoleApplication1
{
    class Program
    {
        static int[] preNum, parent, lowest;
        static bool[] visited;
        static int timer;

        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int V = int.Parse(input[0]);
            int E = int.Parse(input[1]);

            Dictionary<int, List<int>> G = new Dictionary<int, List<int>>();
            for (int i = 0; i < V; i++) G.Add(i, new List<int>());

            for (int i = 0; i < E; i++)
            {
                input = Console.ReadLine().Split(' ');
                int s = int.Parse(input[0]);
                int t = int.Parse(input[1]);

                G[s].Add(t);
                G[t].Add(s);
            }

            PrintBridges(G, V);
        }

        static void PrintBridges(Dictionary<int, List<int>> G, int V)
        {
            preNum = new int[V];
            parent = new int[V];
            lowest = new int[V];
            visited = new bool[V];
            timer = 1;

            DFS(G, 0, -1);

            List<KeyValuePair<int, int>> ans = new List<KeyValuePair<int, int>>();
            for (int i = 1; i < V; i++)
            {
                int p = parent[i];

                if (preNum[p] < lowest[i])
                {
                    int s = Math.Min(p, i);
                    int t = Math.Max(p, i);
                    ans.Add(new KeyValuePair<int, int>(s, t));
                }
            }
            var query = ans.OrderBy(a => a.Key).ThenBy(a => a.Value);

            StringBuilder sb = new StringBuilder();
            foreach (var q in query)
            {
                sb.AppendLine(q.Key + " " + q.Value);
            }
            Console.Write(sb);
        }

        static void DFS(Dictionary<int, List<int>> G, int cur, int prev)
        {
            preNum[cur] = lowest[cur] = timer;
            timer++;

            visited[cur] = true;

            for (int i = 0; i < G[cur].Count; i++)
            {
                int next = G[cur][i];

                if (!visited[next])
                {
                    parent[next] = cur;

                    DFS(G, next, cur);

                    lowest[cur] = Math.Min(lowest[cur], lowest[next]);
                }
                else if (next != prev)
                {
                    lowest[cur] = Math.Min(lowest[cur], preNum[next]);
                }
            }
        }
    }
}

Measured memory_bytes: 13496
import sys
readline = sys.stdin.readline

N,M = map(int,readline().split())

# Mの約数Pのうち、M // P >= Nとなるものの最大値

ans = 0
for i in range(1,int(M ** 0.5) + 1):
  if M % i == 0:
    p = M // i
    if i >= N:
      if ans < p:
        ans = p
    if p >= N:
      if ans < i:
        ans = i

print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
//#include<ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;
 
 
#define ff                first
#define ss                second
#define int               long long
#define pb                push_back
#define mp                make_pair
#define pii               pair<int,int>
#define vi                vector<int>
#define mii               map<int,int>
#define pqb               priority_queue<int>
#define pqs               priority_queue<int,vi,greater<int> >
#define setbits(x)        __builtin_popcountll(x)
#define zrobits(x)        __builtin_ctzll(x)
#define mod               1000000007   //10^9 + 7
#define inf               1e18
#define ps(x,y)           fixed<<setprecision(y)<<x
#define mk(arr,n,type)    type*arr = new type[n]
#define w(x)              int x;cin>>x;while(x--)
#define ti(n)             int n;cin>>n
#define rep(i,n)          for(int i=0;i<(n);++i)
#define repA(i,a,n)       for(int i=a;i<=(n);++i)
#define repD(i,a,n)       for(int i=a;i>=(n);--i)
#define itr(type,it,x)    for(type it = x.begin();it!=x.end();it++)
#define endl              "\n"
mt19937                  rng(chrono::steady_clock::now().time_since_epoch().count());  // to shuffle an array randomly viz. shuffle(arr,arr+n,rng)
 
//typedef tree<int , null_type , less<int> , rb_tree_tag, tree_order_statistics_node_update> pbds;  //policy based data structure
 
 
void c_p_c() {
 
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
 
 
 
}
//PROBLEM - FROG 1 & FROG 2 - ATCODER DP CONTEST
 
int minCostFrog1(vector<int> h, int n)
{
 
	vector<int> dp(n + 1);
 
	dp[1] = 0;
 
	for (int i = 2; i <= n; ++i)
	{
		int op1 = abs(h[i] - h[i - 1]) + dp[i - 1];
		int op2 = (i == 2) ? inf : abs(h[i] - h[i - 2]) + dp[i - 2];
 
		dp[i] = min(op1, op2);
	}
 
	return dp[n];
}
 
 
 
int minCostFrog2(vector<int> h, int n, int k)
{
 
	vector<int> dp(n + 1);
	dp[1] = 0;
 
	for (int i = 2; i <= n; ++i)
	{
 
		dp[i] = inf;
		for (int j = i - 1; j >= (i - k) && j >= 1; --j)
		{
			dp[i] = min(dp[i], abs(h[i] - h[j]) + dp[j]);
		}
	}
 
	return dp[n];
}
 
int32_t main(int32_t argc, char const *argv[]) {
 
	c_p_c();
 
 
 
	int n; cin >> n;
	int k; cin >> k;
	vector<int> h(n + 1);
	for (int i = 1; i <= n; ++i)
	{
 
		cin >> h[i];
	}
 
	//cout << minCostFrog1(h, n) << endl;
	cout << minCostFrog2(h, n, k) << endl;
 
	return 0;
}

Measured memory_bytes: 2560
//arc082_c.cpp
//Thu Jun  7 19:36:10 2018

#include <iostream>
#include <string>
#include <queue>
#include <unordered_map>
#include <vector>
#include <algorithm>
using namespace std;
using ll=long long;

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

	int accum[100000] = {};

	for (int i=0;i<n;i++){
		int temp;
		cin >> temp;
		accum[temp]++;
		if (temp<99999){
			accum[temp+1]++;
		}
		if (temp>0){
			accum[temp-1]++;
		}
	}

	int ans = 0;

	for (int i=0;i<100000;i++){
		if (ans < accum[i]){
			ans = accum[i];
		}
	}

	cout << ans << endl;
}

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

using str = string;
using ss = stringstream;

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

    str n;
    cin>>n;

    int ans=n[0]-'0'-1;

    bool nine=true;

    for(int i=1;i<n.size();i++)
    {
        if(n[i]!='9')nine=false;
        ans+=9;
    }

    if(nine)ans++;

    cout<<ans<<"\n";

    return 0;
}


Measured memory_bytes: 3640
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)

N = int(input())
pair = N * (N - 1) // 2
ptoi = dict()

i = 0
for x in range(1, N):
    for y in range(x + 1, N + 1):
        ptoi[(x, y)] = i
        ptoi[(y, x)] = i
        i += 1

edge = [[] for _ in range(pair)]
indeg = [0] * pair
for i in range(1, N+1):
    inp = list(map(int, input().split()))
    for s, t in zip(inp[:-1], inp[1:]):
        edge[ptoi[(i, s)]].append(ptoi[(i, t)])
        indeg[ptoi[(i, t)]] += 1


now = [i for i, d in enumerate(indeg) if d == 0]
day = 0
while now:
    nxt = []
    while now:
        s = now.pop()
        for t in edge[s]:
            if indeg[t] <= 0:
                continue
            indeg[t] -= 1
            if indeg[t] == 0:
                nxt.append(t)
    day += 1
    now = nxt

if all(i <= 0 for i in indeg):
    print(day)
else:
    print(-1)

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

using namespace std;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int A, B, C, D, E, F;
  cin >> A >> B >> C >> D >> E >> F;
  double maxx = 0;
  int x = 0, y = 0;
  for(double a = 0; a * A * 100.0 <= F; a++){
    for(double b = 0; b * B * 100.0 <= F - A * a * 100.0; b++){
      for(double c = 0; c * C <= F - a * A * 100.0 -  b * B * 100.0; c++){
        for(double d = 0; d * D <= F - a * A * 100.0 - b * B * 100.0 - c * C; d++){
          double sugar = c * C + d * D;
          double water = a * A * 100.0 + b * B * 100.0;
          if(sugar / E > water / 100 || sugar + water > F) continue;
          double des = (100.0 * sugar) / (sugar + water);
          if(des > maxx && sugar + water != 0){
            maxx = des;
            x = (int)(sugar + water);
            y = (int)sugar;
          }
        }
      }
    }
  }
  if(maxx == 0) cout << 100 * A << " " << "0" << endl;
  else{
    cout << x << " " << y << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<queue>
#include<cmath>
#include<algorithm>
#include<map>
#define debug1 cout<<"?"<<endl;
#define debug2 cout<<"?"<<i<<endl;
#define PII pair<int,int>
#define PIB pair<int,bool>
typedef long long ll;
using namespace std;
const int maxn=2e5+9;
const double pi=acos(-1);
const int mod=1e9+7;
const int INF=1e9;
const double ep=1e-10;
int main()
{
	int n,x,y,i,j,k,a[maxn]={0};
	scanf("%d%d%d",&n,&x,&y);
	for(i=1;i<n;i++)
	{
		for(j=i+1;j<=n;j++)
		{
			k=min(j-i,abs(x-i)+1+abs(y-j));
			a[k]++;
		}
	}
	for(i=1;i<n;i++)printf("%d\n",a[i]);
}

Measured memory_bytes: 1024
#include <stdio.h>
int main()
{
	int d,r;
	double a,f,b;
	scanf("%lf %lf",&a,&b);
	d=a/b;
	r=a-(d*b);
	f=a/b;
	printf("%d %d %0.6lf\n",d,r,f);
	return 0;
}


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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vvint = vector<vint>;
using vvvint = vector<vvint>;
using vdouble = vector<double>;
using vvdouble = vector<vdouble>;
using vvvdouble = vector<vvdouble>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using uint = unsigned int;
using ull = unsigned long long;

template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;
constexpr int mod2 = 998244353;
template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return (a > b && (a = b, true)); }
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return (a < b && (a = b, true)); }

template<typename T>
vector<T> makeVector(size_t a, T b) { return (vector<T>(a, b)); }
template<typename... Ts>
auto makeVector(size_t a, Ts... ts) { 
	return (vector<decltype(makeVector(ts...))>(a, makeVector(ts...)));
}

template<typename T>
bool isin(T y, T x, T h, T w) { return (0 <= y && 0 <= x && y < h && x < w); }
template<typename T>
bool isin1(T y, T x, T h, T w) { return (0 < y && 0 < x && y <= h && x <= w); }


template<typename T>
ostream& operator <<(ostream &os, vector<T> &v) {
	os << v[0];
	for (int i = 1; i < v.size(); i++) os << " " << v[i];
	return (os);
}

template<typename T>
istream& operator >>(istream &is, vector<T> &v) {
	for (auto &u : v) is >> u;
	return (is);
}

template<typename T1, typename T2>
istream& operator >>(istream &is, pair<T1, T2> &p) {
	return (is >> p.first >> p.second);
}


void Main() {
	ll N, K; cin >> N >> K;
	ll n = floor(sqrt((double)N+1e-6));

	auto dp1 = makeVector(K, n+2, 0ll);
	auto dp2 = makeVector(K, n+2, 0ll);	
	
	iota(begin(dp1[0]), end(dp1[0]), 0);
	
	for (int i = n; i > 0; i--) {
		if (n*n == N && i == n) continue;
		dp2[0][i] = max(n, N/i) - max(n, N/(i+1));
		dp2[0][i] += dp2[0][i+1];
	}
	
	for (int i = 1; i < K; i++) {
		for (int j = 1; j <= n; j++) {
			dp1[i][j] = (dp1[i-1][n] + dp2[i-1][j]) % mod;
			(dp1[i][j] += dp1[i][j-1]) %= mod;
		}
		for (int j = n; j > 0; j--) {
			if (n*n == N && j == n) continue;
			dp2[i][j] = (dp1[i-1][j] * (max(n, N/j) - max(n, N/(j+1)))) % mod;
			(dp2[i][j] += dp2[i][j+1]) %= mod;
		}
	}

	cout << (dp1[K-1][n] + dp2[K-1][1]) % mod << endl;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout << fixed << setprecision(20);
	Main();
	return (0);
}


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

int main(){
	string S;
	cin >> S;
	int ans = 0;

	for (char c:S)
	{
		if (c == '+')
		{
			ans += 1;
		}else if(c == '-'){
			ans -= 1;
		}
	}	
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<cstdio>
#include<queue>
#include<deque>
#include<map>
#include<stack>
#include<set>
#include<tuple>
using namespace std;
typedef pair<int,int> ii;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef unsigned long long int ull;
const int INF=1e9;
const ll MOD=1e9+7;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
const int MAXN=2e5;

int n,q;
vector<vector<int> > G(MAXN);
vector<bool> visited(MAXN,false);
vector<int> cnt(MAXN,0);

void dfs(int u){
    visited[u]=true;
    for(auto v:G[u]){
        if(!visited[v]){
            cnt[v]+=cnt[u];
            dfs(v);
        }
    }
    return ;
}

int main(){
    cin>>n>>q;
    for(int i=0;i<n-1;i++){
        int a,b;cin>>a>>b;
        a--;b--;
        G[a].emplace_back(b);
        G[b].emplace_back(a);
    }
    for(int i=0;i<q;i++){
        int p,x;cin>>p>>x;
        p--;
        cnt[p]+=x;
    }
    dfs(0);
    for(int i=0;i<n;i++){
        cout<<cnt[i];
        if(i!=n-1) cout<<' ';
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 24276
n = int(input())
l = []
dp = [[0 for i in range(3)]for j in range(n)]
for i in range(n):
    l.append(list(map(int , input().split())))
dp[0][0] = l[0][0]
dp[0][1] = l[0][1]
dp[0][2] = l[0][2]
for i in range(n-1):
    dp[i+1][0] = l[i+1][0]+max(dp[i][1],dp[i][2])
    dp[i+1][1] = l[i+1][1]+max(dp[i][0],dp[i][2])
    dp[i+1][2] = l[i+1][2]+max(dp[i][1],dp[i][0])
print(max(dp[-1]))

Measured memory_bytes: 50196
import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		char[] w = sc.next().toCharArray();
		int[] cnt = new int[26];
		for (int i = 0; i < w.length; i++) {
			cnt[w[i] - 'a']++;
		}
		
		boolean isBeautiful = true;
		for (int num : cnt) {
			if (num % 2 != 0) {
				isBeautiful = false;
				break;
			}
		}
		
		String ans = isBeautiful ? "Yes" : "No";
		System.out.println(ans);
		
		sc.close();
	}
}



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

int main() {
	// your code goes here
	int x;
	
	for (int i = 1; ; i++){
		cin >> x;
		if (x == 0 ){
			break;
		}
		cout << "Case " << i << ": " << x << endl;
	}
	
	/*
	while(1){
		cin >> x;
		cnt += 1;
		
		if (x == 0){
			break;
		}
		cout << "Case " << cnt << ": " << x << endl;
	}
	*/
	return 0;
}

Measured memory_bytes: 2996
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;

int main() {
  int n,m;
  cin >> n >> m;
  cout << (n * (n - 1) / 2) + (m * (m - 1) / 2) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <bitset>
#include <cstdlib>
#include <cmath>
using namespace std;

typedef  bitset<10>  bits;
int len;
bits a = 0;
string str;

int ctoi(char c){
    //cout <<"c:" <<c << endl;
    if('0' <= c && c <= '9') return (c-'0');
    else return -1;
}

long long calc(bits b){
    long long res = 0,tmp = 0;
    //前から10-b文字は無視する。
    tmp = ctoi(str[0]);
    for(int i = 10 - len + 1,j = 1; i < 10; i++, j++){
     //   cout << i << " |: " << ctoi(str[j]) << " || bit: " << b[j-1] << " | ";
        if(b[j-1]==true){//+がない
            tmp = tmp * 10 + ctoi(str[j]);
        }else{//+がある
            res += tmp;
            tmp = ctoi(str[j]);
        }
    }
    res += tmp;
 //   cout << "bit:" << b << "  |res:" << res << endl;
    return res;
}


int main(){
    cin >> str;
    len = str.length();
   // cout << "length:" << len << endl;
    int num = atoi(str.c_str());
    long long ans = 0;

    for(int i = pow(2,len-1)-1; i >= 0; i--){
        a = i;
      //  cout << a << " | " << i << endl;
        ans += calc(a);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
char a[2006][2006];
int main()
{
	int n,m,ans;
	cin>>n>>m;
	for(int i=0;i<n;i++){
		for(int q=0;q<m;q++)
		cin>>a[i][q];
    }
    for(int i=0;i<n;i++){
    	for(int q=0;q<m;q++){
    		ans=0;
    		if(a[i][q]=='#'){
			cout<<"#";continue;}
    		if(a[i-1][q-1]=='#') ans++;
    		if(a[i-1][q]=='#') ans++;
    		if(a[i-1][q+1]=='#') ans++;
    		if(a[i][q-1]=='#') ans++;
    		if(a[i][q+1]=='#') ans++;
    		if(a[i+1][q-1]=='#') ans++;
    		if(a[i+1][q]=='#') ans++;
    		if(a[i+1][q+1]=='#') ans++;
    		cout<<ans;
    		
		} cout<<endl;
	}
	return 0;
	
}
 
 

Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define PB push_back
#define MP make_pair
#define MOD 1000000007LL
#define endl "\n"
const ll UNDEF = -1;
const ll INF=1e18;
template<typename T> inline bool chkmax(T &aa, T bb) { return aa < bb ? aa = bb, true : false; }
template<typename T> inline bool chkmin(T &aa, T bb) { return aa > bb ? aa = bb, true : false; }
const ll mn=304;
string c[mn];
char a[mn];
char b[mn];
ll f[2*mn][2*mn];
ll g[mn][mn];
ll xlim;
ll solve() {
	memset(g,0,sizeof g);
	for (ll sum=0;sum<=2*xlim;sum++) for (ll bs=0;bs<=xlim;bs++) {
		ll as=sum-bs;
		if (0<=as&&as<=xlim) {
			ll prev=0;
			if (as-1>=0&&bs-1>=0) prev=g[as-1][bs-1];
			ll add=0;
			if (as-1>=0&&bs-1>=0) {
				add=(a[as-1]==b[bs-1])?1:0;
				//printf("%c %c chars ",a[as-1],b[bs-1]);
			}
			g[as][bs]=prev+add;
			//printf("as:%lld bs:%lld g:%lld add:%lld\n",as,bs,g[as][bs],add);
		}
	}
	for (ll x=0;x<=2*xlim;x++)for (ll y=0;y<=2*xlim;y++) f[x][y]=INF;
	f[xlim][xlim]=0;
	for (ll sum=xlim*2-1;sum>=0;sum--) for (ll bs=0;bs<=xlim;bs++) {
		ll as=sum-bs;
		if (0<=as&&as<=xlim) {
			f[as][bs]=min(
				f[as][bs+1]+g[as][bs+1],
				f[as+1][bs]+g[as+1][bs]
				);
			//printf("as:%lld bs:%lld f:%lld\n",as,bs,f[as][bs]);
		}
	}
	return f[0][0];
}
int main() {
	ios_base::sync_with_stdio(false);
	ll ylim;
	cin>>xlim>>ylim;
	for (ll x=0;x<xlim;x++) cin>>c[x];
	ll ans=0;
	for (ll y=0;y<ylim-1;y++) {
		for (ll x=0;x<xlim;x++) a[x]=c[x][y];
		for (ll x=0;x<xlim;x++) b[x]=c[x][y+1];
		ans+=solve();
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 4096
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
//const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

class Graph{
	private:
	int n;
	vvp g;
	public:
	vi DIJ(int s){
		priority_queue<P> q;
		vi d(n,inf);
		d[s]=0;
		q.push({0,s});
		while(!q.empty()){
			P p=q.top();
			q.pop();
			int v=p.second;
			if(d[v]<-p.first) continue;
			for(auto i:g[v]){
				int u=i.first,D=d[v]+i.second;
				if(d[u]>D){
					d[u]=D;
					q.push({-D,u});
				}
			}
		}
		return d;
	}
	Graph(int v){
		n=v;
		g=vvp(v);
	}
	void add_edge(int s,int t,int c){
		g[s].push_back({t,c});
	}
};

int h,w;

int f(int x,int y,int k){
	return k*h*w+x*w+y;
}

int main(){
	while(1){
		cin>>w>>h;
		if(h==0) break;
		vvi a(h,vi(w));
		vi b(4);
		for(int i=0;i<h;i++) for(int j=0;j<w;j++) cin>>a[i][j];
		for(int i=0;i<4;i++) cin>>b[i];
		Graph g(h*w*4);
		for(int i=0;i<h;i++) for(int j=0;j<w;j++){
			if(a[i][j]<4){
			for(int k=0;k<4;k++){
				int K=(k+a[i][j])%4;
				int x=i+dx[K],y=j+dy[K];
				if(x>=0&&x<h&&y>=0&&y<w){
					g.add_edge(f(i,j,k),f(x,y,K),0);
				}
			}
			}
			for(int k=0;k<4;k++) for(int l=0;l<4;l++){
				int K=(k+l)%4;
				int x=i+dx[K],y=j+dy[K];
				if(x>=0&&x<h&&y>=0&&y<w){
					g.add_edge(f(i,j,k),f(x,y,K),b[l]);
				}
			}
		}
		int res=inf;
		vi d=g.DIJ(f(0,0,0));
		for(int i=0;i<4;i++) res=min(res,d[f(h-1,w-1,i)]);
		cout<<res<<endl;
	}
}


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

int main(){
  
  ll N;
  cin >> N;
  map<ll,ll> mp;
  ll tmp;
  for(int i = 1;i < N; i++)  cin >> tmp,++mp[tmp - 1]; 
  
  for(int i = 0;i < N;i++)  cout << mp[i] << endl;
  
  return 0;
}

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

#define ll long long
#define tc(t) int t;cin >> t; while(t--)
#define pb push_back
#define fi first
#define se second
#define debug1(x) cerr << #x << " = " << x << '\n';
#define debug2(x, y) cerr << #x << " = " << x << "   " << #y << " = " << y << "\n";
#define _ ios_base::sync_with_stdio(0);cin.tie(NULL);


void solve() {
    ll x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;
    ll p[a] = {}, q[b] = {}, r[c] = {};
    for(int i = 0; i<a; i++) {
        cin >> p[i];
    }
    for(int i = 0; i<b; i++) {
        cin >> q[i];
    }
    for(int i = 0; i<c; i++) {
        cin >> r[i];
    }
    sort(p, p+a, greater<ll>());
    sort(q, q+b, greater<ll>());
    sort(r, r+c, greater<ll>());
    vector<ll> v;
    for(int i = 0; i<min(x, a); i++) {
        v.push_back(p[i]);
    }
    for(int i = 0; i<min(y, b); i++) {
        v.push_back(q[i]);
    }
    for(int i = 0; i<c; i++) {
        v.push_back(r[i]);
    }
    sort(v.rbegin(), v.rend());
    ll sum = 0;
    for(int i = 0; i<x+y; i++) {
        sum += v[i];
    }
    cout << sum << '\n';
}

int main() {_
    int t = 1;
    //cin >> t;
    // Please remember to uncomment for taking test cases
    for(int i = 1; i<=t; i++) {
        solve();
    }
    return 0;
}


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

int main()
{
    string s;
    cin >> s;
    int minA, maxZ;
    int l = s.length();
    int i = 0;
    while (i < l && s[i] != 'A')
    {
        i++;
    }
    int j = l - 1;
    while (j > 0 && s[j] != 'Z')
    {
        j--;
    }
    cout << j - i + 1;
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
using namespace std;
int main(void){
    int n;
    cin>>n;
    int s=0;
    while(true){
        if(n<25)    break;
        else{
            n=n-25;
            s=s+1;
        }
    }
    while(true){
        if(n<10)    break;
        else{
            n=n-10;
            s=s+1;
        }
    }
    while(true){
        if(n<5)    break;
        else{
            n=n-5;
            s=s+1;
        }  
    }
    s=s+n;
    cout<<s;
    cout<<endl;
}
    



Measured memory_bytes: 3104
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<ll> VLL;
typedef vector<string> VS;
typedef vector<PLL> VP;
#define rep(i,n) for (ll i=0; i<(ll)(n); i++)
#define repd(i,n) for (ll i=n-1; i>=0; i--)
#define rept(i,m,n) for(ll i=m; i<n; i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define PF push_front
#define PB push_back
#define SORT(V) sort((V).begin(), (V).end())
#define RVERSE(V) reverse((V).begin(), (V).end())
#define paired make_pair
#define PRINT(V) for(auto v : (V)) cout << v << " "
 
int main()
{
    ll N; cin >> N;
    VLL a(N);
    ll four=0;
    ll two=0;
    rep(i,N){
        cin >> a.at(i);
        if(a.at(i)%4==0){
            four++;
        }
        if(a.at(i)%4!=0 && a.at(i)%2==0){
            two++;
        }
    }
    ll judge=N-four*2;
    if(judge<=1){
        cout << "Yes" << endl;
        return 0;
    }
    else{
        if(judge<=two){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const long long LINF = 1e18;
const long long MOD = 1e9 + 7;

template <typename T>
vector<T> Dijkstra(int s, vector<vector<pair<int, T>>> & G, /*vector<int> & prev,*/ const T INF = 1e9){
    using P = pair<T, int>;
    int V = G.size();
    vector<T> dist(V, INF);
    priority_queue<P, vector<P>, greater<P>> que;
    dist[s] = 0;
    que.emplace(0, s);
    /*prev.assign(V, -1);*/
    while(!que.empty()){
        P p = que.top();
        que.pop();
        int v = p.second;
        if(dist[v] < p.first) continue;
        for(int i = 0; i < G[v].size(); i++){
            int to = G[v][i].first;
            T cost = G[v][i].second;
            if(dist[to] > dist[v] + cost){
                dist[to] = dist[v] + cost;
                /*prev[to] = v;*/
                que.emplace(dist[to], to);
            }
        }
    }
    return dist;
}

signed main(){
    double xs,ys,xt,yt;
    cin >> xs >> ys >> xt >> yt;
    int n;
    cin >> n;
    double x[n + 2], y[n + 2], r[n + 2];
    x[0] = xs;
    y[0] = ys;
    r[0] = 0;
    x[n + 1] = xt;
    y[n + 1] = yt;
    r[n + 1] = 0;
    for(int i = 1; i <= n; i++){
        cin >> x[i] >> y[i] >> r[i];
    }
    vector<vector<pair<int, double>>> G(n + 2);
    for(int i = 0; i < n + 2; i++){
        for(int j = i + 1; j < n + 2; j++){
            double d = sqrt((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j])) - (r[i] + r[j]);
            if(d < 0) d = 0.0;
            G[i].emplace_back(j, d);
            G[j].emplace_back(i, d);
        }
    }
    vector<double> dist = Dijkstra<double>(0, G, LINF);
    printf("%.12lf\n", dist[n + 1]); 
    return 0;
}

Measured memory_bytes: 22256
#include <iostream>
#include <vector>
#include <stdio.h>
#include <algorithm>
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> l(n);
    for (int i = 0; i < n; i++) cin >> l[i];

    sort(l.begin(), l.end(), greater<int>());
    int ans = 0;
    for (int i = 1; i < n; i++) ans += l[i];
    if (l[0] < ans) printf("Yes\n");
    else printf("No\n");
}

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

// 配列出力
template <typename T1, typename T2>
void arrayOutPut(vector<T1> A, T2 N){
	for(T2 i=0; i<N; i++){
		if(i>0) cout << " ";
		cout << A.at(i);
	}
}

// 選択ソート
int selectionSort(vector<int> &A,int &N){
	int minj;
	int buf;
	int count=0;
	for(int i=0; i<N-1; i++){
		minj = i;
		for(int j=i; j<N; j++){
			if(A.at(j) < A.at(minj)) minj=j;
		}
		buf = A.at(i);
		A.at(i) = A.at(minj);
		A.at(minj) = buf;
		if(minj != i) count++;
	}
	return count;
}


int main(){
	int N;
	cin >> N;
	vector<int> A(N);
	for(int i=0; i<N; i++) cin >> A.at(i);
	int count;
	count = selectionSort(A, N);
	arrayOutPut(A, N);
	cout << endl;
	cout << count << endl;

}



Measured memory_bytes: 3132
package main

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

func main () {
  JPY := "JPY"
  sc := bufio.NewScanner(os.Stdin)
  sc.Split(bufio.ScanWords)

  sc.Scan()
  n, _ := strconv.Atoi(sc.Text())

  var sum float64
  for i := 0; i < n; i++ {
    sc.Scan()
    x, _ := strconv.ParseFloat(sc.Text(), 64)

    sc.Scan()
    u := sc.Text()

    if u == JPY {
      sum += x
    } else {
      sum += x * 380000
    }
  }

  fmt.Println(sum)
}


Measured memory_bytes: 640