akhauriyash/Code-Regression huggingface dataset:
# -*- coding: utf-8 -*-
N = int(input())

add = lambda c: ord(c) - ord("A") + N
cov = lambda c: chr(c+65)

S = list(input())
ans = ""
d = []
for i in range(len(S)):
    a = add(S[i])
    a = a % 26
    a = cov(a)
    ans += a
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
main(){
  int A,B,C,X;
  cin >> A >> B >> C >> X;
  int sum=0;
  int cnt=0;
  for(int i=0;i<=A;i++){
    for(int j=0;j<=B;j++){
      for(int k=0;k<=C;k++){
        sum=0;
        sum = 500*i + 100*j + 50*k;
        if(sum==X){
          cnt++;
        }
      }
    }
  }
  cout << cnt << endl;
}

Measured memory_bytes: 3560
#include<iostream>
#include<cmath>
#include<algorithm>

using namespace std;
#define ll long long 
const int maxn = 1e9;
int main(){
    int tam,k;
    cin>>tam>>k;
    int dp[110000];
    int arr[110000];
    for(int y = 0; y <= tam;y++)
        dp[y] = maxn;
    for(int y = 0; y < tam;y++)
        cin>>arr[y];
    dp[0] = 0;
    for(int y = 0; y < tam; y++){
        for(int z = 1; z <= k; z++){
            if( y + z < tam){
                dp[y + z ] = min(dp[y + z], dp[y] + abs(arr[y] - arr[y + z]));
            }
        }
    }
    cout<<dp[tam - 1];
    return 0;
}


Measured memory_bytes: 4396
n = gets.chomp.to_i
arr = gets.chomp.split(' ')

if !arr.include?('0')  
  result = 1
  arr.each do |num|
    result = result * num.to_i
    if result == 0
      result = 0
      break
    elsif result > 10**18
      result = -1
      break
    end
  end
else
  result = 0
end

puts result

Measured memory_bytes: 22700
import java.util.Scanner;

public class Main {
    
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        // 整数の入力
        int n = Integer.parseInt(sc.nextLine());
        
        String  str[] = new String[n];
        
        
        for(int i = 0; i < n ; i++){
             str[i] = sc.next();
        }

        //for(int i = 0; i < n ; i++){
        //    System.out.println(str[i]);
       //}
        
        int cnt_AC = 0;
        int cnt_WA = 0;
        int cnt_TLE = 0;
        int cnt_RE = 0;

        
        for(int i = 0; i < n ; i++){
            if( str[i] .equals( "AC")){
                //System.out.println("AC ");
                 cnt_AC ++;
            }else if( str[i] .equals("WA")){
                cnt_WA ++;
                
            }else if( str[i].equals( "TLE")){
                cnt_TLE++;
            }else if( str[i].equals("RE")){
                cnt_RE++;
            }
       }
        System.out.println("AC x "+cnt_AC);  
        //System.out.println(cnt_AC);  
        System.out.println("WA x "+cnt_WA);  
        System.out.println("TLE x "+cnt_TLE);  
        System.out.println("RE x "+cnt_RE);  
}

}

Measured memory_bytes: 63768
import heapq
N,M=map(int, input().split())
A=list(map(int, input().split()))
for i in range(N):
    A[i]=-1*A[i]
heapq.heapify(A)
for i in range(M):
    heapq.heappush(A,heapq.heappop(A)/2)
for i in range(N):
    A[i]=-1*int(A[i])
print(sum(A))

Measured memory_bytes: 93080
package main

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

func main() {
	sc.Split(bufio.ScanWords)
	a := nextInt()
	b := nextInt()
	c := nextInt()
	if 0 <= a && a < b && b < c && c <= 100 {
		fmt.Println("Yes")

	} else {
		fmt.Println("No")
	}
}

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}



Measured memory_bytes: 1112
#include <bits/stdc++.h>
using namespace std;
int main()
{
   int n,d,x; cin>>n>>d>>x;
   int c=0;  
   for(int i=0;i<n;i++) { int a; cin>>a; c+=ceil(double(d)/a); } 
   cout<<c+x; 
   return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  int x1,y1,x2,y2;
  int x3,y3,x4,y4;
  int dx,dy;
  
  scanf("%d %d %d %d",&x1,&y1,&x2,&y2);
  dx = x2 - x1;	dy = y2 - y1;
  
  x3 = x2 - dy;	y3 = y2 + dx;
  x4 = x1 - dy;	y4 = y1 + dx;
  
  printf("%d %d %d %d\n",x3,y3,x4,y4);
  return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <iostream>
#include <cassert>
#include <string>
#include <algorithm>
#include <cstring>
#include <utility>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <deque>
#include <unordered_map>
using namespace std;
typedef long long LL;
typedef long double LD;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
const int MAXN = 234567;
char s[MAXN];
int a[MAXN], psum[MAXN];

int main() {
    int N;
    scanf("%d", &N);
    scanf("%s", s + 1);
    for (int i = 1; i <= N; i++) {
        if (s[i] == '#') a[i] = 1;
        psum[i] = psum[i - 1] + a[i];
    }
    //int ans = min(N - psum[N], psum[N]);
    int ans = N;
    for (int i = 1; i <= N; i++) {
        int rsum = N - i, lsum = i - 1;
        int rb = psum[N] - psum[i], lb = psum[i - 1];
        //cur = B
        int cnt1 = (!a[i]) + rsum - rb + min(lsum - lb, lb);
        //cur = W
        int cnt2 = (a[i]) + lb + min(rb, rsum - rb);
        //printf("i = %d cnt = %d cnt2 = %d\n", i, cnt1, cnt2);
        ans = min({ans, cnt1, cnt2});
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 2048
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _0013
{
    class Program
    {
        static void Main(string[] args)
        {

            string str = "";
            List<int> train = new List<int>();

            while ((str = Console.ReadLine()) != null)
            {
                int frequent = int.Parse(str);
                if (frequent != 0)
                {
                    train.Add(frequent);
                }
                else
                {
                    Console.WriteLine(train[train.Count() - 1]);
                    train.RemoveAt(train.Count() - 1);
                }
            }
        }
    }
}



Measured memory_bytes: 14188
using System;
using System.Collections.Generic;

public class Hello
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine());
        var d = new (int, int)[n];
        
        for (var a = 0; a < n; ++a)
        {
            var line = Console.ReadLine().Split();
            
            d[a] = (int.Parse(line[0]), int.Parse(line[1]));
        }
        
        var count = 0;
        
        for (var i = 0; i < n; ++i)
        {
            var (a, b) = d[i];
            
            if (a == b)
            {
                ++count;
            }
            
            if (count == 3)
            {
                Console.WriteLine("Yes");

                return;
            }
          
          	if (a != b)
            {
                count = 0;
            }
        }
        
        Console.WriteLine("No");
    }
}


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

namespace CSharp_AtCoder
{


    class Program
    {



        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());

            string minus_binary = "";
            while (N != 0)
            {
                minus_binary = Math.Abs((N % -2)).ToString() + minus_binary;
                if (N % 2 == 0 || N > 0) N /= -2;
                else if (N < 0) N = N / -2 + 1;
            }

            if (minus_binary == "") minus_binary = "0";

            Console.WriteLine(minus_binary);
        }
    }
}


Measured memory_bytes: 11220
from collections import Counter, defaultdict
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline
from math import factorial
import bisect
import math



def main():
    n, k = map(int, input().split())
    ans = k * pow(k - 1, n - 1)
    print(ans)





if __name__ == '__main__':
    main()

Measured memory_bytes: 38512
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
	string S;
	int N;
	int x = 0;
	int Max = 0;
	cin >> N >> S;
	for (int i = 0; i < N; i++) {
		if (S[i] == 'I') {
			x++;
		}
		else {
			x--;
		}
		Max = max(x, Max);
	}
	cout << Max << endl;
	return 0;
}

Measured memory_bytes: 3580
/*
   AUTHOR :- Gaurang_Kothiya
   
   Quote:-" Great things never come from comfort zones."                                                                                                                
*/
 
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>  
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional>
#include <bitset>
#include <cstdint>
#include <initializer_list>
 
using namespace std;
using namespace __gnu_pbds;  

typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> data_set; 
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long  
#define ld long double
#define f(i,x,n) for(ll i=x;i<=n;i++)
#define fe(x,v)   for(auto &x :v)
#define nf(i,x,n) for(ll i=n;i>=x;i--)
#define all(a)   a.begin(),a.end()
#define rall(a)  a.rbegin(),a.rend()
#define b_s(a,b)   binary_search( all(a),b)
#define lb(v,n)  lower_bound(all(v) ,n )
#define ub(v,n)  upper_bound( all(v) , n)
#define gcd(a,b) __gcd(a,b)
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define RE rend()
#define RB rbegin()
#define B begin()
#define E end()
#define acc(v, x) accumulate(all(v), x)
#define p(a,b) pair<a,b>
#define F first
#define S second
#define sz size()
#define v(x) vector<x>
#define m(a,b) map<a,b>
#define u_m(a,b) unordered_map<a,b>
#define mm(a,b) multimap<a,b>
#define s(a) set<a>
#define us(a) unordered_set<a>
#define ms(a) multiset<a>
#define maxy __LONG_LONG_MAX__
#define miny INT_MIN
#define PI 3.14159265358979323846
#define MOD 1000000007




void Solve()
{
 	ll x;
 	cin>>x;
 	
 	f(i,-1000,1000)
 	{
 		f(j,-1000,1000)
 		{
 			if( i*i*i*i*i - j*j*j*j*j ==x  )
 			{
 				cout<<i<<" "<<j;
 				return;
			 }
		 }
	 }
 	
}

signed main() 
{
	speed		
	
	int q=1;
	//cin>>q;
	
	while(q--)
	Solve();
	
	//cout << "\n\n"<<"Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " seconds.\n";
	return 0;
}

 
 

Measured memory_bytes: 3648
n = int(input())
a = list(input())
b = list(input())
c = list(input())

count = []
for i in range(n):
    if (int(a[i] == b[i]) + int(b[i] == c[i]) + int(c[i] == a[i])) == 3:
        count.append(0)
    elif (int(a[i] == b[i]) + int(b[i] == c[i]) + int(c[i] == a[i])) == 1:
        count.append(1)
    else:
        count.append(2)
print(int(sum(count)))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(a,n) for (ll a = 0; a < (n); ++a)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<vector<ll> > Graph;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1e18;


int main(){
    ll n,h,w;
    cin >> n >> h >> w;
    cout << (n-h+1)*(n-w+1) << endl;
    return 0;
}


Measured memory_bytes: 3624
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0;i < (int)(n);i++)
using ll = long long;
const ll MOD=1000000007;
const long long INF = 1LL << 60;
const double pi=acos(-1.0);

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; }

vector<ll> a;
ll N,K;

//dp
vector<bool> table;
vector<bool> checked;

bool dp(ll k){
  if(k<a.at(0)) return false;
  if(checked.at(k)) return table.at(k);
  
  checked.at(k)=true;
  rep(i,N){
    if(k-a.at(i)>=0&&!dp(k-a.at(i))) table.at(k)=true;
  }
  
  return table.at(k);
}

int main()
{
  cin>>N>>K;
  a=vector<ll>(N); rep(i,N) cin>>a.at(i);
  sort(a.begin(),a.end());
  
  //dp
  table=vector<bool>(K+1,false);
  checked=vector<bool>(K+1,false);
  
  if(dp(K)) cout<<"First"<<endl;
  else cout<<"Second"<<endl;
  return 0;
}

Measured memory_bytes: 8352
N = int(input())
A = list(map(int,(input().split())))
B = [0]*N
c = 0
for i in range(N):
    if A[i] < 0:
        c += 1
for i in range(N):
    B[i] = abs(A[i])

if c % 2 == 0:
    print(sum(B))
else:
    print(sum(B)-2*min(B))

Measured memory_bytes: 64752
import numpy as np

# input
N, M = map(int, input().split())
A = [list(input()) for _ in range(N)]
B = [list(input()) for _ in range(M)]

A_arr = np.array(A)
B_arr = np.array(B)

for i in range(N - M + 1):
    for j in range(N - M + 1):
        if np.array_equal(A_arr[i:i + M, j:j + M], B_arr):
            print('Yes')
            exit()

print('No')        


Measured memory_bytes: 12436
n = int(input())
A = tuple(map(int, input().split()))
ans = 0
from itertools import product
for P in product([-1, 0, 1], repeat=n):
    B = 1
    for a, p in zip(A, P):
        B *= (a+p)
        if B%2 == 0:
            ans += 1
            break
print(ans)


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

int main() {
  string s;
  cin>>s;
  int ans=9999;
  for(int i=0;i<s.size()-2;i++){
    int tmp=atoi(s.substr(i,3).c_str());
    //cout<<tmp<<endl;
    tmp = abs(tmp-753);
    ans =min(tmp,ans);
  }
cout<<ans<<endl;
}


Measured memory_bytes: 256
/* ****TCIITB**** */

#include<bits/stdc++.h>
#define io          ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); 
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
using namespace std;

#define N  100005

int main()
{
	
	io

	ll n;
	cin>>n;
	std::map<ll,ll> freq;
	std::vector<ll> a(n);
	rep(i,0,n)
	{
		cin>>a[i];
		freq[a[i]]++;
	}
	ll res=0;
	for(auto i:freq)
	{
		res+=(i.S*(i.S-1))/2;
	}
	rep(i,0,n)
	{
		cout<<res-freq[a[i]]+1<<endl;
	}
	
}

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

map<long long, long long> dp;
long long N, A, B, C, D;

vector<long long> v = {2,3,5}, c;

long long solve(long long N) {
    if (dp.count(N))    return dp[N];

    long long ans = 1e18;
    if (N <= ans/D)     ans = min(ans, N*D);

    for (int i=0; i<3; i++) {
        long long p = v[i];
        long long C = c[i];
        long long r = N%p;
        ans = min(ans, r*D+solve(N/p)+C);
        if (r > 0)  ans = min(ans, (p-r)*D+solve(N/p+1)+C);
    }

    return dp[N] = ans;
}

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

    int t;
    cin>>t;

    while (t--) {
        cin>>N>>A>>B>>C>>D;

        c = {A, B, C};

        dp.clear();
        dp[0] = 0;
        dp[1] = D;

        cout<<solve(N)<<endl;
    }
}


Measured memory_bytes: 4444
#include<iostream>
using namespace std;
int main(){
	int h,w;
	cin>>h>>w;
	char a[h][w];
	for(int i=0; i<h; i++){
		for(int k=0; k<w; k++){
			cin >> a[i][k];
		}
	}

	for(int i=0; i<w; i++){
		if(i==0)cout<<"#";
		cout<<"#";
		if(i==w-1)cout<<"#"<<endl;
	}
	for(int i=0; i<h; i++){
		cout<<"#";
		for(int k=0; k<w; k++){
			cout<<a[i][k];
		}
		cout<<"#"<<endl;
	}
	for(int i=0; i<w; i++){
		if(i==0)cout<<"#";
		cout<<"#";
		if(i==w-1)cout<<"#"<<endl;
	}
}





Measured memory_bytes: 256
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
//const int INF = 1e8;
using namespace std;

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

    long long a[300005];
    rep(i,n * 3){
        cin >> a[i];
    }
    priority_queue<long long, vector<long long>, greater<long long>> s;
    priority_queue<long long> t;
    long long s_sum = 0, t_sum = 0;
    rep(i,n){
        s.push(a[i]);
        s_sum += a[i];
    }

    for(int i = n * 3 - 1; i >= n + n; i--){
        t.push(a[i]);
        t_sum += a[i];
    }


    long long s_max[100005], t_min[100005];
    s_max[0] = s_sum;
    range(i,n,n + n){
        s_sum += a[i];
        s.push(a[i]);
        s_sum -= s.top();
        s.pop();
        s_max[i - n + 1] = s_sum;
    }

    t_min[0] = t_sum;
    for(int i = n + n - 1; i >= n; i--){
        t_sum += a[i];
        t.push(a[i]);
        t_sum -= t.top();
        t.pop();
        t_min[n + n - i] = t_sum;
    }
    //rep(i,n + 1){ show(s_max[i]) }
    //rep(i,n + 1){ show(t_min[i]) }

    long long ans = -(1LL << 60);
    rep(i,n + 1){
        ans = max(ans, s_max[i] - t_min[n - i]);
    }

    cout << ans << endl;
}


Measured memory_bytes: 6388
/************************************************
*Author        :  xzj213
*Created Time  :  2019.11.07.08:33
*Mail          :  xzj213@qq.com
*Problem       :  pyramid
************************************************/
#include <bits/stdc++.h>
#define REP(i,a,b) for(register int i=(a);i<=(b);i++)
#define DREP(i,a,b) for(register int i=(a);i>=(b);i--)
#define mem(a,x) memset((a),(x),sizeof(a))
#define pii pair<int,int>
#define lson k<<1
#define rson k<<1|1
#define x first
#define y second
#define str(a) strlen(a)
#define max_(x,y) ((x)>(y)?(x):(y))
#define min_(x,y) ((x)<(y)?(x):(y))
#define lowbit(i) ((x)&-(x))
using namespace std;
const int maxn=1e6+5;
int n,a[maxn*2],b[maxn*2];
int read() {
    int x=0,f=1;
    char ch=getchar();
    while(ch>57 || ch<48){if(ch==45)f=-1;ch=getchar();}
    while(ch<=57 && ch>=48){x=x*10+ch-48;ch=getchar();}
    return x*f;
}
bool check(int Mid){
	REP(i,1,n*2-1)b[i]=(a[i]>Mid?1:0);
	REP(i,0,n-2){
		if(b[n-i]==b[n-i-1])
			return b[n-i];
		if(b[n+i]==b[n+i+1])
			return b[n+i];
	}
	return b[1];
}
int main() {
    n=read();
	REP(i,1,n*2-1)a[i]=read();
	int l=1,r=n*2-1;
	while(l<=r){
		int Mid=(l+r)>>1;
		if(check(Mid))l=Mid+1;
		else r=Mid-1;
	}
	cout<<r+1<<endl;
    return 0;
}


Measured memory_bytes: 5120
#include <bits/stdc++.h>
using namespace std;
const long long int INF = 1e18L+5;
int main()
{
  int n;
  cin>>n;
  int a[n];
  for(int i=0;i<n;i++) cin>>a[i];
  long long int dp[n][n], ps[n];
  ps[0]=a[0];
  for(int i=1;i<n;i++) ps[i]=ps[i-1]+a[i];
  for(int i=0;i<n;i++) dp[i][i]=0;
  for(int i=1;i<n;i++)
  {
    for(int j=0;j+i<n;j++)
    {
      dp[j][j+i]=INF;
      for(int k=j;k<j+i;k++)
      {
        dp[j][j+i]=min(dp[j][j+i],dp[j][k]+dp[k+1][j+i]+ps[j+i]-((j>0)?ps[j-1]:0));
      }
    }
  }
  cout<<dp[0][n-1];
}

Measured memory_bytes: 4828
#define _CRT_SECURE_NO_WARNINGS
//#define _USE_MATH_DEFINES
#include<stdio.h>
#include<stdlib.h>
//#include<math.h>
#include<string.h>
//#include<time.h>
#define P(type,x) fprintf(stdout,"%"#type"\n",x)
typedef struct {
	int p,
		left,
		right;
}NODE;
NODE *node, tmp;

int main() {
	int n,i,id,k,j,c,r;
	int depth,t;
	fscanf(stdin, "%d", &n);
	node =(NODE*) malloc(sizeof(NODE)*n);
	for (i = 0; i < n; i++)
		node[i].p = node[i].left = node[i].right = -1;
	
	for (i = 0; i < n; i++) {
		fscanf(stdin, "%d%d", &id, &k);
		for (j = 0; j < k; j++) {
			fscanf(stdin, "%d", &c);
			if (j == 0)node[id].left = c;
			else node[r].right = c;
			node[c].p = id;
			r = c;
		}
	}
	for (i = 0; i < n; i++) {
		depth = 0;
		t = node[i].p;
		while (t != -1) {
			t = node[t].p;
			depth++;
		}
		if (node[i].p == -1)
			fprintf(stdout, "node %d: parent = %d, depth = %d, root, [", i, node[i].p, depth);
		else if( node[i].left==-1)
			fprintf(stdout,"node %d: parent = %d, depth = %d, leaf, [",i, node[i].p, depth);
		else 
			fprintf(stdout,"node %d: parent = %d, depth = %d, internal node, [",i, node[i].p, depth);
		t = node[i].left;
		if (t != -1) fprintf(stdout, "%d", t);
		while (t != -1) {
			t = node[t].right;
			if (t != -1)printf(", %d", t);
		}
		P(s, "]");
	}
	free(node);
	return 0;
}

Measured memory_bytes: 1680
#include <stdio.h>

#define max(a, b) (a > b ? a : b)
#define min(a, b) (a < b ? a : b)

int main() {
  int n;
  scanf("%d", &n);
  int a[n];
  for (int i = 0; i < n; i++) {
    scanf("%d", a + i);
  }
  int ans = 1;
  for (int i = 1; i < n; i++) {
    int cur = 1;
    for (int j = 0; j < i; j++) {
      cur &= (a[j] <= a[i]);
    }
    ans += cur;
  }
  printf("%d\n", ans);
  return 0;
}

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

int main() {
	long long a,b,k;
	cin >> a >> b >> k;
	if(a < k)
	{
		
		k = k - a;
      a = 0;
		if(b < k)
		{
			b = 0;
		}
		else
		{
			b = b - k;
		}
	}
	else
	{
		a = a - k;
	}
	
	cout << a << ' ' << b <<endl;
	return 0;
}


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

using namespace std;

typedef long long int ll;



ll x, y, z;


int main(){

	while(scanf("%lld %lld %lld", &x, &y, &z)!=EOF){
		int ans = 0;
		if(x==y && y==z){
			printf("%d\n", (x%2)?0:-1);
			continue;			
		}

		while(1){
			if(x%2 || y%2 || z%2){
				break;
			}
			ll nx=(y+z)/2, ny=(x+z)/2, nz=(x+y)/2;
			x=nx; y=ny; z=nz;
			ans++;
		}
		printf("%d\n", ans);
	}

	return 0;

}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int N,M;
bool Graph[50][50];
bool went[50];
void dfs(int a){
  went[a]=true;
  for(int i=0;i<M;i++){
    if(!Graph[i][a])continue;
    if(went[i])continue;
    dfs(i);
  }
}
int main(){
  cin>>N>>M;
  vector<pair<int,int>>A(M);
  for(int i=0;i<M;i++){
    cin>>A[i].first>>A[i].second;
    A[i].first--;A[i].second--;
    Graph[A[i].first][A[i].second]=true;
    Graph[A[i].second][A[i].first]=true;
  }
  int ans=0;
  for(int i=0;i<M;i++){
    Graph[A[i].first][A[i].second]=false;
    Graph[A[i].second][A[i].first]=false;
    dfs(0);
    bool a=false;
    for(int j=0;j<N;j++)if(!went[j])a=true;
    if(a)ans++;
    for(int i=0;i<N;i++)went[i]=false;
    Graph[A[i].first][A[i].second]=true;
    Graph[A[i].second][A[i].first]=true;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3632
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 50;
constexpr double pi=3.14159265358979;
 
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;
}
using namespace std;

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


void solve(){
  ll n;
  cin>>n;
  vector<ll>v(n+5,1);
  for(ll i=1;i<=n;++i){
    map<int64_t,int>mp=prime_factor(i);
    for(auto x:mp){
      v[x.first]+=x.second;
    }
  }
  int m=0,k=0,a=0,b=0,c=0,d=0,e=0;
  for(auto x:v){
    if(x>=5)++m;
    else if(x>=3)++k;
    if(x>=25)++a;
    else if(x>=3)++b;
    if(x>=15)++c;
    else if(x>=5)++d;
    if(x>=75)++e;
  }
  int ans=((m*(m-1))/2)*k+(m*(m-1)*(m-2))/2;
  ans+=a*b+a*(a-1);
  ans+=c*d+c*(c-1);
  ans+=e;
  cout<<ans<<"\n";
  return;
}
 
signed main(){
	ios::sync_with_stdio(false);
  cin.tie(0);
  cout<<fixed<<setprecision(20);
	solve();
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main()
{
    long long n, m;
    cin >> n >> m;
    long long x = min(n, m), y = max(n, m);
    //long long ans = n * m;
    long long ans;
    if (x==1 && y == 1)
    {
        ans = 1LL;
    }
    else if (x == 1 && y!= 1)
    {
        ans = y-2;
    }
    else
    {
        ans = (x-2LL)*(y-2LL);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
A = [[0]*(N+1) for _ in range(N+1)]
for i in range(M):
    a, b = map(int, input().split())
    A[a][b] += 1
    A[b][a] += 1
for i in range(1, N+1):
    sum = 0
    for j in range(1, N+1):
        sum += A[i][j]
    print(sum)

Measured memory_bytes: 3064
N = int(input())
a_i = list(map(int, input().split()))

a_i.sort(reverse = True)

L_a = []
L_b = []

for i in range(0, N, 2):
    L_a.append(a_i[i])

for i in range(1, N, 2):
    L_b.append(a_i[i])

print(sum(L_a) - sum(L_b))


Measured memory_bytes: 3060
# -*- coding: utf-8 -*-
import sys
input = sys.stdin.readline

n = int(input())
a = list(map(int,input().split()))

#最小公倍数(least common multiple)
import fractions
from functools import reduce
def lcm_base(x, y):
    return (x  * y ) // fractions.gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

lcm_a = lcm(*a)
b = [lcm_a//i for i in a]
print(sum(b)%(10**9+7))

Measured memory_bytes: 264392
import numpy as np

N = int(input())

A = [0]*N
for i in range(N):
	A[i] = int(input())

A = np.array(A)
maxval = A.max()
maxindex = A.argmax()

A[maxindex] = -1
secval = A.max()

for i in range(N):
	if i == maxindex:
		print(secval)
	else:
		print(maxval)


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

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

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

  string s; cin >> s;
  bool flag = true;
  if(s[0] != 'A') flag = false;
  if(count(s.begin()+2, s.end()-1, 'C') != 1) flag = false;
  int cnt = 0;
  rep(i, s.size()) {
    if(s[i] < 'a') cnt++;
  }
  if(cnt > 2) flag = false;

  cout << (flag ? "AC" : "WA") << '\n';
  return 0;
}


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

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()
#define endl "\n"

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

void solve() {
    int A,B;
    cin >> A >> B;
    cout << A*B << endl;
}

int main() {
    solve();
    return 0;
}


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

int main(){
  ll l, k;
  cin >> l >> k;
  vector<vector<ll> > dp(2, vector<ll>(l + 1, 0));
  dp[0][0] = 1;
  //dp[next_is_white][height] = number
  for(int from = 0;from<l;from++){
    for(int black = 0;black<=1;black++){
      dp[1-black][from + 1] += dp[black][from];
      if(black == 0 && from + k <= l)
	dp[1-black][from + k] += dp[black][from];
    }
  }
  ll ans = 0;
  for(int i=1;i<=l;i++){
    ans += dp[1][i];
    //cout << "i:" << dp[1][i] << endl;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3164
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <cmath>
#include <numeric>
 
using namespace std;
 
int main()
{
    int n;
    int a[200010];
    int ball[200010] = {};
    int cnt, ans = 0;
 
    cin >> n;
 
    for (int i = 0; i < n; i++) {
        cin >> a[i+1];
    }
    
    for (int i = n; i >= 1; i--) {
        cnt = 0;
        for (int j = i; j <= n; j += i) {
            if (ball[j] == 1) cnt++;
        }
        if (cnt%2 != a[i]) {
            ball[i] = 1;
            ans++;
        }
    }
 
    cout << ans << endl;
 
    for (int i = 1; i <= n; i++) {
        if (ball[i] == 1) {
            cout << i << " ";
         }
    }
    if (ans != 0) {
        cout << endl;
    }
}

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

struct UnionFind{
  int num;//連結成分の数
  vector<int> r,p;//そのグループのサイズ,自分の親っぽいやつ
  UnionFind(){}
  UnionFind(int n):num(n),r(n,1),p(n,0){iota(p.begin(),p.end(),0);}

  int find(int x){//どのグループに所属するか
    return (x==p[x]?x:p[x]=find(p[x]));//xがグループの名前と一致するまでxを親にする
  }

  bool same(int x,int y){//同じグループかどうか
    return find(x)==find(y);
  }

  void unite(int x,int y){//xとyを同じグループにする
    x=find(x);y=find(y);//xとyのグループの名前をどっちかが変える
    if(x==y) return;
    if(r[x]<r[y]) swap(x,y);//サイズが大きい方をxとする
    r[x]+=r[y];//yの親をxにする（今までyだったグループ名がxになる）
    p[y]=x;
    num--;
  }

  int size(int x){//グループの大きさ
    return r[find(x)];
  }

  int count() const{//グループの数
    return num;
  }
};

template<typename T>
void chmax(T &a,T b){
  if(a<b)a=b;
}

signed main(){
  int n,m;cin>>n>>m;
  UnionFind uf(n);
  while(m--){
    int a,b;cin>>a>>b;a--;b--;
    uf.unite(a,b);
  }
  int ans=0;
  for(int i=0;i<n;i++)chmax(ans,uf.size(i));
  cout<<ans<<endl;
}


Measured memory_bytes: 4848
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#define llint long long
#define mod 1000000007

using namespace std;

llint sx, sy, tx, ty;
const int FACT_MAX = 3000005;
llint fact[FACT_MAX], fact_inv[FACT_MAX];

llint modpow(llint a, llint n)
{
	if(n == 0) return 1;
	if(n % 2){
		return ((a%mod) * (modpow(a, n-1)%mod)) % mod;
	}
	else{
		return modpow((a*a)%mod, n/2) % mod;
	}
}

void make_fact()
{
	llint val = 1;
	fact[0] = 1;
	for(int i = 1; i < FACT_MAX; i++){
		val *= i;
		val %= mod;
		fact[i] = val;
	}
	fact_inv[FACT_MAX-1] = modpow(fact[FACT_MAX-1], mod-2);
	for(int i = FACT_MAX-2; i >= 0; i--){
		fact_inv[i] = fact_inv[i+1] * (i+1) % mod;
	}
}

llint comb(llint n, llint k)
{
	llint ret = 1;
	ret *= fact[n];
	ret *= fact_inv[k], ret %= mod;
	ret *= fact_inv[n-k], ret %= mod;
	return ret;
}

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	make_fact();
	
	cin >> sx >> sy >> tx >> ty;
	
	llint ans = 0;
	for(int i = sx; i <= tx; i++){
		ans += comb(i+ty+1, ty), ans %= mod;
		ans += mod - comb(i+(sy-1)+1, sy-1), ans %= mod;
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 47104
#include <bits/stdc++.h>
using namespace std;
 
int main(){
   int L,R,d;
   cin>>L>>R>>d;
   int count = 0;
   for(int i=L;i<=R;i++){
       if(i%d ==0 ){
           count++;
       }
   }cout << count <<endl;
   
}


Measured memory_bytes: 3568
#include <bits/stdc++.h>
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ThxDem=b;i<ThxDem;++i)
#define pb push_back
#define ALL(s) s.begin(),s.end()
#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define SZ(s) int(s.size())
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;

int main(){FIN;
	int a,b,c,d; cin>>a>>b>>c>>d;
	int x=(c+b-1)/b;
	int y=(a+d-1)/d;
	if(x<=y)cout<<"Yes\n";
	else cout<<"No\n";
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define mp make_pair
#define ss second
#define ff first
#define ll long long int
#define tcase ll t;cin>>t;while(t--)
#define sz(a) int((a).size())
#define pb push_back
#define present(c,x) (�.find(x) != �.end())
#define cpresent(c,x) (find(all�,x) != �.end())
#define YES cout<<"YES\n";
#define NO cout<<"NO\n";
#define Yes cout<<"Yes\n";
#define No cout<<"No\n";
#define f(i,a) for(int i=0;i<a;i++)
#define in insert
const ll M=1e9+7;

using namespace std;

int main()
{

      int a,b;
      char c;
      cin>>a>>c>>b;
      if(c=='+')
        cout<<a+b;
      else
        cout<<a-b;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    string a, b, c;
    cin >> a >> b >> c;
    
    char A = a[0] - 0x20;
    char B = b[0] - 0x20;
    char C = c[0] - 0x20;

    cout << A << B << C << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr double eps = 1e-9;
constexpr ll MOD = 1000000007LL;
template <typename T> bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T> bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T> ostream &operator<<(ostream &os, vector<T> v) {
    for (int i = 0; i < v.size(); i++) {
        os << v[i] << (i + 1 == v.size() ? "\n" : " ");
    }
    return os;
}
template <typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) {
    t = v;
}
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) {
    for (auto &e : t) {
        fill_v(e, v);
    }
};
vector<vector<int>> G;
vector<ll> res;
void dfs(int i, int p) {
    for (auto &e : G[i]) {
        if (e == p) {
            continue;
        }
        res[e] += res[i];
        dfs(e, i);
    }
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    G.resize(n);
    res.resize(n);
    int q;
    cin >> q;
    for (int i = 0; i < n - 1; i++) {
        int a, b;
        cin >> a >> b;
        --a;
        --b;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    for (int i = 0; i < q; i++) {
        int p, x;
        cin >> p >> x;
        --p;
        res[p] += x;
    }
    dfs(0, -1);
    cout << res;
}


Measured memory_bytes: 25856
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>

using namespace std;

char map[2000][2000];

int a, b, x, y, n, m, nn, mm;
bool flg = false;

void output() {
	for(int i=0;i<nn;i++){
		for(int j=0;j<mm;j++){
			cout<<map[i][j];
		}
		cout<<endl;
	}
}

int main() {
	cin>>nn>>mm>>a>>b;
	n=nn;
	m=mm;
	for(int i=0;i<nn;i++){
		for(int j=0;j<mm;j++){
			map[i][j]='.';
		}
	}

	if(n%2==1){
		for(int i=m%2;i<m-1;i+=2){
			if(a>0) {
				map[0][i] = '<';
				map[0][i+1] = '>';
				a--;
			} else {
				break;
			}
		}
	}
	if(m%2==1){
		for(int i=n%2;i<n-1;i+=2){
			if(b>0){
				map[i][0] = '^';
				map[i+1][0] = 'v';
				b--;
			}else{
				break;
			}
		}
	}
	if(n>2&&m>2&&n%2==1&&m%2==1&&(a%2==1||b%2==1)&&a>0&&b>0){
		map[0][0]='<';
		map[0][1]='>';
		map[0][2]='^';
		map[1][2]='v';
		map[2][2]='>';
		map[2][1]='<';
		flg=true;
		a--;
		b--;
	}

	for(int i=n%2;i<n;i+=2){
		for(int j=m%2;j<m;j+=2){
			if(flg&&i==1&&j==1)continue;
			if(a>0){
				map[x+i][y+j] = '<';
				map[x+i][y+j+1] = '>';
				a--;
				if(a>0){
					map[x+i+1][y+j] = '<';
					map[x+i+1][y+j+1] = '>';
					a--;
				}
			} else if(b>0){
				map[x+i][y+j] = '^';
				map[x+i+1][y+j] = 'v';
				b--;
				if(b>0){
					map[x+i][y+j+1] = '^';
					map[x+i+1][y+j+1] = 'v';
					b--;
				}
			}
		}
	}

	if(a>0||b>0){
		cout<<"NO"<<endl;
		return 0;
	}

	cout<<"YES"<<endl;
	output();

	return 0;
}

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

public class Main {
	void run() {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int ans = gcd(a, b);
		System.out.println(ans);
		sc.close();
	}
	int gcd(int a, int b) {
		if(a < b) {
			int c = a;
			a = b;
			b = c;
		}
		if(b == 0) return a;
		else return gcd(b, a%b);
	}

	void debug(Object... o) {
		System.out.println(Arrays.deepToString(o));
	}

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


Measured memory_bytes: 26344
#include <iostream>
#include <string>
#include <algorithm>
#include <cassert>
#include <limits>
#include <numeric>
#include <type_traits>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <functional>
#include <utility>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <complex>
#include <climits>
#include <time.h>

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<string> vs;
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)

ll gcd(ll a, ll b) {
 	while (a && b) {
 		if (a >= b) a %= b;
 		else b %= a;
  	}
  	return a + b;
}
ll ketasum(ll n) { //桁の数字全ての和を返す 例: 112 -> 4
	ll sum=0;
	if (n<0) return 0;
	while (n>0) {
		sum += n%10;
		n /= 10;
	}
	return sum;
}

typedef pair<ll, ll> pair_t;

bool comp(const pair_t &a, const pair_t &b) {
        return a.first < b.first;
}

void sort2vectors(vector<ll> &av, vector<ll> &bv)
{ // ふたつの配列をまとめてそーと A[2,1] B[3,4] -> 1,4 2,3
        ll n = av.size();
        vector<pair_t> p(n);
        vector<ll> av2(n), bv2(n);
        for (ll i = 0; i < n; i++)
                p[i] = make_pair(av[i], bv[i]);
        sort(p.begin(), p.end(), comp);
        for (ll i = 0; i < n; i++) {
                av2[i] = p[i].first;
                bv2[i] = p[i].second;
        }
        av = av2;
        bv = bv2;
}
ll facctorialMethod(ll k){ //階乗
	ll s;
	if(k > 1){
		s = k*facctorialMethod(k-1);
	} else {
		s = 1;
	}
	return s;
}

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

// 変数定義start(vectorはresizeしようね)
ll A, B;
// 変数定義end

void solve(){
	cin >> A >> B;
	if(A >= 2*B){
		cout << A - 2 * B << endl;
	} else {
		cout << 0 << endl;
	}
}

int main(){

	//clock_t start = clock();

	cout << std::fixed << std::setprecision(10);
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	solve();
	//clock_t end = clock();

	//const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC * 1000.0;
	//printf("time %lf[ms]\n", time);
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <stdio.h>
using namespace std;
#define MAX 100000
#define WHITE 0
#define GRAY 1
#define BLACK 2

// 重み付き有向グラフの隣接リスト
vector<pair<int,int> > adj[MAX];

int dijkstra(vector<pair<int,int> >* adj,int n,int startIndex,int dest){
    priority_queue<pair<int,int> >pq;
    // weight[v]に始点sからvまでの最短コストを保存する
    int weight[MAX];
    // 訪問状態を記録
    int color[MAX];
    // 1.初期化
    for(int i = 0;i < n;++i){
        weight[i] = __INT_MAX__;
        color[i] = WHITE;
    }
    
    // 始点
    weight[startIndex] = 0;
    color[startIndex] = GRAY;
    pq.push(make_pair(0,startIndex));
    
    // 2
    while(!pq.empty()){
        // 2.1最小である頂点の決定
        pair<int,int> first = pq.top();
        pq.pop();
        // 頂点
        int u = first.second;
        color[u] = BLACK;
        // 最短値を取りだして、最短でなければ飛ばす
        if(weight[u] < first.first * -1) continue;
        // uに隣接する頂点vが存在する限り最短店を更新する
        for(int i = 0;i < adj[u].size();++i){
            int v = adj[u][i].first;
            if(color[v] == BLACK)continue;
            // 2.2最短点の更新
            if(weight[v] > weight[u] + adj[u][i].second){
                weight[v] = weight[u] + adj[u][i].second;
                // priority_queueはデフォルトで大きい値を優先するので-にする
                pq.push(make_pair(weight[v] * -1, v));
                color[v] = GRAY;
            }
        }
    }
    return weight[dest];
}

int main(){
    int begin,vNum,eNum,dest,salary,cost,totalCost = 0;
    cin >> vNum;
    cin >> eNum;

    int s,t,d1,d2;
    for(int i = 0;i < eNum;++i){
        scanf("%d,%d,%d,%d",&s,&t,&d1,&d2);
        adj[s - 1].push_back(make_pair(t - 1,d1));
        adj[t - 1].push_back(make_pair(s - 1,d2));
    }
    scanf("%d,%d,%d,%d",&begin,&dest,&salary,&cost);
    totalCost += dijkstra(adj,vNum,begin - 1,dest - 1);
    totalCost += dijkstra(adj,vNum,dest - 1,begin - 1);
    int ans = salary - (cost + totalCost);
    cout << ans << endl;
}



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

string t[100000],u[100000];
map<string,int> mp;
int n,m;

int countf(string A[100000],string str){
  char ch='z'+1;
  int L=lower_bound(A,A+n,str) - A;
  str.push_back(ch);
  int R=lower_bound(A,A+n,str) - A;
  return R-L;
}

int solve(string str){
  int len=str.size();
  if(str[0]=='*'){
    string tmp=str.substr(1);
    reverse(tmp.begin(),tmp.end());
    return countf(u,tmp);
  }else if(str[len-1]=='*'){
    string tmp=str.substr(0,len-1);
    return countf(t,tmp);
  }else{
    return mp[str];
  }
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  string str;
  cin>>n>>m;
  for(int i=0;i<n;i++){
    cin>>str;
    t[i]=str;
    mp[str]=1;
    reverse(str.begin(),str.end());
    u[i]=str;
  }
  sort(t,t+n);
  sort(u,u+n);
  
  for(int i=0;i<m;i++){
    cin>>str;
    int p=-1;
    for(int j=0;j<(int)str.size();j++)if(str[j]=='?')p=j;

    if(p==-1){
      cout<<solve(str)<<endl;
    }else{
      int ans=0;
      for(char ch='a';ch<='z';ch++){
        str[p]=ch;
        ans+=solve(str);
      }
      cout<<ans<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 83376
#include<stdio.h>
#include<string.h>

#define M 1046527
#define NIL -1
#define L 14

char H[M][L];

int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
}

long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key){ return key % M; }
int h2(int key){ return 1 + (key % (M-1)); }

int find(char str[]){
  long long key, i, h;
  key = getKey(str);
  for ( i = 0;; i++){
    h = (h1(key)+i*h2(key))%M;
    if( strcmp(H[h],str) == 0 ) return 1;
    else if ( strlen(H[h]) == 0 ) return 0;
  }
  return 0;
}

int insert(char str[]){
  long long key, i, h;
  key = getKey(str);
  for ( i = 0; ; i++ ){
    h = (h1(key)+i*h2(key))%M;
    if( strcmp(H[h],str) == 0 ) return 1;
    else if ( strlen(H[h]) == 0 ){
      strcpy(H[h], str);
      return 0;
    }
  }
 return 0;
}

main(){
  int i, n, h;
  char str[L], com[9];
  for ( i = 0; i < M; i++ ) H[i][0] = '\0';
  scanf("%d", &n);
  i=0;
  while(i<n){
    i++;
    scanf("%s %s", com, str);

    if ( com[0] == 'i' ){
      if (insert(str)){

      }
    } else {
      if (find(str) ){
        printf("yes\n");
      } else {
        printf("no\n");
      }
    }
  }
  return 0;
}



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

using i64 = int64_t;

int main(){
    string s, t;
    cin >> s >> t;
    set<char> st;
    for(auto c: s)st.insert(c);
    for(auto c: t){
        if(!st.count(c)){
            cout << -1 << endl;
            return 0;
        }
    }

    vector<vector<int>> indices(26, vector<int>());
    for(int i=0;i<(int)s.size();++i){
        int idx = s[i] - 'a';
        indices[idx].push_back(i);
    }
    i64 ans = 0;
    i64 idx = -1;
    for(int i=0;i<(int)t.size();++i){
        int c = t[i] - 'a';
        int ok = indices[c].size(), ng = -1;
        while(abs(ok-ng) > 1){
            int mid = (ok + ng) / 2;
            if(indices[c][mid] > idx)ok = mid;
            else ng = mid;
        }
        i64 next;
        if(ok == (int)(indices[c].size()))next = indices[c][0];
        else next = indices[c][ok];
        i64 tmp = next - idx;
        //cout << next << endl;
        if(tmp <= 0)tmp += (i64)s.size();
        ans += tmp;
        idx = next;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1216
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
typedef long long int ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<signed(n);i++)
#define EREP(i,n) for(int i=1;i<=signed(n);i++)
#define ALL(a) (a).begin(),(a).end()
using std::cout;
using std::vector;
using std::endl;
using std::cin;
using std::string;
//#define EVEL 1
#ifdef EVEL
#define DEB(X) cout << #X << ":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const int MOD = 1000000007;
const ll INF = 5000000000000;
typedef std::pair<int, int> P;
struct edge { int to;double cost; };
#define VMAX 1010
int N;
long double C[VMAX][VMAX];
long double d[VMAX];
bool F[VMAX];
ll X[VMAX], Y[VMAX], R[VMAX];


void Dijkstra(int s) {
	std::fill(F, F + N + 2, false);
	std::fill(d, d + N + 2, INF);
	d[s] = 0;
	while (true) {
		int v = -1;
		REP(i, N+2) {
			if (!F[i] && (v == -1 || d[i]<d[v]))v = i;
		}
		if (v == -1)break;
		F[v] = true;
		REP(i, N+2) {
			d[i] = std::min(d[i], d[v] + C[v][i]);
		}
	}
}

int main() {
	int sx, sy, gx, gy;
	cin >> sx >> sy >> gx >> gy >> N;
	X[N] = sx, Y[N] = sy, X[N + 1] = gx, Y[N + 1] = gy;
	R[N] = R[N + 1] = 0;
	REP(i, 1002)REP(j, 1002)C[i][j] = INF;
	REP(i, N) {
		cin >> X[i] >> Y[i] >> R[i];
	}
    REP(i,2)REP(j,N){
      long double temp =
			sqrtl((X[N+i] - X[j])*(X[N+i] - X[j]) + (Y[N+i] - Y[j])*(Y[N+i] - Y[j]));
      if(temp<=R[j]){
        X[N+i]=X[j];
        Y[N+i]=Y[j];
        R[N+i]=R[j];
        break;
      }
    }
	REP(i, N + 2){REP(j, N + 2) {
		if (i == j) { continue; }
		long double temp =
			sqrtl((X[i] - X[j])*(X[i] - X[j]) + (Y[i] - Y[j])*(Y[i] - Y[j]));
        if(temp<=R[i]+R[j]){C[i][j]=0;}
	    else C[i][j] = temp- R[i] - R[j];
		/*DEB(X[i])DEB(X[j])DEB(Y[i])DEB(Y[j])*/DEB(C[i][j])
	}END}
    Dijkstra(N);
	printf("%.10llf\n", d[N + 1]);
	return 0;
}

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

using namespace std;

#define MAX_V 100

int V,E;
bool found;
vector<int> G[MAX_V];
int visited[MAX_V];

void dfs(int v){
  visited[v] = 0;
  for(int i = 0 ; i < (int)G[v].size() ; i++){
    int to = G[v][i];
    if(visited[to] == -1){
      dfs(to);
    }else if(visited[to] == 0){
      found = true;
      return;
    }
  }
  visited[v] = 1;
}

void solve(){
  found = false;
  memset(visited,-1,sizeof(visited));
  for(int i = 0 ; i < V ; i++){
    if(visited[i] == -1){
      dfs(i);
    }
  }
  cout << found << endl;
}

int main(){
  int s,t;
  cin >> V >> E;
  for(int i = 0 ; i < E ; i++){
    cin >> s >> t;
    G[s].push_back(t);
  }
  solve();
  return 0;
}

Measured memory_bytes: 1216
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_W = 30;
const int MAX_H = 30;
const int MAX_HW = MAX_H * MAX_W;
const int SWBITS = 8;
const int MAX_SW = 1 << SWBITS;

const int INF = 1 << 30;

/* typedef */

typedef pair<int,int> pii;

enum { F_EMPTY, F_WALL };

/* global variables */

int w, h, hw, nsw;
int spos, gpos;
int flds[MAX_HW], swtbl[26];
int dists[MAX_HW][MAX_SW];
int dpos[4];

/* subroutines */

/* main */

int main() {
  for (;;) {
    int w, h;
    cin >> w >> h;
    if (w == 0) break;

    hw = w * h;
    dpos[0] = 1, dpos[1] = -w, dpos[2] = -1, dpos[3] = w;
    nsw = 0;
    
    memset(flds, 0, sizeof(flds));
    memset(swtbl, -1, sizeof(swtbl));
    
    for (int y = 0; y < h; y++) {
      string line;
      cin >> line;
      for (int x = 0; x < w; x++) {
	int pos = y * w + x;
	int ch = line[x];

	if (ch == '@') spos = pos;
	else if (ch == '<') gpos = pos;
	else if (ch == '#') flds[pos] = F_WALL;
	else if (ch >= 'a' && ch <= 'z') {
	  int id = ch - 'a';
	  if (swtbl[id] < 0) swtbl[id] = nsw++;
	  flds[pos] = 10 + swtbl[id];
	}
	else if (ch >= 'A' && ch <= 'Z')
	  flds[pos] = 20 + (ch - 'A');
      }
    }

    if (nsw > 8) {
      printf("Error: nsw=%d\n", nsw); exit(0);
    }
    
    for (int i = 0; i < MAX_HW; i++)
      for (int j = 0; j < MAX_SW; j++) dists[i][j] = INF;
    dists[spos][0] = 0;

    queue<pii> q;
    q.push(pii(spos, 0));

    int min_d = INF;
    
    while (! q.empty()) {
      pii u = q.front(); q.pop();

      int upos = u.first;
      int usw = u.second;
      int ud = dists[upos][usw];

      if (upos == gpos) {
	min_d = ud;
	break;
      }
      
      for (int di = 0; di < 4; di++) {
	int vpos = upos + dpos[di];
	int vsw = usw;
	int vfld = flds[vpos];

	if (vfld == F_WALL) continue;
	else if (vfld >= 10 && vfld <= 19) {	// sw
	  int sw = vfld - 10;
	  vsw ^= (1 << sw);
	}
	else if (vfld >= 20) {	// rock
	  int sw = swtbl[vfld - 20];
	  if (sw < 0 || ! (vsw & (1 << sw))) continue;
	}

	if (dists[vpos][vsw] >= INF) {
	  dists[vpos][vsw] = ud + 1;
	  q.push(pii(vpos, vsw));
	}
      }
    }

    if (min_d >= INF) cout << -1 << endl;
    else cout << min_d << endl;
  }

  return 0;
}

Measured memory_bytes: 2204